Author Topic: Timer Question  (Read 1116 times)

0 Members and 1 Guest are viewing this topic.

Offline Irlandec

  • Soldier
  • **
  • Posts: 176
Timer Question
« on: July 29, 2008, 07:25:14 am »
How to add a timers to commands(every timer i different).
Exmaple:

timer1 for command /test
timer2 for command /do etc.

Here's an exmaple of one timer in my code:
Code: [Select]
var
   k_timer: array[1..32] of integer;

procedure AppOnIdle(Ticks: integer);
var i: integer;
begin
        for i := 1 to 32 do
        if k_timer[I] > 0 then begin
                k_timer[I] := k_timer[I] - 1;
                if k_timer[I] = 0 then
                        WriteConsole(i,'Hunter Kit cooled down, type !kit to get it',cWowItIsAColour);
        end;
end;

and only 1 timer is possible( i dunno, all my tries failed)

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
Re: Timer Question
« Reply #1 on: July 30, 2008, 01:20:34 pm »
you'll have to make one timer for each command
Code: [Select]
var
    test_timer: array[1..32] of integer;
    do_timer: array[1..32] of integer;

procedure ticktimer(timer);
        if timer > 0 then begin
           timer := timer - 1;
           if timer = 0 then
case timer of
    test_timer[i]:WriteConsole(i,'Hunter Kit cooled down, type !kit to get it',cWowItIsAColour);
    (...)
end;
       end;
end;

procedure AppOnIdle(Ticks: integer);
var i: integer;
begin
       for i := 1 to 32 do begin
           ticktimer(test_timer[i]);
           ticktimer(do_timer[i]);
end
end;

or something like that, I didn't tested it
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: Timer Question
« Reply #2 on: July 30, 2008, 03:04:13 pm »
Nah, just use procedure AppOnIdle(Ticks: integer); once and have multiple modulus if-thens inside.

ex:
Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
  //first thing
  if (Ticks % 5) = 0 then
     Whatever1();  //something to do every 5 seconds
  //a different timer
  if (Ticks % 60) = 0 then
     Whatever1();  //something to do every minute
end;

(the descriptions on time probably aren't correct and my code might be syntacticly invalid, but you probably get the idea)
There are other worlds than these

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Timer Question
« Reply #3 on: August 02, 2008, 01:26:12 pm »
@jrgp 60 ticks = 1 second..
and I don't believe % is defined in pascal
so instead:
Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
  //first thing
  if (Ticks mod (60 * 5)) = 0 then
     Whatever1();  //something to do every 5 seconds
  //a different timer
  if (Ticks % (60 * 60) = 0) then
     Whatever1();  //something to do every minute
end;

Offline Irlandec

  • Soldier
  • **
  • Posts: 176
Re: Timer Question
« Reply #4 on: August 03, 2008, 09:32:48 am »
Umm , actuallt I wanted the timer started after command was executed

Offline amb2010

  • Camper
  • ***
  • Posts: 264
  • Fear the dot ...
Re: Timer Question
« Reply #5 on: August 03, 2008, 02:11:27 pm »
Then add a boolean in front of the Ifs so that when you type the command it sets the boolean to true then just set it back to false when you don't want it to do the timer.

-taken from curts example-

Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
  //first thing
  if (start1) then begin
    if (Ticks mod (60 * 5)) = 0 then
      Whatever1();  //something to do every 5 seconds
  end;
  //a different timer
  if (start2) then begin
    if (Ticks % (60 * 60) = 0) then
      Whatever1();  //something to do every minute
  end;
end;

I think that should work....
And as the lyrics go in the United State's national anthem: "America, f**k YEAH!".