Array must be indexed & argument type mismatch errors
#1

Errors:
Код:
C:\Documents and Settings\Administrator\My Documents\New Folder (2)\gamemodes\DRP.pwn(15833) : error 033: array must be indexed (variable "playerb")
C:\Documents and Settings\Administrator\My Documents\New Folder (2)\gamemodes\DRP.pwn(15835) : error 033: array must be indexed (variable "playerb")
C:\Documents and Settings\Administrator\My Documents\New Folder (2)\gamemodes\DRP.pwn(15836) : error 033: array must be indexed (variable "playerb")
C:\Documents and Settings\Administrator\My Documents\New Folder (2)\gamemodes\DRP.pwn(15838) : error 035: argument type mismatch (argument 1)
C:\Documents and Settings\Administrator\My Documents\New Folder (2)\gamemodes\DRP.pwn(15839) : error 035: argument type mismatch (argument 1)
C:\Documents and Settings\Administrator\My Documents\New Folder (2)\gamemodes\DRP.pwn(15840) : error 033: array must be indexed (variable "playerb")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.
My code for basically for offline ajail:
pawn Код:
CMD:jailaccount(playerid, params[])
{
    new playerb[32], string[128], file[32], time, RandomCell;
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    if(sscanf(params, "uis[64]", playerb, time, params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jailaccount [playername] [time] [reason]");
    format(file, sizeof(file), "users/%s.ini", playerb);
    if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_GREY, "Player name not found.");
    if(time > 0)
    {
        PlayerInfo[playerb][pPrison] = 3;
        PlayerInfo[playerb][pPrisonTime] = time*60;
        format(PlayerInfo[playerb][pPrisonReason], 64, "%s", params);
        format(PlayerInfo[playerb][pPrisonBy], 32, "%s", RPN(playerid));
        RandomCell = random(sizeof(RandomCells));
        SetPlayerFacingAngle(playerb, RandomCells[RandomCell][3]);
        SetPlayerPos(playerb, RandomCells[RandomCell][0], RandomCells[RandomCell][1], RandomCells[RandomCell][2]);
        format(string, sizeof(string), "AdmCmd: %s has been offline-ajailed for %d minute(s) by %s, reason: %s", playerb, PlayerInfo[playerb][pPrisonTime]/60, RPN(playerid), params);
        SendClientMessageToAll(COLOR_LIGHTRED, string);
    }
    return 1;
}
Reply
#2

PHP код:
new playerb[MAX_PLAYERS];
//or
enum pInfo
{
playerb
};
new 
PlayerInfo[MAX_PLAYERS][pInfo]; 
Reply
#3

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
PHP код:
new playerb[MAX_PLAYERS];
//or
enum pInfo
{
playerb
};
new 
PlayerInfo[MAX_PLAYERS][pInfo]; 
Will this affect the other commands and sections where I use playerb?

Edit: It did, it gave me a bunch of warnings and errors.
Reply
#4

You are using playerb as if it isn't a string and is in fact a playerid that is online, how are you going to Set a player's pos if he is offline?

Example of what you should do:
pawn Код:
CMD:jailaccount(playerid, params[])
{
    new playerb[32], string[128], file[35], time, reason[64];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    if(sscanf(params, "sis[64]", playerb, time, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jailaccount [playername] [time] [reason]");
    format(file, sizeof(file), "users/%s.ini", playerb);
    if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_GREY, "Player name not found.");
    if(time > 0)
    {
        //Save pPrison to the user's file
        //save the jail time to the user's file
        //Save the reason to the user's file
        //save prisonby to the user's file
        new RandomCell = random(sizeof(RandomCells));
        //Save player angle to the users file
        //Save the player pos to the user's file
        format(string, sizeof(string), "AdmCmd: %s has been offline-ajailed for %d minute(s) by %s, reason: %s", playerb, PlayerInfo[playerb][pPrisonTime]/60, RPN(playerid), params);
        SendClientMessageToAll(COLOR_LIGHTRED, string);
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    //After loading all the user stats
    if(PlayerInfo[playerid][pPrison] == 3) //Or whatever you use to determine if they're jailed
    {
        SetPlayerPos(playerid... //to the position saved in their file
        SetPlayerFacingAngle(playerid... //to the angle saved in their file
    }
    return 1;
}
You basically just need to save a few more player variables into the target user's file, and you must treat playerb like a string, not a playerid, because that is what playerb is... a string.
Reply
#5

Код:
error 033: array must be indexed (variable "playerb")
It means you should create a MAX_PLAYERS variable.
Reply
#6

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
Код:
error 033: array must be indexed (variable "playerb")
It means you should create a MAX_PLAYERS variable.
That is because he is using in the format of:
pawn Код:
PlayerInfo[playerb][pPrison]
for example.

So it's detecting that playerb is part of the MAX_PLAYERS in the variable:
pawn Код:
new PlayerInfo[MAX_PLAYERS][PlayerData];
So, just a misunderstanding of playerid and string and you are wrong.
You don't use it like this:
pawn Код:
PlayerInfo["BenzoAMG"][pPrison] = 3;
because that's just wrong.
Reply
#7

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
That is because he is using in the format of:
pawn Код:
PlayerInfo[playerb][pPrison]
for example.

So it's detecting that playerb is part of the MAX_PLAYERS in the variable:
pawn Код:
new PlayerInfo[MAX_PLAYERS][PlayerData];
So, just a misunderstanding of playerid and string and you are wrong.
You don't use it like this:
pawn Код:
PlayerInfo["BenzoAMG"][pPrison] = 3;
because that's just wrong.
BenzoAMG, thank you for the clarification.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)