23.10.2012, 20:46
How can i make a changename Command, and that it work only for Admins? I script with sscanf and zcmd, for help.
CMD:changename(playerid, params[])
{
new name[MAX_PLAYER_NAME],
id,
pname[MAX_PLAYER_NAME],
string[128],
nick[20];
if(PlayerInfo[playerid][Admin] > 5)
{
if(sscanf(params, "us[20]", id, nick)) return SendClientMessage(playerid, COLOR_RED, "SYNTAX: /changename <playername/id> <nickname>");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid-Playerid!");
if(IsPlayerNPC(id)) return SendClientMessage(playerid, COLOR_RED, "You cannot change NPC Bot's name!");
GetPlayerName(id, name, sizeof(name));
GetPlayerName(playerid, pname, sizeof(pname));
SetPlayerName(id, nick);
format(string, sizeof(string), "Administrator %s(ID:%d) has set %s(ID:%d)'s name to %s", pname, playerid, name, id, nick);
SendClientMessageToAll(COLOR_RED, string);
format(string, sizeof(string), "You set %s(ID:%d)'s name to %s", name, id, nick);
SendClientMessage(playerid, COLOR_GREEN, string);
format(string, sizeof(string), "Administrator %s(ID:%d) has set your name to %s", pname, playerid, nick);
SendClientMessage(id, COLOR_RED, string);
format(string, sizeof(string), "ADMIN-SPEC: %s has used /changename", pname);
SentMessageToAdmins(COLOR_GREY, string);
}
else return SendClientMessage(playerid, COLOR_RED, "You must be Administrator Level 5 or higher to use this command!");
return 1;
}
CMD:changename(playerid,params[])
{
new ID,newname[24];
if(sscanf(params, "us[24]", ID,newname)) return SendClientMessage(playerid, -1, "/changename [id] [name]");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, -1, "[ERROR] Player is off.");
SetPlayerName(ID,newname);
return 1;
}
Here you go, just put the save variables that you have there
PHP код:
|
CMD:changename(playerid, params[]) { new name[MAX_PLAYER_NAME], id, pname[MAX_PLAYER_NAME], string[128], nick[20]; if(PlayerInfo[playerid][pAdmin] > 5) { if(sscanf(params, "us[20]", id, nick)) return SendClientMessage(playerid, COLOR_RED, "SYNTAX: /changename <playername/id> <nickname>"); if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid-Playerid!"); if(IsPlayerNPC(id)) return SendClientMessage(playerid, COLOR_RED, "You cannot change NPC Bot's name!"); GetPlayerName(id, name, sizeof(name)); GetPlayerName(playerid, pname, sizeof(pname)); SetPlayerName(id, nick); format(string, sizeof(string), "Administrator %s(ID:%d) has set %s(ID:%d)'s name to %s", pname, playerid, name, id, nick); SendClientMessageToAll(COLOR_RED, string); format(string, sizeof(string), "You set %s(ID:%d)'s name to %s", name, id, nick); SendClientMessage(playerid, COLOR_GREEN, string); format(string, sizeof(string), "Administrator %s(ID:%d) has set your name to %s", pname, playerid, nick); SendClientMessage(id, COLOR_RED, string); format(string, sizeof(string), "ADMIN-SPEC: %s has used /changename", pname); SentMessageToAdmins(COLOR_GREY, string); } else return SendClientMessage(playerid, COLOR_RED, "You must be Administrator Level 5 or higher to use this command!"); return 1; }