SA-MP Forums Archive
[3D Array] Defining an array entry with another array - 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: [3D Array] Defining an array entry with another array (/showthread.php?tid=604423)



[3D Array] Defining an array entry with another array - introzen - 04.04.2016

Hi!

I'm trying to create a /invite command, but it returns SERVER: Unknown Command.

PHP код:
CMD:invite(playeridparams[]) {
    new 
string[128], id;
    if(
PlayerInfo[playerid][pFaction] == 0) return SendErrorMessage(playerid"You're not part of any faction.");
    if(
FactionRank[PlayerInfo[playerid][pFaction]][PlayerInfo[playerid][pFactionrank]][fInviteKick] < 1) return SendErrorMessage(playerid"You do not have the permission required to invite new faction members.");
    if(
sscanf(params"u"id)) return SendSyntaxMessage(playerid"/invite <playerid/partofname>");
    if(!
IsPlayerConnected(id)) return SendErrorMessage(playerid"Player is not connected.");
    
PlayerInfo[id][pFaction] = PlayerInfo[playerid][pFaction];
    
PlayerInfo[id][pFactionrank] = 1;
    
format(stringsizeof(string), "You've invited %s to the faction."PlayerName(idfalse));
    
SendInfoMessage(playeridstring);
    
format(stringsizeof(string), "You've been invited to %s by %s."FactionInfo[PlayerInfo[playerid][pFaction]][fName], PlayerName(playeridfalse));
    
SendInfoMessage(idstring);
    return 
1;

Although it compiles without errors, it fails on the following line:
PHP код:
if(FactionRank[PlayerInfo[playerid][pFaction]][PlayerInfo[playerid][pFactionrank]][fInviteKick] < 1) return SendErrorMessage(playerid"You do not have the permission required to invite new faction members."); 
Here's the array:
PHP код:
enum fRanks {
    
fID,
    
fFaction,
    
fRank,
    
fName[40],
    
fInviteKick,
    
fPromoteDemote,
    
fMoneyManage,
    
fBuildingManage,
    
fFactionManage
}; new FactionRank[MAX_FACTIONS][MAX_FACTIONRANKS][fRanks]; 



Re: [3D Array] Defining an array entry with another array - Konstantinos - 04.04.2016

Run time errors in commands return the unknown command message. Crashdetect would tell you exactly what is wrong but it's obvious in your case: Run time error 4.

To prevent it, you need to check both pFaction and pFactionrank of the player because if the value of it is not valid (0 to sizeof FactionRank - 1) will give you the run time error.
pawn Код:
if ((0 <= PlayerInfo[playerid][pFaction] < sizeof FactionRank) && (0 <= PlayerInfo[playerid][pFactionrank] < sizeof FactionRank[]))
{
    if (FactionRank[PlayerInfo[playerid][pFaction]][PlayerInfo[playerid][pFactionrank]][fInviteKick] < 1) return SendErrorMessage(playerid, "You do not have the permission required to invite new faction members.");
}
else return SendErrorMessage(playerid, "Not in faction or not correct rank..");// modify this line



Re: [3D Array] Defining an array entry with another array - introzen - 04.04.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Run time errors in commands return the unknown command message. Crashdetect would tell you exactly what is wrong but it's obvious in your case: Run time error 4.

To prevent it, you need to check both pFaction and pFactionrank of the player because if the value of it is not valid (0 to sizeof FactionRank - 1) will give you the run time error.
pawn Код:
if ((0 <= PlayerInfo[playerid][pFaction] < sizeof FactionRank) && (0 <= PlayerInfo[playerid][pFactionrank] < sizeof FactionRank[]))
{
    if (FactionRank[PlayerInfo[playerid][pFaction]][PlayerInfo[playerid][pFactionrank]][fInviteKick] < 1) return SendErrorMessage(playerid, "You do not have the permission required to invite new faction members.");
}
else return SendErrorMessage(playerid, "Not in faction or not correct rank..");// modify this line
Wow, thank you for sharing your knowledge.

In this case though, PlayerInfo[playerid][pFaction] is equal to 1 and PlayerInfo[playerid][pFactionrank] is equal to 50. Would it still cause the error? Running Crashdetect now to see if I get anything out of it.


Re: [3D Array] Defining an array entry with another array - Konstantinos - 04.04.2016

As long as there is at least 1 faction and MAX_FACTIONRANKS is less than 50, no it wouldn't.
Let's wait the logs from crashdetect to be sure.