Debugs and run time errors
#1

Each time a player logs in I get these errors
Код:
[18:13:19] Incoming connection: 41.227.56.26:59801
[18:13:19] [debug] Run time error 4: "Array index out of bounds"
[18:13:19] [debug]  Accessing element at negative index -1
[18:13:19] [debug] AMX backtrace:
[18:13:19] [debug] #0 0006122c in public Audio_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\gamemodes\CSRP.pwn:9792
[18:13:19] [debug] #1 native CallLocalFunction () [080d2870] from samp03svr
[18:13:19] [debug] #2 00015480 in public SSCANF_OnPlayerDisconnect (... <2 arguments>)  at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\pawno\include\audio.inc:166
[18:13:19] [debug] #3 0000e7c0 in public Itter_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\pawno\include\sscanf2.inc:184
[18:13:19] [debug] #4 native CallLocalFunction () [080d2870] from samp03svr
[18:13:19] [debug] #5 00002248 in public Streamer_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\pawno\include\foreach.inc:715
[18:13:19] [debug] #6 native CallLocalFunction () [080d2870] from samp03svr
[18:13:19] [debug] #7 00000dd4 in public OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\pawno\include\streamer.inc:361
[18:13:19] [part] Star_Bontano has left the server (0:1)
[18:13:26] Incoming connection: 41.227.56.26:59802
[18:13:30] [join] Amir_Bontano has joined the server (0:41.227.56.26)
[18:13:39] Amir_Bontano has logged in.
[18:13:39]  Loading Amir_Bontano's vehicles.
[18:13:39]  Loading all vehicles mods.
[18:13:40] [debug] Run time error 4: "Array index out of bounds"
[18:13:40] [debug]  Accessing element at index 999 past array upper bound 499
[18:13:40] [debug] AMX backtrace:
[18:13:40] [debug] #0 000883e8 in public OnPlayerStateChange (playerid=0, newstate=8, oldstate=0) at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\gamemodes\CSRP.pwn:13219
[18:13:40] [debug] Run time error 4: "Array index out of bounds"
[18:13:40] [debug]  Accessing element at negative index -1
[18:13:40] [debug] AMX backtrace:
[18:13:40] [debug] #0 000889ec in public OnPlayerStateChange (playerid=0, newstate=1, oldstate=8) at C:\Users\SU Gaming\Documents\Casey's Server\Crimson Streets Roleplay [ENG]2\Crimson Streets Roleplay [ENG]\gamemodes\CSRP.pwn:13250
This is my 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] != -1)
	{
		new spectator = GettingSpectated[playerid];
		if(!IsPlayerConnected(spectator))
		{
			GettingSpectated[playerid] = -1;
			Spectate[spectator] = -1;
		}

		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(!IsPlayerConnected(spectator))
        {
            GettingSpectated[playerid] = -1;
            Spectate[spectator] = -1;
        }

        if(newstate == PLAYER_STATE_DRIVER && PlayerInfo[spectator][pAdmin] >= 2 || newstate == PLAYER_STATE_PASSENGER && PlayerInfo[spectator][pAdmin] >= 2)
        {
			SetPlayerWeaponsEx(playerid);
		}
		else if(oldstate == PLAYER_STATE_PASSENGER) SetPlayerWeaponsEx(playerid);
Reply
#2

The errors are at

Код:
spectate[spectator] = -1
Reply
#3

Please help me...Many views no replies :/
Reply
#4

When you declare for example [MAX_PLAYERS], it's from 0 to 499 (if MAX_PLAYERS equals to 500). So, doing
pawn Код:
new
    something[ MAX_PLAYERS ]
;

// somewhere
if(something[-1] == value)
// OR
new
    sth = -1
;
if(something[sth] == value)
makes it:

Run time error 4: "Array index out of bounds"
Accessing element at negative index -1


In order to prevent this, check if the value is not -1 and do the rest. If it's -1 and you continue, the run time error will be appeared again.
Reply
#5

I changed -1 to 498 and sent the script to my friend but she didn't test it.Do you think it will work?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)