if(pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
enum ENUM_NAME
{
pFaction = -1
};
|
How are you setting the player's faction to -1?
If it's like this: Код:
enum ENUM_NAME
{
pFaction = -1
};
If not: Check if it's == to -1 before using fData[pData[playerid][pFaction][fManageRank], or else it'll be fData[-1][fManageRank], and that's invalid. |
CMD:settest(playerid, params[])
{
new type, count;
if(sscanf(params, "ii", type, count)) return SendUsageMessage(playerid, "/settest [type] [number] (1:faction,2:factionrank,3:facmanagerank)");
if(type > 3 || type < 1) return SendErrorMessage(playerid, "type cant be more than 3 or less than 1");
switch(type)
{
case 1: pData[playerid][pFaction] = count;
case 2: pData[playerid][pFactionRank] = count;
case 3: fData[pData[playerid][pFaction]][fManageRank] = count;
}
return 1;
}
CMD:factions(playerid, params[])
{
new str[200];
format(str, sizeof(str), "List Factions\n");
if(pData[playerid][pFaction] >= 0)
{
format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
if(pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
{
format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
}
}
if(pData[playerid][pAdmin] > 1)
{
format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
}
ShowPlayerDialog(playerid, DIALOG_FACTION_MAIN, DIALOG_STYLE_LIST, "Faction Control Panel", str, "Select", "Cancel");
return 1;
}
[08:24:32] [debug] Run time error 4: "Array index out of bounds" [08:24:32] [debug] Accessing element at negative index -1 [08:24:32] [debug] AMX backtrace: [08:24:32] [debug] #0 0006b310 in public cmd_factions (playerid=0, params[]=@02133ff0 "") at <myscript>.pwn:2682 [08:24:32] [debug] #1 native CallLocalFunction () from samp-server.exe [08:24:32] [debug] #2 0000b9dc in public f3_KBROnPlayerCommandText (playerid=0, cmdtext[]=@02133fc8 "/factions") at C:\Users\Administrator\Desktop\Script from scratch new\pawno\include\izcmd.inc:94
if(pData[playerid][pAdmin] > 1)
{
format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
}
if (pData[playerid][pFaction] >= 0)
{
format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
if (pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
{
format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
}
if (pData[playerid][pAdmin] > 1)
{
format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
}
}
|
Check if the player's is admin inside the if statement about faction >= 0
pawn Код:
|
#define MAX_FACTIONS (20)
new fData[MAX_FACTIONS][factions];
forward OnFactionLoad(); public OnFactionLoad()
{
new rows, fields, count = 0;
cache_get_data(rows, fields, mysql);
if(rows)
{
while(count < rows)
{
fData[count][fID] = cache_get_field_content_int(count, "fID");
cache_get_field_content(count, "fName", fData[count][fName], mysql, 30);
and so on, all data gets loaded
count++;
}
printf("%i factions loaded.", count);
}
else printf("No factions found.");
factioncount = count;
}
fData[pData[playerid][pFaction][fID]
fData[0][fID]
1

|
I don't get what you're trying to do with that command.
You're listing all the factions, yet you're not even looping through them? |
CMD:factions(playerid, params[])
{
new str[200];
format(str, sizeof(str), "List Factions\n");
if(pData[playerid][pFaction] >= 0)
{
format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
if(pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
{
format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
}
}
if(pData[playerid][pAdmin] > 1)
{
format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str);
}
ShowPlayerDialog(playerid, DIALOG_FACTION_MAIN, DIALOG_STYLE_LIST, "Faction Control Panel", str, "Select", "Cancel");
return 1;
}