SA-MP Forums Archive
Index out of bounds - 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: Index out of bounds (/showthread.php?tid=434845)



Index out of bounds - thefatshizms - 04.05.2013

When someone dies (OnPlayerDeath) I get array index out of bounds from crash detect.

I think it comes from this piece of code:

pawn Код:
if(IsPlayerCivilianClass(killerid) || gTeam[killerid] == MECHANIC || gTeam[killerid] == HITMAN) {
        WantedLevel[killerid]+=4;
        CallLocalFunction("OnPlayerCommitCrime", "iis", killerid, WantedLevel[killerid], "Killed a player");
        format(G_String, 128, "[CRIME] %s has killed %s", PlayerName(killerid), PlayerName(playerid));
        SendClientMessageToAll(COLOR_SKYBLUE, G_String);
        format(G_String, 128, "[CRIME COMMITED] %s has murdered %s Location: %s Wanted Level: %d", PlayerName(killerid), PlayerName(playerid), PlayerZone(killerid), WantedLevel[killerid]);
        SendMessageToLaw(COLOR_BLUE1, G_String);
    }
But I'm not sure what's causing it.


Re: Index out of bounds - Yashas - 04.05.2013

Show your Wanted Level Declaration.


Re: Index out of bounds - thefatshizms - 04.05.2013

new WantedLevel[MAX_PLAYERS];


Re: Index out of bounds - Yashas - 04.05.2013

Show gTeam and the SendMessage Function.


Re: Index out of bounds - ryansheilds - 04.05.2013

You did check if killerid was invalid? Otherwise it's obviously going to be out of bounds.


Re: Index out of bounds - thefatshizms - 04.05.2013

EDit: Forgot to check if it's invalid :P


Re: Index out of bounds - caki - 04.05.2013

pawn Код:
if(killerid != INVALID_PLAYER_ID) // Valid killer, give cash+score
{
    PlayerInfo[killerid][pKills] += 1;
}
 
    // Outside the check, handle stuff for playerid
    // if killerid was INVALID_PLAYER_ID the player killed themselves (i.e. falling)
Just an example. Try to use it this way it should work


Re: Index out of bounds - RajatPawar - 04.05.2013

Comment out each line, and see what gives that error and what doesn't.