SA-MP Forums Archive
/namechange - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /namechange (/showthread.php?tid=544272)



/namechange - mkmk - 01.11.2014

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.


Re: /namechange - TheSimpleGuy - 01.11.2014

pawn Код:
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;
}



Re: /namechange - Ryz - 01.11.2014

Quote:
Originally Posted by mkmk
Посмотреть сообщение
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.
Its depend on your user saving system.


Re: /namechange - Quickie - 01.11.2014

pawn Код:
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;
}



Re: /namechange - mkmk - 01.11.2014

Quote:
Originally Posted by Quickie
Посмотреть сообщение
pawn Код:
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;
}
Not working. Just says "name is already taken".

The first one just didn't.


Re: /namechange - dominik523 - 01.11.2014

Quote:
Originally Posted by TheSimpleGuy
Посмотреть сообщение
pawn Код:
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;
}
When putting specifiers in sscanf, you need to tell it how long the string will be.
pawn Код:
if(sscanf(params,"ds[24]",id,name))...
If you don't set this, you will get warnings in your server console.


Re: /namechange - mkmk - 01.11.2014

Any ideas?


Re: /namechange - DanishHaq - 01.11.2014

pawn Код:
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;
}



Re: /namechange - mkmk - 01.11.2014

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
pawn Код:
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;
}
No errors, but it just says "Name is already taken"


Re: /namechange - Sawalha - 01.11.2014

replace
pawn Код:
if(strcmp(checkname, newname, true) == 0)
With
pawn Код:
if(!strcmp(checkname, newname, true) == 0)