how to spec player
#1

hello, how to spec player when the playerid death spec the killered for 5 seconds and write Your Killer: %s?
Reply
#2

You'll have to use TogglePlayerSpectating, PlayerSpectatePlayer, SetTimerEx and GameText or Textdraw.
Under OnPlayerDeath, check if the killerid is valid(IsPlayerConnected). If valid, store his ID inside a global variable. Now under OnPlayerSpawn, check if that global variable has a valid killerid(validate it). If the killerid is connected, use TogglePlayerSpectating and PlayerSpectatePlayer to spectate killerid, then set a timer to stop spectating(TogglePlayerSpectating again) and add a GameText to display for 5 seconds.
Reply
#3

add this on the top of your script:

PHP код:
forward FinishPlayerSpectatePlayer(playerid); 
and You can use these codes in OnPlayerDeath:

PHP код:
         TogglePlayerSpectating(playerid1);
         new 
str[128];
         new 
pname;
         
GetPlayerName(killerid pname MAX_PLAYER_NAME);
         
format(strsizeof(str),"Your Killer Is  %s."pname);
         
SendClientMessage(playerid , -str);
         
PlayerSpectatePlayer(playeridkillerid);
         
SetTimerEx("FinishPlayerSpectatePlayer"50000"i"playerid); 
and then after that add this public/callback in your script

PHP код:
public FinishPlayerSpectatePlayer(playerid)
{
    
TogglePlayerSpectating(playerid0);
    return 
1;

Reply
#4

^ I'm not very sure myself, but I think you can't spectate others under OnPlayerDeath. Correct me if I'm wrong, because I think you automatically respawn after death.
Reply
#5

You can spec + rep and ill try out
Reply
#6

pawn Код:
#defien SpectateTimer 5 // Second
forward DeathTimerFinished(playerid);

public OnPlayerDeath(playerid, killerid, reason)
{
if(IsPlayerConnected(killerid))
{
TogglePlayerSpectating(playerid, 1);
if(IsPlayerInAnyVehicle(killerid)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(killerid));
else PlayerSpectatePlayer(playerid, killerid);
SetTimerEx("DeathTimerFinished", SpectateTime*1000, 0, "d", playerid);
new KillerName[MAX_PLAYER_NAME];
GetPlayerName(killerid, KillerName, sizeof KillerName);
new string[70];
format(string, sizeof string, "%s has been killed you.", KillerName);
GameTextForPlayer(playerid, string, SepctateTimer*1000, 6);
}
return 1;
}

public DeathTimerFinished(playerid)
{
return TogglePlayerSpectating(playerid, 0);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)