Server crash when use Spectate
#1

Here's the script. When i choose case 0 or 1. My server got crashed D:

OnPlayerKeyStateChange
Код HTML:
[04:07:36] [debug] Run time error 4: "Array index out of bounds"
[04:07:36] [debug]  Accessing element at index 51 past array upper bound 49
[04:07:36] [debug] AMX backtrace:
[04:07:36] [debug] #0 0004d4a0 in ?? (2, 0, 0) from gamemode.amx
[04:07:36] [debug] #1 000a980c in public GAC_OnPlayerKeyStateChange (2, 4, 0) from gamemode.amx
[04:07:36] [debug] #2 native CallLocalFunction () from samp03svr
[04:07:36] [debug] #3 000114f0 in public ATT_OnPlayerKeyStateChange (2, 4, 0) from gamemode.amx
[04:07:36] [debug] #4 00008f30 in public OnPlayerKeyStateChange (2, 4, 0) from gamemode.amx
Код:
        if(AccInfo[playerid][spec] && PlayerInfo[playerid][VIP] != 0)
 	{
            if(newkeys & KEY_LOOK_BEHIND && IsPlayerSpectating(playerid))
	    {
	   		cmd_specoff(playerid, "");
	    }
	    else if(newkeys & KEY_FIRE && IsPlayerSpectating(playerid))
	    {
	        UpdatePlayerSpectating(playerid, 0, false);
	    }
	    else if(newkeys & KEY_ACTION && IsPlayerSpectating(playerid))
	    {
			UpdatePlayerSpectating(playerid, 1, false);
	    }
	}
OnPlayerDisconnect
Код HTML:
[08:32:33] [debug] Run time error 5: "Invalid memory access"
[08:32:33] [debug] AMX backtrace:
[08:32:33] [debug] #0 00000780 in public OnPlayerDisconnect () from gamemode.amx
[08:32:33] [debug] #1 0004d504 in ?? (1, 0, 0) from gamemode.amx
[08:32:33] [debug] #2 000a980c in public GAC_OnPlayerKeyStateChange (1, 4, 0) from gamemode.amx
[08:32:33] [debug] #3 native CallLocalFunction () from samp03svr
[08:32:33] [debug] #4 000114f0 in public ATT_OnPlayerKeyStateChange (1, 4, 0) from gamemode.amx
[08:32:33] [debug] #5 00008f30 in public OnPlayerKeyStateChange (1, 4, 0) from gamemode.amx
Код:
        foreach(new i : Player)
	{
		if(IsPlayerSpectating(i))
		{
		    if(AccInfo[i][spec] && AccInfo[i][specid] == playerid)
		    {
		        UpdatePlayerSpectating(i, 0, true);
			}
		}
	}
Da Function
Код HTML:
UpdatePlayerSpectating(playerid, type = 0, bool:forcestop = false)
{
	switch(type)
	{
	    case 0:
	    {
			new check = 0;
			
			foreach(new i : Player)
			{
				if(i < AccInfo[i][specid]) i = (AccInfo[playerid][specid] + 1);
			    if(i > GetPlayerPoolSize()) i = 0, check += 1;

				if(check > 1) break;

				if(IsPlayerSpawned(i))
				{
					if(i != playerid)
					{
			    		if(!IsPlayerSpectating(i))
			    		{
							SetPlayerSpectating(playerid, i);
			    			break;
						}
					}
				}
		 	}

		 	if(forcestop)
			{
				cmd_specoff(playerid, "");
				SendClientMessage(playerid, red, "** There was no player to spectate further");
		 	}
		 	else
		 	{
		 	    SetPlayerSpectating(playerid, AccInfo[playerid][specid]);
		 	}
	 	}
	 	case 1:
	 	{
			new check = 0;
			
			foreach(new i : Player)
			{
				if(i > AccInfo[i][specid]) i = (AccInfo[playerid][specid] - 1);
			    if(i < 0) i = GetPlayerPoolSize(), check += 1;

				if(check > 1) break;

				if(IsPlayerSpawned(i))
				{
					if(i != playerid)
					{
			    		if(! IsPlayerSpectating(i))
			    		{
							SetPlayerSpectating(playerid, i);
							break;
						}
					}
				}
		 	}

		 	if(forcestop)
			{
				cmd_specoff(playerid, "");
				SendClientMessage(playerid, red, "** There was no player to spectate back");
	 		}
		 	else
		 	{
		 	    SetPlayerSpectating(playerid, AccInfo[playerid][specid]);
		 	}
	 	}
	 	case 2:
	 	{
	 	    if(GetPlayerInterior(playerid) != GetPlayerInterior(AccInfo[playerid][specid]))
		    {
		    	AC_BS_SetPlayerInterior(playerid, GetPlayerInterior(AccInfo[playerid][specid]));
		   	}
		    if(GetPlayerVirtualWorld(playerid) != GetPlayerVirtualWorld(AccInfo[playerid][specid]))
		    {
		    	AC_BS_SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(AccInfo[playerid][specid]));
		    }

		    if(IsPlayerInAnyVehicle(AccInfo[playerid][specid]))
		    {
		        PlayerSpectateVehicle(playerid, GetPlayerVehicleID(AccInfo[playerid][specid]));
		    }
		    else
		    {
		        PlayerSpectatePlayer(playerid, AccInfo[playerid][specid]);
		    }
	 	}
	}
	return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)