/namechange
#1

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.
Reply
#2

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;
}
Reply
#3

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.
Reply
#4

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;
}
Reply
#5

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.
Reply
#6

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.
Reply
#7

Any ideas?
Reply
#8

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;
}
Reply
#9

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"
Reply
#10

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


Forum Jump:


Users browsing this thread: 2 Guest(s)