SA-MP Forums Archive
[SNIPPET] Dynamic Timer System - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [SNIPPET] Dynamic Timer System (/showthread.php?tid=111737)



[SNIPPET] Dynamic Timer System - [HLF]Southclaw - 03.12.2009

- 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:



Re: [SNIPPET] Dynamic Timer System - MJ! - 03.12.2009

Any screenshot ? We must see the texture ...


Re: [SNIPPET] Dynamic Timer System - KnooL - 05.12.2009

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


Re: [SNIPPET] Dynamic Timer System - [HLF]Southclaw - 06.12.2009

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


Re: [SNIPPET] Dynamic Timer System - RyDeR` - 06.12.2009

Good job


Re: [SNIPPET] Dynamic Timer System - Harry_Gaill - 06.12.2009

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


Re: [SNIPPET] Dynamic Timer System - [HLF]Southclaw - 06.12.2009

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



Re: [SNIPPET] Dynamic Timer System - Benne - 06.12.2009

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


Re: [SNIPPET] Dynamic Timer System - [HLF]Southclaw - 06.12.2009

What did you think? I thought 'carrots'.








I'm not drunk, honest.