03.12.2009, 15:58
- Timer System -
Hi, I decided i would finally make a timer system that you can add ID's to so i made and it works perfect!
Basicly you can add the code to a GM FS or INC and use the function SetCountDown( countdownID, minutes, seconds, xpos, ypos );
the timers are textdraw and it includes a timer end callback!
Hope it comes in useful
All the stuff at the topHi, I decided i would finally make a timer system that you can add ID's to so i made and it works perfect!
Basicly you can add the code to a GM FS or INC and use the function SetCountDown( countdownID, minutes, seconds, xpos, ypos );
the timers are textdraw and it includes a timer end callback!
Hope it comes in useful
pawn Код:
#define timers 100
new Text:CDTD [timers];
new CDsec [timers];
new CDmin [timers];
new Float:TDPx [timers];
new Float:TDPy [timers];
new TDTimer [timers];
forward CDTimer(cid);
forward OnCountDownEnd(cid);
pawn Код:
stock SetCountDown(cid, minutes, seconds, Float:x, Float:y)
{
cid++;
CDmin[cid] = minutes;
CDsec[cid] = seconds;
TDPx[cid] = x;
TDPy[cid] = y;
if(CDmin[cid] == 0 && CDsec[cid] == 0)
{
return 0;
}
CDTD[cid] = TextDrawCreate(TDPx[cid],TDPy[cid], "00:00");
TextDrawTextSize(CDTD[cid],636.000000,824.000000);
TextDrawAlignment(CDTD[cid], 2);
TextDrawFont(CDTD[cid],3);
TextDrawLetterSize(CDTD[cid],0.499999,1.800000);
TextDrawColor(CDTD[cid],0xffffffff);
TextDrawSetProportional(CDTD[cid],2);
TextDrawSetShadow(CDTD[cid],1);
TextDrawSetOutline(CDTD[cid], 1);
TDTimer[cid] = SetTimerEx("CDTimer",1000,1,"d",cid);
TextDrawShowForAll(CDTD[cid]);
return cid;
}
pawn Код:
public CDTimer(cid)
{
new string[128];
if(CDsec[cid] >= 1)
{
format(string,sizeof(string), "~w~%02d:%02d",CDmin[cid], CDsec[cid]);
TextDrawSetString(CDTD[cid], string);
CDsec[cid]--;
}
else if(CDsec[cid] == 0 && CDmin[cid] != 0)
{
format(string,sizeof(string), "~w~%02d:%02d",CDmin[cid], CDsec[cid]);
TextDrawSetString(CDTD[cid], string);
CDsec[cid] = 59;
CDmin[cid]--;
}
else if(CDmin[cid] == 0 && CDsec[cid] == 0)
{
OnCountDownEnd(cid);
}
return 1;
}
pawn Код:
public OnCountDownEnd(cid)
{
KillTimer(TDTimer[cid]);
TextDrawDestroy(CDTD[cid]); // keep all this here!
//you can add these so when a specific timer ends you can call a function or event
if(cid == YourTimerID)
{
CallAnEvent();
}
}
pawn Код:
new cdtimer;
dcmd_countdown(playerid, params)
{
new s, m;
if (sscanf(params, "ii", m, s)) SendClientMessage(playerid, YELLOW, "Usage: \"/count [minutes] [seconds]\"");
else
{
SetCountDown(cdtimer, m, s, 100.0, 200.0);
SendFormatMessage(playerid, LIGHTBLUE, "Countdown set for %02d:%02d", m, s);
}
}
public OnCountDownEnd(cid)
{
KillTimer(TDTimer[cid]);
TextDrawDestroy(CDTD[cid]);
if(cid == cdtimer) // the ID
{
GameTextForAll("GO!!", 3000, 4);
PlaySoundForAll(1139);
}
}
- Set timer TD size in function
- Count UP Function
- More customizable parameters [like colour, bold, underlined]
- Fix a known bug [if used in a /coundtdown command and typed twice the beep at the end is non stopping!]
- Plus any other bugs that you find!