SA-MP Forums Archive
Spectating the player who killed you on death - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Spectating the player who killed you on death (/showthread.php?tid=185569)



Spectating the player who killed you on death - Haydz - 25.10.2010

My script works fine apart from when you get killed you spec a player and it constantly goes -1 -2 -3 etc and doesn't stop,

i want it to be Respawning in %d(countdown from 5) and when the timer hits 0 he gets respawned and starts playing again.

my code.

Код:
new spectateTimer[MAX_PLAYERS];

forward respawnCounter(playerid);

public OnPlayerDeath(playerid, killerid, reason)
{
    TogglePlayerSpectating(playerid, 1);
    PlayerSpectatePlayer(playerid, killerid);
    spectateTimer[playerid] = SetTimerEx("respawnCounter", 1000, true, "d" , playerid);
    return 1;
}
public respawnCounter(playerid)
{
    new string[21];
    format(string, sizeof(string), "Respawning in %d", GetPVarInt(playerid, "rCount"));
    GameTextForPlayer(playerid, string, 1000, 4);
    
    SetPVarInt(playerid, "rCount", GetPVarInt(playerid, "rCount")-1);
    if(GetPVarInt(playerid, "rCount") == 0)
    {
        TogglePlayerSpectating(playerid, 0);
        KillTimer(spectateTimer[playerid]);
        SetPVarInt(playerid, "rCount", 0);
    }
    return 1;
}



Re: Spectating the player who killed you on death - JaTochNietDan - 25.10.2010

Well you've got almost everything right except one thing, if you want it to start at 5 and finish at 0, then you need to set the PVar to 5 in the first place!

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    TogglePlayerSpectating(playerid, 1);
    PlayerSpectatePlayer(playerid, killerid);
    SetPVarInt(playerid,"rCount",5); // See here, set it to 5 before the countdown starts
    spectateTimer[playerid] = SetTimerEx("respawnCounter", 1000, true, "d" , playerid);
    return 1;
}
That should fix the issue


Re: Spectating the player who killed you on death - Haydz - 25.10.2010

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Well you've got almost everything right except one thing, if you want it to start at 5 and finish at 0, then you need to set the PVar to 5 in the first place!

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    TogglePlayerSpectating(playerid, 1);
    PlayerSpectatePlayer(playerid, killerid);
    SetPVarInt(playerid,"rCount",5); // See here, set it to 5 before the countdown starts
    spectateTimer[playerid] = SetTimerEx("respawnCounter", 1000, true, "d" , playerid);
    return 1;
}
That should fix the issue
tested and works, thanks alot.