• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Making a custom cooldown

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
I have a boat map with enemy ships. These ships fire ballistas. I want them to only be able to fire once every 8 seconds.

What I tried: I made an array of timers called OrdersTimer. I start the timers when the unit casts an ability, and then detect if the remaining time on the timer is less than 1, enabling it to fire again. A section of the trigger is given below:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Abs(math_1)) Less than 20.00
      • (Distance between tempPoint and tempPoint2) Less than 4000.00
      • (Remaining time for OrdersTimer[tempInteger]) Less than 1.00
    • Then - Actions
      • -------- fire ballista --------
      • Countdown Timer - Start OrdersTimer[tempInteger] as a One-shot timer that will expire in 8.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between tempPoint and tempPoint2) Greater than or equal to 3150.00
        • Then - Actions
          • Set BallistaFallSpeedTemp = -15.00
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between tempPoint and tempPoint2) Greater than or equal to 2550.00
            • Then - Actions
              • Set BallistaFallSpeedTemp = -12.00
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between tempPoint and tempPoint2) Greater than or equal to 1975.00
                • Then - Actions
                  • Set BallistaFallSpeedTemp = -9.00
                • Else - Actions
                  • Set BallistaFallSpeedTemp = -6.00
      • Sound - Play BallistaAttackEffort1 <gen> at 100.00% volume, attached to (Triggering unit)
      • Trigger - Run AI Ballista <gen> (ignoring conditions)
    • Else - Actions

THE PROBLEM: the timer doesn't appear to work. The trigger fires every time, even right after the timer is started.

Is there some problem with arrays of Timers? Does the condition "Remaining time for OrdersTimer" not refer to how much time is left on a timer?
 
Level 26
Joined
Aug 18, 2009
Messages
4,099
Timers are objects that need to be created in order to use them. If you declare a timer variable in GUI, you can see the preset value "New Timer", which creates and assigns a new timer object to the variable.

Now you try to make an array but it won't automatically create tons of objects for each index. The size property in the variable editor determines up to which index the array is initialized with the preset value, so only index 1 to size get a functional timer object.
 
Level 14
Joined
Aug 30, 2004
Messages
909
Thank you both. I went to my variables and set the Timer array to size 100 and it appears to work now. I had just left it on 1 with my other arrays.

I hadn't known about the unitgroup array problem either. Good to know.

+rep to you both, and have a good day.
 
Status
Not open for further replies.
Top