[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
#2

Any screenshot ? We must see the texture ...
Reply
#3

I'm willing to test this out, any screenshots?
Reply
#4

I've been away this weekend, I will post some screens later today.
Reply
#5

Good job
Reply
#6

Screenshot... for what? Just have a look at the code.
Reply
#7

Good point, and i thought that, it's just a simple 00:00 clock thing but if they want to see it then il post one later
Reply
#8

Thank you, I will check it out. I hope it's what I think.
Reply
#9

What did you think? I thought 'carrots'.








I'm not drunk, honest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)