SA-MP Forums Archive
OnPlayerStateChange Crashdetect problem! - 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: OnPlayerStateChange Crashdetect problem! (/showthread.php?tid=506616)



OnPlayerStateChange Crashdetect problem! - Kenway - 13.04.2014

I have a problem every time i login the server crash because of the OnPlayerStateChange

Crashdetect code:
Код:
[20:48:58] [debug] Run time error 4: "Array index out of bounds"
[20:48:58] [debug]  Accessing element at index 999 past array upper bound 500
[20:48:58] [debug] AMX backtrace:
[20:48:58] [debug] #0 0007cdac in public OnPlayerStateChange (0x00000000, 0x00000001, 0x00000008) from UGRP.amx
[20:49:06] [debug] Server crashed while executing UGRP.amx
The code that doing it:
Код:
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);
	    }
	}
or this

Код:
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 ) );
		}



Re: OnPlayerStateChange Crashdetect problem! - Konstantinos - 13.04.2014

On the last one, do you check if GettingSpectated[playerid] is not 999? If not, do that to prevent it.


Re: OnPlayerStateChange Crashdetect problem! - Kenway - 13.04.2014

So make it GettingSpectated[playerid] != INVAILD_PLAYER_ID?


Re: OnPlayerStateChange Crashdetect problem! - Konstantinos - 13.04.2014

Not INVALID_PLAYER_ID but 999 instead.
pawn Код:
if(GettingSpectated[playerid] != 999)
{
    // second code here
}



Re: OnPlayerStateChange Crashdetect problem! - Kenway - 13.04.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Not INVALID_PLAYER_ID but 999 instead.
pawn Код:
if(GettingSpectated[playerid] != 999)
{
    // second code here
}
doing now this

Код:
[22:21:55] [debug] Server crashed while executing UGRP.amx
[22:21:55] [debug] AMX backtrace:
[22:21:55] [debug] #0 ffffffff in public OnPlayerClickMap () from UGRP.amx



Re: OnPlayerStateChange Crashdetect problem! - Kenway - 13.04.2014

help


Re: OnPlayerStateChange Crashdetect problem! - Konstantinos - 13.04.2014

Posting OnPlayerClickMap callback would be helpful.


Re: OnPlayerStateChange Crashdetect problem! - Kenway - 13.04.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Posting OnPlayerClickMap callback would be helpful.
The problem I dont have this call back in the script and my plugins are streamer 2.7.1 and sscanf


Re: OnPlayerStateChange Crashdetect problem! - Kenway - 14.04.2014

?


Re: OnPlayerStateChange Crashdetect problem! - Kenway - 14.04.2014

NO ONE