Player Death Spectate Bug
#1

I'm having a problem with the script below. Everything runs smoothly. But when you die. It just spawns you. It doesn't spec the killer. Could I get some help? I've pretty much tried everything I know.



Код:
#include <a_samp>

#define PLAYERS 390 // Number of your player slots
#define PlayerLoop(%1) for(new %1=0; %1<PLAYERS,IsPlayerConnected(%1);%1++)


//======================================================================Settings

//#define RespawnOption // Comment this if you don't want to give players the option to skip speccing their killer

#define SpawnTime 5 // Time player spectates his kill, in seconds

//#define SpawnCamera // Comment out if you want player to instantly spawn if no one killed him

//Camera positions for when player just dies
#define CamX 0.0
#define CamY 0.0
#define CamZ 0.0

#define CamLX 0.0
#define CamLY 0.0
#define CamLZ 0.0


new PlayerSpec[PLAYERS] = -1;

public OnPlayerConnect(playerid)
{
  PlayerSpec[playerid] = -1;
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	PlayerLoop(i)
	{
	  if(PlayerSpec[playerid] == i)
	  {
			ExitSpec(i);
	  }
	}
	return 1;
}

public OnPlayerSpawn(playerid)
{
  PlayerSpec[playerid] = -1;
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	if(killerid == INVALID_PLAYER_ID)
	{
	  #if defined SpawnCamera
	  SetPlayerCameraLookAt(playerid, CamLX, CamLY, CamLZ);
	  SetPlayerCameraPos(playerid, CamX, CamY, CamZ);
	  #else
	  SpawnPlayer(playerid);
	  #endif
	}
	else
	{
		TogglePlayerSpectating(playerid, true);
		if(IsPlayerInAnyVehicle(killerid))PlayerSpectateVehicle(playerid, GetPlayerVehicleID(killerid));
		else PlayerSpectatePlayer(playerid, killerid);
		PlayerSpec[playerid] = killerid;
		PlayerLoop(i)
		{
			if(playerid == PlayerSpec[i])
			{
				TogglePlayerSpectating(i, true);
				if(IsPlayerInAnyVehicle(killerid))PlayerSpectateVehicle(i, GetPlayerVehicleID(killerid));
				else PlayerSpectatePlayer(i, killerid);
				PlayerSpec[i] = killerid;
				SetTimerEx("ExitSpec", SpawnTime*1000, false, "d", i);
			}
		}
		SetTimerEx("ExitSpec", SpawnTime, false, "d", playerid);
	}
	return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	#if defined RespawnOption
	if(newkeys == KEY_SPRINT)
	{
 		ExitSpec(playerid);
	}
	#endif
	return 1;
}

forward ExitSpec(id);
public ExitSpec(id)
{
	TogglePlayerSpectating(id, false);
	SpawnPlayer(id);
}
Reply
#2

Maybe this can help:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
      TogglePlayerSpectating(playerid, true);
        if(IsPlayerInAnyVehicle(killerid))PlayerSpectateVehicle(playerid, GetPlayerVehicleID(killerid));
        else PlayerSpectatePlayer(playerid, killerid);
        PlayerSpec[playerid] = killerid;
        PlayerLoop(i)
        {
            if(playerid == PlayerSpec[i])
            {
                TogglePlayerSpectating(i, true);
                if(IsPlayerInAnyVehicle(killerid))PlayerSpectateVehicle(i, GetPlayerVehicleID(killerid));
                else PlayerSpectatePlayer(i, killerid);
                PlayerSpec[i] = killerid;
                SetTimerEx("ExitSpec", SpawnTime*1000, false, "d", i);
            }
        }
        SetTimerEx("ExitSpec", SpawnTime, false, "d", playerid);
    }
    return 1;
}
Reply
#3

Your loop is also wrong. If you have 10 players connected and playerid 3 disconnected, then the loop will stop at 3 and not go to 10
Reply
#4

I COULD tell you the answer but instead i'll let you learn on your own, trust me its worth it so you don't ever have this problem again, try out my "Who Killed Me?" Filterscript included in my signature and open it in pawno and try learning from it, its nothing but timers and text
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)