Timer help - 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: Timer help (
/showthread.php?tid=91073)
Timer help -
Oi! - 12.08.2009
Okay heres the deal, I made a Job Contract timer for my server, the timer is 25 minutes long, heres how many seconds it is. 1500000. However I put the job contract time in stats in this format "Job contract time left:[%d min]" and instead of telling me how many minutes they have left in their job contract it tells them how many seconds they have left. Is there anyway I can get it to tell them how many minutes they have?
Re: Timer help -
James_Alex - 12.08.2009
visit this
http://forum.sa-mp.com/index.php?topic=91713.0
it's a countdown include
Re: Timer help -
Oi! - 12.08.2009
Nah, I want it to tell them in their stats how many minutes the have left before they can do /quitjob again.
Re: Timer help -
WrathOfGenesis - 12.08.2009
pawn Code:
stock FormatTime ( time )
{
new count;
while ( time > 60 )
{
time = time - 60;
count = count + 1;
}
new string [ 256 ];
format ( string , sizeof ( string ) , "%02d:%02d" , count , time );
return string;
}
Takes a number (Eg. 210) and returns the string: 03:30.
Example of usage:
pawn Code:
printf ( "%s" , FormatTime ( 500 ) );
Re: Timer help -
James_Alex - 12.08.2009
try this
pawn Code:
// put this in the top of the script
new pSec[MAX_PLAYERS];
new pMin[MAX_PLAYERS];
new plSe[MAX_PLAYERS];
// Timers
new STimer[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/contract", true) == 0)
{
STimer[playerid] = SetTimerEx("Seconds", 1000, true, "i", playerid);
pSec[playerid] = 1500000;
plSe[playerid] = 60;
pMin[playerid] = 25;
return 1;
}
if(strcmp(cmdtext, "/stats", true) == 0)
{
new Sstr[128]; format(Sstr, 128, "Contract time left:[%d min / %d second]", pMin[playerid], plSe[playerid]);
SendClientMessage(playerid, 0x33AA33AA, Sstr);
return 1;
}
return 0;
}
forward Seconds(playerid);
public Seconds(playerid)
{
pSec[playerid] -= 1000;
plSe[playerid] --;
if(plSe[playerid] == 0) { plSe[playerid] = 60; pMin[playerid] -= 1; return 1; }
else if(pSec[playerid] == 0)
{
KillTimer(STimer[playerid]);
pMin[playerid] = 0;
pSec[playerid] = 0;
plSe[playerid] = 0;
// do here the function when the timer finish
return 1;
}
return 1;
}