[SNIPPET] Dynamic Timer System
#1

- 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 top
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);
The Actual Function [Kind Of Important!]
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;
}
The main Callback
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;
}
The End Callback
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();
    }
}
Here is a example of a /countdown function:
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);
    }
}
Next Version:
  • 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!

Reply


Messages In This Thread
[SNIPPET] Dynamic Timer System - by [HLF]Southclaw - 03.12.2009, 15:58
Re: [SNIPPET] Dynamic Timer System - by MJ! - 03.12.2009, 18:36
Re: [SNIPPET] Dynamic Timer System - by KnooL - 05.12.2009, 13:39
Re: [SNIPPET] Dynamic Timer System - by [HLF]Southclaw - 06.12.2009, 10:40
Re: [SNIPPET] Dynamic Timer System - by RyDeR` - 06.12.2009, 17:17
Re: [SNIPPET] Dynamic Timer System - by Harry_Gaill - 06.12.2009, 17:31
Re: [SNIPPET] Dynamic Timer System - by [HLF]Southclaw - 06.12.2009, 18:50
Re: [SNIPPET] Dynamic Timer System - by Benne - 06.12.2009, 19:07
Re: [SNIPPET] Dynamic Timer System - by [HLF]Southclaw - 06.12.2009, 20:19

Forum Jump:


Users browsing this thread: 1 Guest(s)