01.11.2014, 03:34
How would I make a /namechange command? I use zcmd and sscanf, any tut links would be helpful (Yes, I've looked but there are none), or if anyone could help by giving me some indication.
CMD:changename(playerid, params[])
{
new name[24], id;
if(sscanf(params,"ds",id,name)) return SendClientMessage(playerid, -1, "USAGE: /changename [id] [name]");
SetPlayerName(id, name);
return 1;
}
CMD:changename(playerid, params[])
{
new name[MAX_PLAYER_NAME]; // declaring array that we will use to store the input name of the player
if(sscanf(params,"s[MAX_PLAYER_NAME]",name)) //input check if the player put the correct input see sscanf documentation for further details
{
return SendClientMessage(playerid, -1, "USAGE: /changename [name]"); // this will print if the player's input exceeds the MAX_PLAYER_NAME
}
new pname[MAX_PLAYER_NAME];
for(new i;i!=MAX_PLAYERS;i++) // looping through all players to check if the name is already taken
{
if(IsPlayerConnected(i)) // checking if the player is online to avoid crashing the server
{
GetPlayerName(i,pname,sizeof(pname));// getting the name of the player currently lopped
if(strcmp(name,pname,true)==0) // compring the input name and the name of the player currently looped
{
return SendClientMessage(playerid,-1,"name already taken");
}
}
}
new msg[128];
SetPlayerName(playerid,name); // setting the input name as the players name
format(msg,sizeof(msg)," Your name successfully change to %s",name);
SendClientMessage(playerid,-1,msg);
return 1;
}
pawn Код:
|
pawn Код:
|
if(sscanf(params,"ds[24]",id,name))...
CMD:changename(playerid, params[])
{
new newname[MAX_PLAYER_NAME];
if(sscanf(params, "s[MAX_PLAYER_NAME]", newname)) return SendClientMessage(playerid, 0xFFFFFFFF, "Syntax: /changename <newname>");
new checkname[MAX_PLAYER_NAME];
new bool:nametaken = false;
for(new i = 0; i < MAX_PLAYERS; i ++)
{
GetPlayerName(i, checkname, sizeof(checkname));
if(strcmp(checkname, newname, true) == 0)
{
nametaken = true;
}
}
if(nametaken == true) return SendClientMessage(playerid, 0xFFFFFFFF, "That name is already taken.");
SetPlayerName(playerid, newname);
new string[40];
format(string, sizeof(string), "Name changed to %s.", newname);
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
pawn Код:
|
if(strcmp(checkname, newname, true) == 0)
if(!strcmp(checkname, newname, true) == 0)