03.02.2015, 01:31
pawn Код:
CMD:changename(playerid, params[]) {
if(isnull(params)) {
return SendClientMessage(playerid, -1, "/changename [newname]");
}
if(strlen(params) > MAX_PLAYER_NAME) {
return SendClientMessage(playerid, -1, "Your name must contain a maximum of 24 characters.");
}
new current[MAX_PLAYER_NAME];
GetPlayerName(playerid, current, sizeof current);
if(!strcmp(current, params, false)) {
return SendClientMessage(playerid, -1, "That's already your name!");
}
new query[128];
mysql_format(mysql, query, sizeof query, "SELECT * FROM `players` WHERE `Username` = '%s'", params);
mysql_tquery(mysql, query, "ChangeName", "is", playerid, params);
return 1;
}
forward ChangeName(playerid, newname[]);
public ChangeName(playerid, newname[]) {
if(cache_get_row_count(mysql)) {
return SendClientMessage(playerid, -1, "This name is already in use!");
}
new current[MAX_PLAYER_NAME];
GetPlayerName(playerid, current, sizeof current);
new query[128];
mysql_format(mysql, query, sizeof query, "UPDATE `players` SET `Username` = '%s' WHERE `Username` = '%s'", newname, current);
mysql_tquery(mysql, query);
SetPlayerName(playerid, newname);
return 1;
}