SA-MP Forums Archive
Count down Timer fails - 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: Count down Timer fails (/showthread.php?tid=589206)



Count down Timer fails - DerickClark - 16.09.2015

it only works for id 0 but not all ids. for id 1 i type in /work the message showing for id 1
and sometimes it spams.
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(gMissionInt[playerid] == 1)
    {
        LastOrCurrentVeh[playerid] = vehicleid;
    }
	return 1;
}
Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(gMissionInt[playerid] == 1)
    {
        LastOrCurrentVeh[playerid] = vehicleid;
    }
	return 1;
}
In command
Code:
gMissionInt[playerid] = 1;
truckchecktime = SetTimerEx("TruckCheck", 1000, true, "i", playerid);
Code:
forward TruckCheck(playerid);
public TruckCheck(playerid)
{
    new str[128];
    if (!IsPlayerInAnyVehicle(playerid) || !IsTrailerAttachedToVehicle(LastOrCurrentVeh[playerid])) {
            truckTime[playerid]++;
            format(str, sizeof(str), "Get back in your truck! ~n~or~n~Reconnect your trailer! ~n~(%d)", 30 - truckTime[playerid]);
            GameTextForPlayer(playerid, str, 1000, 3);
            PlayerPlaySound(playerid,1056,0.0,0.0,0.0);
            if (truckTime[playerid] >= 30) {
                KillTimer(truckchecktime);
                StopPlayerJob(playerid);
                SendClientMessage(playerid, COLOR_LIGHTGREEN, "You failed the mission!");
                truckTime[playerid] = 0;
            }
            return 1;
    }
    return 0;
}



Re: Count down Timer fails - Logofero - 16.09.2015

Quote:
Originally Posted by DerickClark
In command

gMissionInt[playerid] = 1;
truckchecktime = SetTimerEx("TruckCheck", 1000, true, "i", playerid);
Most likely error is on commands. Only call id 0 in timer.


Re: Count down Timer fails - DerickClark - 16.09.2015

whats the right timer for that code? and yes its only called for id 0.


Re: Count down Timer fails - Logofero - 16.09.2015

Quote:
Originally Posted by DerickClark
View Post
whats the right timer for that code? and yes its only called for id 0.
Submitted code is valid but you have not given the instruction code where the timer is. Most likely there is error.

Such ridiculous errors occur often due to fatigue, when a programmer ceases to understand simple things.
Tip: Take a break to rest.


Re: Count down Timer fails - DerickClark - 16.09.2015

Quote:
Originally Posted by Logofero
View Post
Submitted code is valid but you have not given the instruction code where the timer is. Most likely there is error.

Such ridiculous errors occur often due to fatigue, when a programmer ceases to understand simple things.
Tip: Take a break to rest.
.. This all of the code..


Re: Count down Timer fails - Logofero - 16.09.2015

I have it
PHP Code:
CMD:mission(playeridparams[]) {
    
gMissionInt[playerid] = 1;
    
truckchecktime SetTimerEx("TruckCheck"1000true"i"playerid);
    return 
1;




Re: Count down Timer fails - DerickClark - 16.09.2015

Quote:
Originally Posted by Logofero
View Post
I have it
PHP Code:
CMD:mission(playeridparams[]) {
    
gMissionInt[playerid] = 1;
    
truckchecktime SetTimerEx("TruckCheck"1000true"i"playerid);
    return 
1;

i did that, didn't work.


Re: Count down Timer fails - Logofero - 16.09.2015

And fixed it
PHP Code:
forward TruckCheck(playerid);
public 
TruckCheck(playerid)
{
    new 
str[128];
    new 
vehicleid GetPlayerVehicleID(playerid);
    if (!
vehicleid || !IsTrailerAttachedToVehicle(vehicleid)) {
            
truckTime[playerid]++;
            
format(strsizeof(str), "Get back in your truck! ~n~or~n~Reconnect your trailer! ~n~(%d)"30 truckTime[playerid]);
            
GameTextForPlayer(playeridstr10003);
            
PlayerPlaySound(playerid,1056,0.0,0.0,0.0);
            if (
truckTime[playerid] >= 30) {
                
KillTimer(truckchecktime);
                
StopPlayerJob(playerid);
                
SendClientMessage(playeridCOLOR_LIGHTGREEN"You failed the mission!");
                
truckTime[playerid] = 0;
            }
            return 
1;
    }
    return 
0;




Re: Count down Timer fails - DerickClark - 16.09.2015

When the mission fails, it reset it.


Re: Count down Timer fails - davve95 - 16.09.2015

I lend the topic a bit, where's the bit that actually makes the timer to count down?. Need to learn that so I ask it here as it's same function...