Author Topic: Executing sth in every X minutes, help!  (Read 672 times)

0 Members and 1 Guest are viewing this topic.

Offline keshramisami

  • Major(1)
  • Posts: 2
  • LoL
Executing sth in every X minutes, help!
« on: March 26, 2009, 04:53:36 pm »
Hi! I wrote script, that starts "party" on cmd, and after 60 seconds party ends.. I want to do it executes automaticly every X mintues, but really don't know how (tried AppOnIdle event from enesce help but I can''t make this work). Here's the script executing "party" on cmd (used iDante Timer from "How to write soldat script"): http://nopaste.com/p/aVYG7ow8o
Could somebody help me :o? Ty

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Executing sth in every X minutes, help!
« Reply #1 on: March 26, 2009, 05:28:51 pm »
lol, sure

replace the line:
Code: [Select]
if Timer > 0 then
with:
Code: [Select]
if (Timer > 0) and (Timer < 60) then

and change this:
Code: [Select]
Timer := -1;
to:
Code: [Select]
Timer := X;
and replace X the number of SECONDS you want it to execute automaticly.

type /party once to start the fun
and /recompile to stop it :p

oh and i would remove the line with WriteFile in it. I really don't see the purpose of it and it will execute every second..
Come join: EliteCTF
Listen to: My Music

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Executing sth in every X minutes, help!
« Reply #2 on: March 26, 2009, 06:12:29 pm »
Another method to do this would be:
Code: [Select]
var
  CallAt: cardinal;

procedure OnTimeEnd();
begin
  // this gets called every 5 minutes
end;

procedure ActivateServer();
begin
  CallAt := GetTickCount() + 60; // one second latter
end;

procedure AppOnIdle(Ticks: cardinal);
begin
  if ((CallAt > 0) and (Ticks >= CallAt)) then begin
    CallAt := Ticks + 18000; // 60 ticks per second * 60 seconds per minute * 5 minutes = 18000 ticks
    OnTimeEnd();
  end;
end;
But this is probably more confusing, but it doesn't have to set a variable every second. The other way works just as well.

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: Executing sth in every X minutes, help!
« Reply #3 on: March 27, 2009, 02:03:05 am »
Bah.
Code: [Select]
procedure AppOnIdle(Ticks: cardinal);
begin
  if (Ticks mod (3600 * 5) = 0) then begin
    //Code here to be executed every 5 minutes
  end;
end;

You all do it so very very wrong.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Executing sth in every X minutes, help!
« Reply #4 on: March 27, 2009, 03:42:02 am »
Bah.
Code: [Select]
procedure AppOnIdle(Ticks: cardinal);
begin
  if (Ticks mod (3600 * 5) = 0) then begin
    //Code here to be executed every 5 minutes
  end;
end;

You all do it so very very wrong.
Yeah that works too.
On another note, why does AppOnIdle use ticks instead of just the # of seconds?

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: Executing sth in every X minutes, help!
« Reply #5 on: March 27, 2009, 03:48:47 am »
Because that doesn't allow room for the function to ever be called more than once per second.

Offline keshramisami

  • Major(1)
  • Posts: 2
  • LoL
Re: Executing sth in every X minutes, help!
« Reply #6 on: March 27, 2009, 07:02:18 am »
I tried all of those... Nothing works, only one thing that have changed is player dies and seeing "party ends blalbla" on join team... I'm propably doing it wrong, because I'm newbie, so please gimme ready piece of code :/ Ty.. Oh, and btw. I don't wanna to make another topic so Ill ask here: I need sth to clear all dropped weapons from map when party ends... Ty ^^