Jump to content


Photo

How to add a timer?


  • Please log in to reply
7 replies to this topic

#1 Jack

Jack
  • Members
  • 24 posts

Posted 20 October 2009 - 02:35 AM

Sorry, I forgot.
I already have the text for it (such as 'reinforcements in:') But I don't know how to add the acutal TIMER part of it.

#2 Glaeken

Glaeken

    Almost identical to something very similar

  • Project Team
  • 174 posts
  • Location:Ohio, USA
  • Projects:The Peloponnesian Wars mod - map team
  •  "...wordy little bastard..." - sometimes.

Posted 20 October 2009 - 04:12 AM

Jack,

I've had success by using the "timer" provided under the "Scripting" category.

It provides the user the ability to:
  • Frame countdown timer - set random ( = set timer 'y' to expire between 'x' and 'z' frames)
  • Frame countdown timer -set ( = add 'x' seconds to 'y' timer)
  • Seconds countdown timer - add ( = set timer 'y' to expire in 'x' frames)
  • Seconds countdown timer - set random ( = set 'y' timer to expire between 'x' and 'z' seconds)
  • Seconds countdown timer - set (= 'y' timer to expire in 'x' seconds)
  • Seconds countdown timer - subtract ( = subtract 'x' seconds from 'y' timer)
  • Timer - restart stopped ( = restart a stopped named timer)
  • Timer - stop. ( = Stop a named timer)

The 'x', 'y', and 'z' are parameters you provide.

You'll notice there are two types of timers shown: Frame and Seconds.
Frame timers deal with the number of frames happening and the Seconds timers deal with the number of seconds transpiring.

According to the World Builder manual there are roughly 30 frames to a second in time. I have done no calculations or studies to refute or confirm this and am just stating what the manual provides.

Another thing to keep in mind is how the game engine determines various occurrences and in reference to what. Meaning if the user is wanting to track when a unit is killed one must keep in mind that the game engine determines and references this to occur during a particular "FRAME". It won't remember it in memory. So, your condition script must evaluate the script "Every Frame".
Understanding this then one can utilize the "Timer" script action more effectively based on the user's needs.

Some things are kept in memory by the game and other things are not. I wish I could provide you with a list of each of these but I can't.
I do know that when a script action sets a "Flag" the flag is retained in memory and can be referenced/called on at any time after it has been set.
I mention this because "Flags" and "Timers" can easily be utilized together.

Good luck, let us know how it works out for you.


Below is the relevant section from the manual -
World Builder Manual

Scripting section - Timers

TIMERS
Countdown timers monitor the passage of time in the game. Timers come in two varieties: Seconds timers and Frame timers. Both timers assume that in the game one second equals 30 frames. On faster machines, the game can perform at this rate. On a machine producing 18 frames per second, the rate for timers is still assumed to be 30 frames per second. So, on a slower machine, while 30 frames may last nearly two seconds in real time, they are treated as a single second in game time.
To create a Seconds timer, use the action [Scripting] Seconds countdown timer - set. Enter a name for the timer and its initial value in seconds. The timer begins as soon as the script is executed.
To create a Frame timer, use the action [Scripting] Frame countdown timer - set. Enter a name for the timer and its initial value in frames. The timer begins to count down frames as soon as the script is executed.
The [Scripting] Frame countdown timer - random action lets you set up frame timers of random duration, which is useful for creating the appearance of random behavior in your maps.
Avoid using timers in multiplayer missions.
Timers always count down from the start time you set. A timer can be used as a counter, too. You can perform all of the operations on a timer that you can perform on a counter.

Useful Conditions
When scripting timers, there are some useful conditions that you can test to determine if action should be taken:
Timer Expired: You can fire actions when a timer reaches 0 seconds or frames. The Timer Expired condition is useful for scripted cinematics or for delaying action. For pacing purposes, you may want to use timers to delay AI counter-attacks.
Counter Compared to Value: Use this condition to compare a named timer to an entered value. Note that the default setting is “less than zero.” If you don’t set a positive value for the counter, the condition never fires.


