Spectating the player who killed you on death
#1

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;
}
Reply
#2

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
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)