Debug with Function LoadCells and command Civil
#1

Hey guys I have a few debugging codes in my script and I'm not sure how to fix them. I would appreciate if someone could give me a website that allows me to look at the debug codes and try to figure out what's wrong with them that way but I can't find any at the moment. I don't understand what this Array index out of bounds means.

Here are my debug codes.
Код:
[23:16:43] [debug] Run time error 4: "Array index out of bounds"
[23:16:43] [debug]  Attempted to read/write array element at index 30 in array of size 30
[23:16:43] [debug] AMX backtrace:
[23:16:43] [debug] #0 00051830 in public LoadCells () from vR.amx
[23:16:54] [debug] Run time error 4: "Array index out of bounds"
[23:16:54] [debug]  Attempted to read/write array element at negative index -1
[23:16:54] [debug] AMX backtrace:
[23:16:54] [debug] #0 001416ec in public cmd_civil (0, 24722412) from vR.amx
[23:16:54] [debug] #1 native CallLocalFunction () from samp03svr
[23:16:54] [debug] #2 00000754 in public OnPlayerCommandText (0, 24722384) from vR.amx
Here is my LoadCells function

PHP код:
public LoadCells()
{
    new 
rows,fields;
    
cache_get_data(rows,fields);
    for(new 
0rowsi++)
    {
        
cellInfo[i][cellx]=cache_get_field_content_float(i"X");
        
cellInfo[i][celly]=cache_get_field_content_float(i"Y");
        
cellInfo[i][cellz]=cache_get_field_content_float(i"Z");
        
cellInfo[i][cella]=cache_get_field_content_float(i"A");
    }
    return 
1;

Here is my civil command.

PHP код:
CMD:civil(playerid)
{
    new 
string[100],str[25];
    new 
orgid=PlayerInfo[playerid][OrgID];
    if(
PlayerInfo[playerid][Rules] == 0) return SendClientMessage(playeridCOLOR_RED"You need to accept rules using /rules!");
    
format(str,10,"0x%sFF",oInfo[PlayerInfo[playerid][OrgID]][Color]);
    if(
GetPVarInt(playerid,"Oskin") == || GetPVarInt(playerid"VIPSkin") == 1)
    {    
        
SetPlayerSkin(playerid,pedskin[playerid]);
        
SetPlayerColor(playeridCOLOR_PLAYER);
        
SendClientMessage(playeridCOLOR_YELLOW"ACTION: You have set your state to civilian.");
        
SetPlayerSkin(playerid,pedskin[playerid]);
        if(
GetPVarInt(playerid,"Oskin") == 1)
        {
            if(
oInfo[PlayerInfo[playerid][OrgID]][Type] == 1)
            {
                
format(string,sizeof(string),"[LAW]:%s-%s is now off duty!",GetName(playerid),oInfo[PlayerInfo[playerid][OrgID]][Name]);
                foreach(
Player,i)
                {
                    if(
oInfo[PlayerInfo[i][OrgID]][Type] == 1)
                    {
                        
SendClientMessage(i,oInfo[orgid][Color],string);
                    }
                }
            }
        }
        
SetPVarInt(playerid,"VIPSkin"0);
        
SetPVarInt(playerid,"Weps",0);
        
SetPVarInt(playerid,"Oskin"0);
    }
    else
    {
        return 
SendClientMessage(playerid,COLOR_RED,"Error: You're already in your civil state");
    }
    return 
1;

I'm not sure if you need anymore information just if someone could describe what these debugs mean I would greatly appreciate it.
Reply
#2

size of cellInfo is 30 ( 0 - 29 ) but you are trying to load more than 29 indexes so - "Array index out of bounds".
pawn Код:
public LoadCells()
{
    new rows,fields;
    cache_get_data(rows,fields);
    for(new i = 0; i < rows; i++)
    {
        if(i >= sizeof(cellInfo))
        {
            printf("ERROR LoadCells: You cant load more than %d cells",sizeof(cellInfo));
            break;
        }
        cellInfo[i][cellx] = cache_get_field_content_float(i, "X");
        cellInfo[i][celly] = cache_get_field_content_float(i, "Y");
        cellInfo[i][cellz] = cache_get_field_content_float(i, "Z");
        cellInfo[i][cella] = cache_get_field_content_float(i, "A");
    }
    return 1;
}

In second code propably PlayerInfo[playerid][OrgID] is -1
Reply
#3

Thank you. I checked the Cells created and there are 36 so I changed the variable name. With the org system if a player isn't in an org their Org ID is -1 because Org ID's start from 0 and go up. Is there a way to avoid this debug issue? Or do I have to change the default value of the Org ID's?
Reply
#4

if(orgid < 0) return you are not in any org + in foreach change to if(PlayerInfo[i][OrgID] > -1 && oInfo[PlayerInfo[i][OrgID]][Type] == 1)
Reply
#5

I still get this.
Код:
[02:51:07] [debug] Run time error 4: "Array index out of bounds"
[02:51:07] [debug]  Attempted to read/write array element at negative index -1
[02:51:07] [debug] AMX backtrace:
[02:51:07] [debug] #0 0014ae54 in public cmd_civil (0, 24731200) from vR.amx
[02:51:07] [debug] #1 native CallLocalFunction () from samp03svr
[02:51:07] [debug] #2 00000754 in public OnPlayerCommandText (0, 24731172) from vR.amx
PHP код:
CMD:civil(playerid)
{
    new 
string[100],str[25];
    new 
orgid=PlayerInfo[playerid][OrgID];
    if(
PlayerInfo[playerid][Rules] == 0) return SendClientMessage(playeridCOLOR_RED"You need to accept rules using /rules!");
    if((
orgid 0) && (PlayerInfo[playerid][VIP] == 0)) return SendClientMessage(playeridCOLOR_RED"Error: You're not in an Organization!");
    
format(str,10,"0x%sFF",oInfo[PlayerInfo[playerid][OrgID]][Color]);
    if(
GetPVarInt(playerid,"Oskin") == || GetPVarInt(playerid"VIPSkin") == 1)
    {    
        
SetPlayerSkin(playerid,pedskin[playerid]);
        
SetPlayerColor(playeridCOLOR_PLAYER);
        
SendClientMessage(playeridCOLOR_YELLOW"ACTION: You have set your state to civilian.");
        
SetPlayerSkin(playerid,pedskin[playerid]);
        if(
GetPVarInt(playerid,"Oskin") == 1)
        {
            if(
oInfo[PlayerInfo[playerid][OrgID]][Type] == 1)
            {
                
format(string,sizeof(string),"[LAW]:%s-%s is now off duty!",GetName(playerid),oInfo[PlayerInfo[playerid][OrgID]][Name]);
                foreach(
Player,i)
                {
                    if(
PlayerInfo[i][OrgID] > -&& oInfo[PlayerInfo[i][OrgID]][Type] == 1)
                    {
                        
SendClientMessage(i,oInfo[orgid][Color],string);
                    }
                }
            }
        }
        
SetPVarInt(playerid,"VIPSkin"0);
        
SetPVarInt(playerid,"Weps",0);
        
SetPVarInt(playerid,"Oskin"0);
    }
    else
    {
        return 
SendClientMessage(playerid,COLOR_RED,"Error: You're already in your civil state");
    }
    return 
1;

Reply
#6

are you sure that PlayerInfo[playerid][VIP] is 0 ?
Reply
#7

Well basically I want /civil to work if a player is either vip or in an org. So if player is vip and not org it checks of they have vip skin on. If player isn't vip and is in org it checks if they have org on. If player isn't in vip and isn't in org it says they not in org.

For my account vip is 1 not 0
Reply
#8

Can you post SQL log?
Reply
#9

You need change that if because if vip is 1 and orgid = -1 here is error
pawn Код:
format(str,10,"0x%sFF",oInfo[PlayerInfo[playerid][OrgID]][Color]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)