SA-MP Forums Archive
Array must be indexed & argument type mismatch errors - 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: Array must be indexed & argument type mismatch errors (/showthread.php?tid=406606)



Array must be indexed & argument type mismatch errors - EAsT-OAK_510 - 10.01.2013

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;
}



Re: Array must be indexed & argument type mismatch errors - ThePhenix - 10.01.2013

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



Re: Array must be indexed & argument type mismatch errors - EAsT-OAK_510 - 10.01.2013

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.


Re: Array must be indexed & argument type mismatch errors - Threshold - 11.01.2013

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.


Re: Array must be indexed & argument type mismatch errors - ThePhenix - 11.01.2013

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


Re: Array must be indexed & argument type mismatch errors - Threshold - 11.01.2013

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.


Re: Array must be indexed & argument type mismatch errors - EAsT-OAK_510 - 11.01.2013

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.