SA-MP Forums Archive
Timer is going negative. - 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)
+--- Thread: Timer is going negative. (/showthread.php?tid=562677)



Timer is going negative. - GuitarMan - 10.02.2015

Hello.
Im using admantis afterlife system (https://sampforum.blast.hk/showthread.php?pid=990124#pid990124) on my GM. It works just fine if im alone. After dieing, it counts 30 secs and then spawns me into hospital. The problem is, when multiple players die (at least i think so) and try to revive the timer(SecsToGo[playerid]) glitches and goes negative and it would never ever stop

So heres my code:

PHP код:
public AfterLife(playerid)
{
        
IsAfterLifing[playerid] = 1;
    
SecsToGo[playerid]--;
        new 
string[128];
        
format(string,sizeof(string),"~b~ ~h~ ~h~Tu You' ve passed out~n~ ~b~ ~h~ ~h~You're gona be just fine in  %d seconds.",SecsToGo[playerid]);
        
GameTextForPlayer(playerid,string,1100,3);
        if (
SecsToGo[playerid] <= 0)
    {
        
CleanPlayerChat(playerid);
        
KillTimer(AfterLifeTimer);
        
SCM(playerid,COLOR_RED,"--------------------------------------------------------");
            
SCM(playerid,WHITE,"-");
            
SCM(playerid,WHITE,"-");
            
SCM(playerid,WHITE,"-");
            
SCM(playerid,COLOR_RED,"--------------------------------------------------------");
            
SetPlayerVirtualWorld(playerid0);
            
SetPlayerPos(playerid1598.2131,1172.3086,1025.3767);
            
SetCameraBehindPlayer(playerid);
               
TogglePlayerControllable(playerid,true);
            return 
1;
        }
        return 
1;

.

This is the command to start the afterlife process:
PHP код:
CMD:acceptdeath(playeridparams[])
{
        
#pragma unused params
        
if (IsDead[playerid] == 0) { return 0; }
        else
        {
            
IsDead[playerid] = 0;
            
SecsToGo[playerid] = AFTERLIFE_SECONDS;
            
CleanPlayerChat(playerid);
               
ResetWeapon(playerid);
            
SCM(playerid,COLOR_RED,"--------------------------------------------------------");
            
SCM(playerid,WHITE,"Tu esi miris. Atputies. ");
            
SCM(playerid,WHITE,"Kad atdzimsi, busi aizmirsis visu, kas notika pedejo 30 min laika.");
            
SCM(playerid,WHITE,"Ja tevi nogalinaja NeRPiski, zino foruma.");
            
SCM(playerid,COLOR_RED,"--------------------------------------------------------");
    
SetPlayerVirtualWorld(playerid0);
        
SetPlayerInterior(playerid0);
    
SetPlayerPos(playerid,1194.5045,-1335.0654,13.3984-15);
            
SetPlayerCameraPos(playerid,1194.5045,-1335.0654,13.3984);
            
SetPlayerCameraLookAt(playerid,1178.5105,-1314.2529,14.0983);
            
AfterLifeTimer SetTimerEx("AfterLife",1000,true,"i",playerid);
            return 
1;
         }

And the define for the Afterlife secounds.
PHP код:
#define AFTERLIFE_SECONDS           30 
I just dont get it. There is a check that prevents it from going negative....
PHP код:
        if (SecsToGo[playerid] <= 0



Re: Timer is going negative. - Abagail - 10.02.2015

A simple mistake.

You put the loop parameter to true; when to my knowledge it should be false.

Replace:
pawn Код:
AfterLifeTimer = SetTimerEx("AfterLife",1000,true,"i",playerid);
With:
pawn Код:
AfterLifeTimer = SetTimerEx("AfterLife",1000,false,"i",playerid);



Re: Timer is going negative. - Jefff - 10.02.2015

replace on top
pawn Код:
new AfterLifeTimer; // its global for only one player
to
pawn Код:
new AfterLifeTimer[MAX_PLAYERS]; // its for each player
then
pawn Код:
AfterLifeTimer[playerid] = SetTimerEx(...);
and
pawn Код:
KillTimer(AfterLifeTimer[playerid]);



Re: Timer is going negative. - GuitarMan - 10.02.2015

Thanks, works like a charm!