summaryrefslogtreecommitdiff
path: root/npc/commands/force-rename.txt
blob: 82ba46eb6cfc8a3395e69320be43aa2e1bd77148 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// @charrename/@forcerename atcommand
// FORCEFULLY renames a char. Collision is handled by SQL.
//
// group lv: 80+
// group char lv: 80+
// log: True
//
// usage: npc/commands/force-rename.txt
//    @charrename New Nickname
//    #forcerename "char" <Nickname>
//

-	script	@charrename	32767,{
    end;

OnRename:
    // array size validation
    if (getarraysize(.@atcmd_parameters$) <= 0) {
        dispbottom("Syntax requires argument between 3 and 30 chars long.");
        end;
    }
    // Set new nickname
	.@nickname$ += implode(.@atcmd_parameters$, " ");
    .@nickname$ = strip(.@nickname$);
    // Empty nickname
    if (.@nickname$ == "" || .@nickname$ == "NULL")
        end;
    // Too long or too short nickname
    if (getstrlen(.@nickname$) > 30 || getstrlen(.@nickname$) < 3)
        end;
    // Attempt to rename. If name is taken, will fail at SQL query
    dispbottom l("Your nickname has been redefined by GM Team.");
    .@id=getcharid(3);
    .@n$=strcharinfo(0);
    detachrid();
    kick(.@id, 12);
    sleep(25);
    query_sql(sprintf("UPDATE `char` SET `name`='%s' WHERE `name`='%s'", escape_sql(.@nickname$), escape_sql(.@n$)));
    debugmes "[SUCCESS] char %s renamed to %s", .@n$, .@nickname$;
    end;

OnInit:
    bindatcmd "charrename", "@charrename::OnRename", 80, 80, 1;
    bindatcmd "forcerename", "@charrename::OnRename", 80, 80, 1;
    end;
}