Array out of Bounds
#1

Quote:

if (strcmp (cmd, "/ orguninvite", true) == 0)
{
tmp = strtoknew (cmdtext, idx);
if (! strlen (tmp))
{
SendClientMessage (playerid, COLOR_GRAD2, "Usage: / orguninvite [playerid / name]");
return 1;
}
if (PlayerInfo [playerid] [pOrgMember] == 0) return SendClientMessage (playerid, COLOR_GREY, "You are not in any organization.");

new para1 = ReturnUser (tmp);
if ((IsPlayerConnected para1))
{
if (para1! = INVALID_PLAYER_ID)
{
if (GetDistanceBetweenPlayers (playerid, para1) <= 8 ) // remove
{
if (para1 == playerid)
{
SendClientMessage (playerid, COLOR_GREY, "You can not invite yourself");
return 1;
}
if (gPlayerLogged [para1] == 0)
{
SendClientMessage (playerid, COLOR_GREY, "The player is already in an organization");
return 1;
}

new org = PlayerInfo [playerid] [pOrgMember];
new orgleader = PlayerInfo [playerid] [pOrgLeader];
if (! strcmp (OrgInfo [org] [OrgOwner], GetName (playerid), true)) // return SendClientMessage (playerid, COLOR_GREY, "You are not leader in any organization"); // orgowner bafrage
{
SCM (playerid, -1, "And yes you are the owner");

if (! IsPlayerConnected (para1)) return SendClientMessage (playerid, COLOR_GREY, "The specified player is not logged in!");
if (PlayerInfo [para1] [pOrgMember]! = org) return SendClientMessage (playerid, COLOR_GREY, "The specified player is not member of your organization.");
format (string, sizeof (string), "You were dropped from% s (ID:% i) from the organization '% s'.", PlayerInfo [playerid] [name], playerid, OrgInfo [org] [OrgName]) ;
Send Message Client (para1, COLOR_LIGHTBLUE, string);
format (string, sizeof (string), "% s was dropped from% s by the organization.", PlayerInfo [para1] [name], PlayerInfo [playerid] [name]);
Send Message organization (org, COLOR_PURPLE, string);
PlayerInfo [para1] [pOrgLeader] = 0;
PlayerInfo [para1] [pOrgMember] = 0;
}
else
{
if (orgleader! = org) return SCM (playerid, -1, "You are not a leader of this ORG!");
else
{
if (! IsPlayerConnected (para1)) return SendClientMessage (playerid, COLOR_GREY, "The specified player is not logged in!");
if (PlayerInfo [para1] [pOrgMember]! = org) return SendClientMessage (playerid, COLOR_GREY, "The specified player is not member of your organization.");
if (PlayerInfo [para1] [pOrgLeader] == org) return SCM (playerid, -1, "You can not eject ORG Leader!");
format (string, sizeof (string), "You were dropped from% s (ID:% i) from the organization '% s'.", PlayerInfo [playerid] [name], playerid, OrgInfo [org] [OrgName]) ;
Send Message Client (para1, COLOR_LIGHTBLUE, string);
format (string, sizeof (string), "% s was dropped from% s by the organization.", PlayerInfo [para1] [name], PlayerInfo [playerid] [name]);
Send Message organization (org, COLOR_PURPLE, string);
PlayerInfo [para1] [pOrgLeader] = 0;
PlayerInfo [para1] [pOrgMember] = 0;
}
}
}
else
{
SendClientMessage (playerid, COLOR_GRAD2, "The player is not nearby");
}
}
}
return 1;
}



Error:
[20:40:25] [cmd] Tec9(1): /orguininvite 0
[20:40:25] [debug] Run time error 4: "Array index out of bounds"
[20:40:25] [debug] Attempted to read/write array element at index 10 in array of size 10
[20:40:25] [debug] AMX backtrace:
[20:40:25] [debug] #0 00101b40 in public ocmdOnPlayerCommandText (1, 6991816 in CoL.amx
[20:40:25] [debug] #1 native CallLocalFunction () in samp8888_6755
[20:40:25] [debug] #2 0000078c in public OnPlayerCommandText (1, 69918116) in CoL.amx





Could someone tell me the mistake & how is it out of bounds?

Btw: The Worth "pOrgLeader" & "pOrgMember" of the user "Tec9" are both 10


Enum

pOrgMember,
pOrgRang,
Reply
#2

There is a tutorial on the forum somewhere (I couldn't find it), to be honest this is one of the most common errors and also one of the easiest problems to fix.

There should never be "Array out of bounds" as a scripting help topic!
Reply
#3

Hello playstores, first of all, this code is unreadable, but i'll try to help.

Look for any Variable Array that has size close to 10, add +2 spaces in it, this should solve the problem, because you are passing the size limit of the Defined Array.
Reply
#4

just simply debug your code and see where are you accessing array element what is bigger then array size
strcmp shoudnt be used for commands because its the slowest possible methods, instead you should switch to the pawn.cmd or other methods
and sscanf usage wouldnt also do any harm, because you are just writing wasteful code at the moment
gplayerlogged check doesnt have to be in every command but before command is passed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)