crashdetect errors help
#1

I have these errors with crashdetect plugin can someone tell me how to fix?

Code:
[00:19:54] [debug] Run time error 4: "Array index out of bounds"
[00:19:54] [debug]   Accessing element at index 999 past array upper bound 500
[00:19:54] [debug] Backtrace:
[00:19:54] [debug] #0  000608d8 in public OnPlayerStateChange () from LARP.amx
Reply
#2

Post the code for OnPlayerStateChange, so we can determine the problem.
Reply
#3

Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate != 2) NOPTrigger[playerid] = 0;
    if(IsPlayerNPC(playerid))
	{
	    if(newstate == PLAYER_STATE_SPECTATING)
	    {
        	TogglePlayerSpectating(playerid, false);
		}
		return 1;
	}
	if(GettingSpectated[playerid] != 999)
	{
	    new spectator = GettingSpectated[playerid];
	    if(!IsPlayerConnected(spectator))
	    {
	        GettingSpectated[playerid] = 999;
	        Spectate[spectator] = 999;
		}

	    if(newstate == PLAYER_STATE_DRIVER && PlayerInfo[spectator][pAdmin] >= 2 || newstate == PLAYER_STATE_PASSENGER && PlayerInfo[spectator][pAdmin] >= 2)
	    {
	        TogglePlayerSpectating(spectator, true);
			new carid = GetPlayerVehicleID( playerid );
			PlayerSpectateVehicle( spectator, carid );
			SetPVarInt(spectator, "SpecState", newstate);
	    }
	    else if(newstate == PLAYER_STATE_ONFOOT && PlayerInfo[spectator][pAdmin] >= 2)
	    {
	        TogglePlayerSpectating(spectator, true);
		   	PlayerSpectatePlayer( spectator, playerid );
		   	SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
			SetPVarInt(spectator, "SpecState", newstate);
	    }
	}
	if(newstate == PLAYER_STATE_ONFOOT)
	{
 		if(Audio_IsClientConnected(playerid))
		{
			Audio_Stop(playerid, stationidp[playerid]);
 			stationidp[playerid] = 0;
		}
		
		
	    new spectator = GettingSpectated[playerid];
	    if(PlayerInfo[spectator][pAdmin] >= 2) {
	        // Preventing possible buffer overflows with the arrays
	 		TogglePlayerSpectating(spectator, true);
			PlayerSpectatePlayer( spectator, playerid );
			SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
			SetPVarInt(spectator, "SpecState", newstate);
			SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
			SetPlayerVirtualWorld( spectator, GetPlayerVirtualWorld( playerid ) );
		}

	    if(oldstate == PLAYER_STATE_DRIVER)
		{
			SetPlayerWeaponsEx(playerid);
		}
		else if(oldstate == PLAYER_STATE_PASSENGER) SetPlayerWeaponsEx(playerid);

		if(ConnectedToPC[playerid] == 1337)//mdc
	    {
            SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "* You are now logged off the MDC.");
	        ConnectedToPC[playerid] = 0;
		}
        if(TransportDuty[playerid] > 0)
		{
		    if(TransportDuty[playerid] == 1)
			{
		        TaxiDrivers -= 1;
			}
			else if(TransportDuty[playerid] == 2)
			{
			    BusDrivers -= 1;
			}
			TransportDuty[playerid] = 0;
			new string[42];
			format(string, sizeof(string), "* You are now off duty and earned $%d.", TransportMoney[playerid]);
			SendClientMessageEx(playerid, COLOR_LIGHTBLUE, string);
			GivePlayerCash(playerid, TransportMoney[playerid]);
			ConsumingMoney[playerid] = 1; TransportValue[playerid] = 0; TransportMoney[playerid] = 0;
			SetPlayerColor(playerid, TEAM_HIT_COLOR);
			TransportTime[playerid] = 0;
   			TransportCost[playerid] = 0;
		}
You know how to fix this? Run time error 4: "Array index out of bounds"
Reply
#4

Try changing those 999 to -1

Edit: Or use INVALID_PLAYER_ID
Reply
#5

change all the 999 right?
Reply
#6

Yes, so it would be something like:
pawn Code:
if(GettingSpectated[playerid] != -1)
Alternatively:
pawn Code:
if(GettingSpectated[playerid] != INVALID_PLAYER_ID)
Since I assume that you're setting the variable as 999 to determine that it's an invalid player ID, right?
Reply
#7

Yes right,im going to try it
Reply
#8

I changed onplayerstatechange 999 to -1 and now i have this

Code:
[01:08:17] [debug] Run time error 4: "Array index out of bounds"
[01:08:17] [debug]   Accessing element at index 999 past array upper bound 499
[01:08:17] [debug] Backtrace:
[01:08:17] [debug] #0  00060478 in public OnPlayerStateChange () from LARP.amx
[01:08:17] [debug] Run time error 4: "Array index out of bounds"
[01:08:17] [debug]   Accessing element at negative index -1
[01:08:17] [debug] Backtrace:
[01:08:17] [debug] #0  000608d8 in public OnPlayerStateChange () from LARP.amx
Reply
#9

Do you have this? If not, then you should.
pawn Code:
new GettingSpectated[MAX_PLAYERS], Spectator[MAX_PLAYERS];
Reply
#10

i have only this new GettingSpectated[MAX_PLAYERS];
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)