18.06.2014, 03:05
pawn Код:
CMD:changename(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, -1, "{FF0000}Error: You are not allowed to use this.");
new id, newname[MAX_PLAYER_NAME];
if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, -1, "{FFFF00}Usage: /changename <ID> <New Name>");
if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "{FF0000}Error: That player is not connected!");
new OldName[MAX_PLAYER_NAME];
GetPlayerName(id, OldName, sizeof(OldName));
if(!SetPlayerName(id, newname))
{
SetPlayerName(id, OldName);
return SendClientMessage(playerid, -1, "You have entered an invalid name.");
}
new Name[MAX_PLAYER_NAME], astring[95];
GetPlayerName(playerid, Name, sizeof(Name));
format(astring, sizeof(astring), "/Users/%s.ini", newname);
if(fexist(astring)) return SendClientMessage(playerid, -1, "<!>Account name is currently in use.");
new INI:file = INI_Open(astring);
INI_SetTag(file, "User's Data");
INI_WriteString(file, "Name", newname);
INI_Close(file);
format(astring, sizeof(astring), "/Users/%s.ini", OldName);
fremove(astring);
SetPVarString(id, "Name", OldName);
format(astring, sizeof(astring), "{0066CC}Admin (%d)%s has changed your name.", playerid, Name);
SendClientMessage(id, -1, astring);
format(astring, sizeof(astring), "{0066CC}You have changed (%d)%s's name to %s.", id, OldName, newname);
SendClientMessage(playerid, -1, astring);
SetTimerEx("KickPlayer", 200, false, "i", id);
return 1;
}
forward KickPlayer(playerid);
public KickPlayer(playerid) return Kick(playerid);