Author Topic: Help with timer...  (Read 1372 times)

0 Members and 1 Guest are viewing this topic.

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Help with timer...
« on: April 25, 2008, 09:57:44 am »
I'm trying to make a timer, which calculates [Human] health every second (no, rly about one millisecond)
adn:
Code: [Select]
if GetPlayerStat(Human, 'Health') <> 90 then begin
Dodamage(Human, 1000)

but help with that, cause i made a calculator that wont work:
it has that ^^^^ "thing" in it
Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
 if Ticks mod (20 * 1) = 0 then begin
  if Getplayerstat(Human,'Health') <> 90 then begin
  DoDamage(Human,1000);
  end;
 end;
end;

But only problem is that human is unknown identifier... i have no idea how to make it to be :D
Also Known As REIMA


Lol Happles (happy apples)

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Help with timer...
« Reply #1 on: April 25, 2008, 10:25:01 am »
Code: [Select]
procedure AppOnIdle(Ticks: integer);
var
  Human: Integer;
begin
  if Ticks mod (20 * 1) = 0 then begin
    if Getplayerstat(Human,'Health') <> 90 then begin
      DoDamage(Human,1000);
    end;
  end;
end;
Human will default to 0, so set it if you actually want to check a players (who is this "Human"?) health. And why would you want to kill him if his health isn't exactly 90...? A little sadistic, are we? Also, AppOnIdle will run every second, so you can't check a players health more often than that (you could use OnPlayerDamage, though).

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Help with timer...
« Reply #2 on: April 25, 2008, 10:35:14 am »
Thank you Boble.. i can delete all my typing now :p

Anyway, you COULD check the player health more often than every second, using sleep:

Code: [Select]
const:
TIMER : 100 //this would mean 100 times per second

Procedure AppOnIdle(Ticks: integer);
var
  i: integer
begin
  for i:=0 to TIMER do begin
    //...wutever you want to do
    Sleep(1000/TIMER);
  end;
end;

Your processor might not be happy with this though. Like Boble said it would be better to use OnPlayerDamage. But i don't know if that will react when the player picks up a medkit.

Anyway.. i really wonder what you want to do here... who do you want to kill unless it's health is 90?
 
Come join: EliteCTF
Listen to: My Music

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Help with timer...
« Reply #3 on: April 25, 2008, 10:54:28 am »
Damnit, Bob for short...


Also, AppOnIdle - first with sleep(10) looped 100 times, then recompiled (// ftw) without. It didn't do as much as I thought, but still not really what you want.
Code: [Select]
17:50:52   50:52:885
17:50:53   50:53:909
17:50:54   50:54:947
17:50:55   50:55:957
17:50:56   50:56:984
17:50:58   50:58:000
17:50:59   50:59:023
17:51:00   51:00:071
17:51:01   51:01:112
17:51:02   51:02:142
17:51:02   /recompile Test (127.0.0.1)
17:51:02    [*] Compiling Test -> Test.pas...
17:51:02    [*] Compilation Complete.
17:51:02   51:02:267
17:51:03   51:03:265
17:51:04   51:04:264
17:51:05   51:05:262
17:51:06   51:06:261
17:51:07   51:07:274
17:51:08   51:08:273
17:51:09   51:09:271
17:51:10   51:10:269
17:51:11   51:11:266
17:51:12   51:12:265
17:51:13   51:13:263

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: Help with timer...
« Reply #4 on: April 25, 2008, 11:23:17 am »
Okay, from the beginning to the very end:
First of all... when player joins, he loses 10 health. So he have 90, right? Then; if player WONT have 90, he will die. Basicly, if you get some bonus... like Medikit, serk or pred, ur hp will go up to 100 (adn then u die)
thats what iam upto :D

But my only problem is still to get that identifier working... maybe i'll be fine with the "check hp every second" thing :D
Also Known As REIMA


Lol Happles (happy apples)

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Help with timer...
« Reply #5 on: April 25, 2008, 12:20:24 pm »
To perform an action for all players, you need to use a loop - like for.
Code: [Select]
procedure AppOnIdle(Ticks: Integer);
var
  i: Integer;
begin

  // a "for" loop
  for i := 1 to 32 do
    if GetPlayerStat(i, 'Active') then
      if GetPlayerStat(i, 'Health') <> 90 then
        DoDamage(i, 1000);

  // This will, every second, check all the active
  // players health, and if it's not 90, kill them.
 
end;
Note that default health is not 100.

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: Help with timer...
« Reply #6 on: April 25, 2008, 02:05:15 pm »
Ok thx ::D
It's 150 then, rite?
Also Known As REIMA


Lol Happles (happy apples)

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Help with timer...
« Reply #7 on: April 25, 2008, 02:17:55 pm »
first of all.. sorry 'Bob' :)
and sorry shantec for hijacking your topic :p
edit: ow, 150 is right


well i never said that a hundred times sleep 10 would work 'well'.. i said it would work.. i did some testing of my own (not using recompile, but timer as a variable). Timer starts as 1 :

Code: [Select]
(20:57:49) 04:48:702
(20:57:49) 04:49:702
(20:57:50) /timer 2 (127.0.0.1)
(20:57:50) timer = 2
(20:57:50) 04:50:702
(20:57:52) 04:52:593  //<----here it kicks in
(20:57:53) 04:53:093
(20:57:54) 04:53:593
//---cut
(20:57:59) 04:59:124
(20:57:59) /timer 10 (127.0.0.1)
(20:57:59) timer = 10
(20:57:59) 04:59:624
(20:58:00) 04:00:124
(20:58:00) 04:00:624
(20:58:01) 04:01:124
(20:58:01) 04:01:624
(20:58:02) 04:02:124
(20:58:02) 04:02:624
(20:58:03) 04:03:124
(20:58:04) 04:04:593  //<--here it kicks in
(20:58:04) 04:04:702
(20:58:04) 04:04:796
(20:58:05) 04:04:905
(20:58:05) 04:04:999
(20:58:05) 04:05:093
(20:58:05) 04:05:202
(20:58:05) 04:05:296
(20:58:05) 04:05:405
(20:58:05) 04:05:499
//--cut
(20:58:12) /timer 100 (127.0.0.1)
(20:58:12) timer = 100
(20:58:12) 04:10:874
(20:58:12) 04:10:968
(20:58:12) 04:11:077
(20:58:12) 04:11:171
//-cut, now from the command window, arsse couldn't keep up with this (also SOMEWHERE (21/22 sec) in between it kicks in):
04:24:093
04:24:109 //1
04:24:124 //2
04:24:124 //3
04:24:140 //4
04:24:155 //5
04:24:171 //6
04:24:171 //7
04:24:187 //8.. aww
04:24:202 //1
04:24:202 //2
04:24:218 //3
04:24:234 //4
04:24:249 //5
04:24:249 //6
04:24:265 //7
04:24:280 //8
04:24:280 //9
04:24:296 //10!!! :D
04:24:312

As you can see, it takes a while before the new timer-variable kicks in. Also it is irregular as bollocks... I only tried it in a script with 100ms once, and as you can see, on my computer that went pretty well. I really disrecommend every 10ms.
Really lmao here btw :D
« Last Edit: April 25, 2008, 02:22:08 pm by JFK »
Come join: EliteCTF
Listen to: My Music

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: Help with timer...
« Reply #8 on: April 25, 2008, 03:40:17 pm »
Okay thx for everyone... im succeeded in what i did ( a new berserker mod XD )
Also Known As REIMA


Lol Happles (happy apples)