I'm gonna go nuts; help.
#1

Seriously, what's wrong with this damn thing?

pawn Код:
error 006: must be assigned to an array
Here's the whole code to my /setrank command of which I'm trying to make work.

pawn Код:
CMD:setrank(playerid, params[])
{
    new id;
    new name[MAX_PLAYER_NAME];
    new rankname[128];
    if(PlayerInfo[playerid][pFactionLeader] == 1 || PlayerInfo[playerid][pFactionAMember] == 1)
    {
       if(!sscanf(params, "us", id, rankname)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /setrank [playerid] [rankname]");
       if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_ERROR, "ERROR: This player is not connected.");
       if(id == PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid, COLOR_ERROR, "ERROR: This player is not a member of your faction.");
       PlayerInfo[playerid][pRank] = rankname;
       new str[128];
       format(str,sizeof(str), "INFO: %s's rank was changed to: %s.", name, rankname);
       SendClientMessage(playerid, COLOR_INFO, str);
       return 1;
    }
    else return SendClientMessage(playerid, COLOR_ERROR, "ERROR: You are unauthorized to use this command.");
}
Reply
#2

Try this:

pawn Код:
// Put this at the top of your script
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

// and replace:
PlayerInfo[playerid][pRank] = rankname;

// with:
strcpy(PlayerInfo[playerid][pRank], rankname);
Reply
#3

Код:
PlayerInfo[playerid][pRank] = rankname;
This line^ is what's producing the error. pRank must be an array. And also it'd be in your best interest to specify a size for a string when asking sscanf to do stuff, otherwise it'll get angry and generate an ugly warning on run-time.
Reply
#4

Like Ada32 said,

pawn Код:
PlayerInfo[playerid][pRank] = rankname;
^ That is your problem, you're defining pRank as a string but in a "integer way". This is the correct way

pawn Код:
format( PlayerInfo[playerid][pRank], sizeof PlayerInfo[playerid][pRank], "%s", rankname);
Also, in the sscanf line you need to add the string's size next to the denominator, like this.

pawn Код:
if(!sscanf(params, "us[128]", id, rankname)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /setrank [playerid] [rankname]");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)