Edited by Glaeken, 20 October 2009 - 05:27 AM.


#3 m@tt

m@tt

    #######

  • Project Team
  • 4,056 posts
  • Location:England
  • Projects:The Dwarf Holds
  •  T3A Chamber Member

Posted 20 October 2009 - 08:54 AM

One thing with timers, which is a bit odd but it's the way WB works:

First create the timer.
Then close the scripts menu (press OK not Cancel or X!)
Reopen scripts menu.
Make your IF timer_X has expired script

The reason for this is that without reopening the scripts, it will say Timer_X does not exist. You can still use it, but it can confuse users (and by reopening you can make sure it's definitely spelt right).
Posted Image

#4 Jack

Jack
  • Members
  • 24 posts

Posted 20 October 2009 - 08:43 PM

So what exactly would I do to show a timer after my premade title thing.
How would I make it say:
(Title): (X) amount of time left

#5 Puzzler33

Puzzler33
  • Members
  • 226 posts

Posted 20 October 2009 - 10:29 PM

You need 3 things:
1) The timer being triggered.
2) The text entered into your map.str file.
3) The timer's display being triggered.

It sounds to me like you've done 1 & 2.
3 is simple:
Create/find your timer's trigger, underneath where you have told the script to create the timer add a new command. Find under Interface>Counters and Timers>Display a specific timer (something like that) = Display 'Timer01' with display name 'SCRIPT:TimerText', where Timer01 is the name of the timer and SCRIPT:TimerText is what you called the string of text in your .str file. You could just enter your text there (without the .str file), but that would mean it would be displayed as: MISSING:'(Title)': (X)
Posted Image

#6 Jordan18124

Jordan18124
  • Members
  • 48 posts
  • Location:UK

Posted 24 January 2010 - 05:08 PM

First create the timer.
Then close the scripts menu (press OK not Cancel or X!)
Reopen scripts menu.
Make your IF timer_X has expired script


or you could just click apply, it works either way, but just clicking apply is quicker than closing it and then reopening it
Posted Image

#7 Puzzler33

Puzzler33
  • Members
  • 226 posts

Posted 24 January 2010 - 07:11 PM

Or just make the script and ignore the Timer '_____' does not exist warning because you know it is ill-informed. No point spend the whole time validating or reopening the scripts.
Posted Image

#8 JUS_SAURON

JUS_SAURON

    El Shaddai

  • Members
  • 1,581 posts
  • Location:Trinidad
  • Projects: BFME2 MOD - Power Of The Ring
  •   INI Coder

Posted 25 January 2010 - 01:53 AM

One way to figure out how TIMERS work is by opening EA CAMPAIGN maps that use timer counts..
I used Hems Deep BFME1 ..also Black Gate and I believe the Dol Guldor map for BFME2 has a timer script

CODE


First script that call on the timed event
Enable Script 'START_TREEBEARD'.
Enable Script 'DISPLAY_TREEBEARD'.
-------------------------------------------
<<<starts the Timer>>>
*** IF ***
True.
*** THEN ***
Set timer 'TREE_ENTRY' to expire in 300.00 seconds.
------------------------
<<<<Shows the timer
*** IF ***
True.
*** THEN ***
Show 'TREE_ENTRY' with text Localized String: 'SCRIPT:TEST_TREEBEARD'
-------------------------
<<<script that does stuff when the timer is up
*** IF ***
Timer 'TREE_ENTRY' has expired.
*** THEN ***
Hide 'TREE_ENTRY'
A radar event occurs at (3895.00,1036.00,0.00) of type Information
Enable Script 'PlyrCivilian/TREEBEARD_SPAWN'.
Play Sound 'TreebeardVoiceSaluteMS' at Waypoint 'ENT'.
Player 'Player_4' fires Special power 'SpellBookElvenWood' at Waypoint 'ENT'.
Player 'Player_4' fires Special power 'SpellBookEntAllies' at Waypoint 'ENT2'.
Move camera to Camera 'ENT' in 5.00 seconds, camera shutter 5.00 seconds, ease-in 5.00 seconds, ease-out 5.00 seconds.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users