SA-MP Forums Archive
Array error - 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 error (/showthread.php?tid=654215)



Array error - Spectat0rDE - 23.05.2018

Im currently creating a simple faction. Im just curious whats wrong. When I compile I get these 2 errors.

Код:
error 033: array must be indexed (variable "mafiaInfo")
error 033: array must be indexed (variable "mafiaInfo")
Thats my enum:

Код:
enum mafia_Faction
{
	FactionName[20],
	MafiaLeaderID,
	MafiaSQL,
	MafiaMembers,
	MafiaNONE

};


new mafiaInfo[MAX_PLAYERS][mafia_Faction];
And thats the command:

Код:
CMD:setmafialeader(playerid,params[])
{
	new mafiaLevel; 
	new mafiaID; 
	if(IsPlayerAdmin(playerid)) 
	{ 
	if(sscanf(params,"ui", mafiaID, mafiaLevel)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /setmafialeader [ID] [0-1]"); 
        mafiaInfo[mafiaID][MafiaLeaderID] = mafiaLevel; 
        SendClientMessage(playerid,COLOR_WHITE, "{FF8200}Information:{FFFFFF} You have been set as leader of the Mafia.");
	} 
	else 
	{ 
		SendClientMessage(playerid,COLOR_RED, "ERROR: You are not allowd to use this command!"); 
	} 
	return 1; 
} 

CMD:mafiainvite(playerid, params[])
{ 
	if(mafiaInfo[MafiaLeaderID] >= 1) 
	{ 
		new mmemberID; 
        if(sscanf(params,"i", mmemberID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /minvite [ID]");
        mafiaInfo[mmemberID][MafiaMembers] = 1; 
        SendClientMessage(playerid,COLOR_ORANGE,"Information:{FFFFFF} Player has been invited!"); 
        SendClientMessage(mmemberID,COLOR_ORANGE,"Information:{FFFFFF} You have joined the Mafia."); 
	} 
	else 
	{ 
		SendClientMessage(playerid,COLOR_RED, "ERROR: You are not the Mafia Leader!");
	} 
	return 1;
} 

CMD:mafiakick(playerid, params[])
{ 
	if(mafiaInfo[MafiaLeaderID] >= 1) 
	{ 
		new mkickoutID; 
        if(sscanf(params,"i", mkickoutID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /mafiakick [ID]"); 
        mafiaInfo[mkickoutID][MafiaNONE] = 1; 
        SendClientMessage(playerid,COLOR_ORANGE,"Information:{FFFFFF} Player has been kicked out!");
        SendClientMessage(mkickoutID,COLOR_ORANGE,"Information:{FFFFFF} You have been kicked out of the Mafia!"); 
	} 
	else 
	{
		SendClientMessage(playerid,COLOR_RED, "ERROR: You are not the Mafia Leader!"); 
	} 
	return 1; 
}



Re: Array error - Kraeror - 23.05.2018

Can you show me only the lanes where the error comes from?


Re: Array error - Kraeror - 23.05.2018

I saw the mistake, you forgot 1 index of the array (playerid in the check if "playerid" is leader)

The array is fine!
Here you are the fixed CMDs:
PHP код:
CMD:setmafialeader(playerid,params[])
{
    new 
mafiaLevel;
    new 
mafiaID;
    if(
IsPlayerAdmin(playerid))
    {
    if(
sscanf(params,"ui"mafiaIDmafiaLevel)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /setmafialeader [ID] [0-1]");
        
mafiaInfo[mafiaID][MafiaLeaderID] = mafiaLevel;
        
SendClientMessage(playerid,COLOR_WHITE"{FF8200}Information:{FFFFFF} You have been set as leader of the Mafia.");
    }
    else
    {
        
SendClientMessage(playerid,COLOR_RED"ERROR: You are not allowd to use this command!");
    }
    return 
1;
}
CMD:mafiainvite(playeridparams[])
{
    if(
mafiaInfo[playerid][MafiaLeaderID] >= 1)
    {
        new 
mmemberID;
        if(
sscanf(params,"i"mmemberID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /minvite [ID]");
        
mafiaInfo[mmemberID][MafiaMembers] = 1;
        
SendClientMessage(playerid,COLOR_ORANGE,"Information:{FFFFFF} Player has been invited!");
        
SendClientMessage(mmemberID,COLOR_ORANGE,"Information:{FFFFFF} You have joined the Mafia.");
    }
    else
    {
        
SendClientMessage(playerid,COLOR_RED"ERROR: You are not the Mafia Leader!");
    }
    return 
1;
}
CMD:mafiakick(playeridparams[])
{
    if(
mafiaInfo[playerid][MafiaLeaderID] >= 1)
    {
        new 
mkickoutID;
        if(
sscanf(params,"i"mkickoutID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /mafiakick [ID]");
        
mafiaInfo[mkickoutID][MafiaNONE] = 1;
        
SendClientMessage(playerid,COLOR_ORANGE,"Information:{FFFFFF} Player has been kicked out!");
        
SendClientMessage(mkickoutID,COLOR_ORANGE,"Information:{FFFFFF} You have been kicked out of the Mafia!");
    }
    else
    {
        
SendClientMessage(playerid,COLOR_RED"ERROR: You are not the Mafia Leader!");
    }
    return 
1;

+REP if I helped


Re: Array error - Spectat0rDE - 23.05.2018

Quote:
Originally Posted by Kraeror
Посмотреть сообщение
Can you show me only the lanes where the error comes from?
line 130
Код:
if(mafiaInfo[MafiaLeaderID] >= 1)
line 147
Код:
if(mafiaInfo[MafiaLeaderID] >= 1)
EDIT: Yes it worked, thanks!