A little bit of help please
#1

I am trying to make it so it changes your name


pawn Код:
enum pData
{
    AdminLevel,
    AdminName
}

pawn Код:
CMD:setadminname(playerid, params[])
{
    if(PlayerData[ID][AdminLevel] >= 1)
    {
        new string[128], newname[15];
        if(sscanf(params, "s", newname)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setadminname <name>");
        PlayerData[playerid][AdminName] = newname;
        format(string, sizeof(string), "You set your admin name to %s", newname);
        SendClientMessage(playerid, 0xFFFFFFFF, string);
    }
    return 1;
}

I am getting this error


pawn Код:
(472) : error 006: must be assigned to an array

Line 472 : PlayerData[playerid][AdminName] = newname;


Thank You


Please Help Me Please
Reply
#2

Your problem is that 'AdminName' is not a string.

pawn Код:
enum pData
{
    AdminLevel,
    AdminName[MAX_PLAYER_NAME],
}
Adding [] with a number in adds dimensions to the variable, making it an array or a string depending on the context. MAX_PLAYER_NAME is 24, and it's the largest possible name a player can have in SA-MP.

Strings in PAWN are for alphanumerical characters, if you don't add [] for a string or an array, it's automatically an integer; that's a variable which only accepts whole numbers.
Reply
#3

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Your problem is that 'AdminName' is not a string.

pawn Код:
enum pData
{
    AdminLevel,
    AdminName[MAX_PLAYER_NAME],
}
Adding [] with a number in adds dimensions to the variable, making it an array or a string depending on the context. MAX_PLAYER_NAME is 24, and it's the largest possible name a player can have in SA-MP.

Strings in PAWN are for alphanumerical characters, if you don't add [] for a string or an array, it's automatically an integer; that's a variable which only accepts whole numbers.
I am now getting this error

pawn Код:
(472) : error 047: array sizes do not match, or destination array is too small

Thank You


Please Help Me Please
Reply
#4

pawn Код:
CMD:setadminname(playerid, params[])
{
    if(PlayerData[ID][AdminLevel] >= 1)
    {
        new string[52], newname[MAX_PLAYER_NAME];
        if(sscanf(params, "s", newname)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setadminname <name>");
        format(PlayerData[playerid][AdminName],MAX_PLAYER_NAME,"%s",newname);
        format(string, sizeof(string), "You set your admin name to %s", newname);
        SendClientMessage(playerid, 0xFFFFFFFF, string);
    }
    return 1;
}
Reply
#5

Sorry I forgot to mention that. The reason that happened is because you can't just use = to set a strings value if the lengths don't match or are undefined.

Also, you might want to replace your sscanf like with this:
pawn Код:
if(sscanf(params, "s[24]", newname)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setadminname <name>");
If you're using the plugin version of sscanf, it will cause an error/warning message to show if you don't specify a length for the string.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)