Create periodic or one shot timers with gameticks.
Posted: 14 Feb 2021, 10:16
Yesterday i have search after a Method to to actively measure the game time for scripts and to create gametime. The Thing is, that Mad Doc have use for his Scripts a special Int, called "cTimerInt" and "cPeriodicInt" which set a single Timer or evaluate for set a trigger periodicaly secunds. Without Description i dident have work with this special Ints. There dident have work in my .ies script, but i have found thanks to Mona a other Method, which is very exactly and work wounderful. Thanks to this you can chanche in a script the perdiodically evaluation or set a simple timer for a script.
Here is the Script:
Empire Earth 2 measures the time from a second in ticks. EE2 has 30 ticks per second, so function is called 30 times during 1. So we only must calculate the time we need for a timer in tickets. And write a simple to function which a game tick deducts or add to a int and set a bool true, if the timer ends.
The advantage of this method is, that she is very exactly and that you can start in the background from the game a timer without complicated calculation of the time. So far that was a bit too bulky for me with the previous script functions. I hope, it help you.
Here is the Script:
Code: Select all
////////////////////////////////////////////////////////////
// INITIALIZATION
////////////////////////////////////////////////////////////
EveryMinute = 18.00;
EveryThirtySeconds = 9.00;
EveryTenSeconds = 3.00;
EveryFiveSeconds = 1.50;
EveryThreeSeconds = 0.90;
EveryTwoSeconds = 0.60;
EverySecond = 0.30;
////////////////////////////////////////////////////////////
// Get the Gametime in Ticks for Triggers and Effects
////////////////////////////////////////////////////////////
RULE CountPeriodicInt
if (true)
then actionPeriodicInt
END_RULE
ACTION actionPeriodicInt
SCRIPT WORLD
EveryMinute = EveryMinute - 0.01;
EveryThirtySeconds = EveryThirtySeconds - 0.01;
EveryTenSeconds = EveryTenSeconds - 0.01;
EveryFiveSeconds = EveryFiveSeconds - 0.01;
EveryThreeSeconds = EveryThreeSeconds - 0.01;
EveryTwoSeconds = EveryTwoSeconds - 0.01;
EverySecond = EverySecond - 0.01;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EveryMinute
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt1
if (EveryMinute <= 0)
then actionSemaphorePeriodicInt1
END_RULE
ACTION actionSemaphorePeriodicInt1
SCRIPT WORLD
EveryMinute = 18.00;
bEveryMinute = true;
DoDelay(1);
STEP
bEveryMinute = false;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EveryThirtySeconds
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt2
if (EveryThirtySeconds <= 0)
then actionSemaphorePeriodicInt2
END_RULE
ACTION actionSemaphorePeriodicInt2
SCRIPT WORLD
EveryThirtySeconds = 9.00;
bEveryThirtySeconds = true;
DoDelay(1);
STEP
bEveryThirtySeconds = false;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EveryTenSeconds
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt3
if (EveryTenSeconds <= 0)
then actionSemaphorePeriodicInt3
END_RULE
ACTION actionSemaphorePeriodicInt3
SCRIPT WORLD
EveryTenSeconds = 3.00;
bEveryTenSeconds = true;
DoDelay(1);
STEP
bEveryTenSeconds = false;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EveryFiveSeconds
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt4
if (EveryFiveSeconds <= 0)
then actionSemaphorePeriodicInt4
END_RULE
ACTION actionSemaphorePeriodicInt4
SCRIPT WORLD
EveryFiveSeconds = 1.50;
bEveryFiveSeconds = true;
DoDelay(1);
STEP
bEveryFiveSeconds = false;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EveryThreeSeconds
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt5
if (EveryThreeSeconds <= 0)
then actionSemaphorePeriodicInt5
END_RULE
ACTION actionSemaphorePeriodicInt5
SCRIPT WORLD
EveryThreeSeconds = 0.90;
bEveryThreeSeconds = true;
DoDelay(1);
STEP
bEveryThreeSeconds = false;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EveryTwoSeconds
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt6
if (EveryTwoSeconds <= 0)
then actionSemaphorePeriodicInt6
END_RULE
ACTION actionSemaphorePeriodicInt6
SCRIPT WORLD
EveryTwoSeconds = 0.60;
bEveryTwoSeconds = true;
DoDelay(1);
STEP
bEveryTwoSeconds = false;
END_SCRIPT
END_ACTION
////////////////////////////////////////////////////////////
// EverySecond
////////////////////////////////////////////////////////////
RULE SemaphorePeriodicInt7
if (EverySecond <= 0)
then actionSemaphorePeriodicInt7
END_RULE
ACTION actionSemaphorePeriodicInt7
SCRIPT WORLD
EverySecond = 0.30;
bEverySecond = true;
DoDelay(1);
STEP
bEverySecond = false;
END_SCRIPT
END_ACTION
The advantage of this method is, that she is very exactly and that you can start in the background from the game a timer without complicated calculation of the time. So far that was a bit too bulky for me with the previous script functions. I hope, it help you.