• 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.

help with ability that generates gold while being channeled

Level 4
Joined
Jul 25, 2024
Messages
13
I want an ability based on something like aerial shackles to generate gold every second it is being cast on a valid target can someone please help with the triggers because im having trouble and it seems simple yet i just cant figure it out (its for a fishing net ability on neutral passive fish units)
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,917
I want an ability based on something like aerial shackles to generate gold every second it is being cast on a valid target can someone please help with the triggers because im having trouble and it seems simple yet i just cant figure it out (its for a fishing net ability on neutral passive fish units)
Here is the most basic way to do it:
  • Cast Start Trigger
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
      • (Ability being cast) Equal to MyAbility
    • Actions
      • Unit Group - Add (Triggering unit) to MyUnitGroupVariable
      • Trigger - Turn on Periodic Trigger
  • Cast Stop Trigger
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • (Ability being cast) Equal to MyAbility
    • Actions
      • Unit Group - Remove (Triggering unit) from MyUnitGroupVariable
      • If all Conditions are True then do (Actions)
        • If - Conditions
          • (Number of units in MyUnitGroupVariable) Equal to 0
        • Then - Actions
          • Trigger - Turn off Periodic Trigger
        • Else - Actions
  • Periodic Trigger
    • Events
      • Time - Every 1.00 seconds of game-time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MyUnitGroupVariable and do (Actions)
        • Loop - Actions
          • Player - Add 100 Gold to (Owner of (Picked unit))
Variables:
MyUnitGroupVariable = Unit Group

Note that this lacks timed precision because the Periodic interval is shared between all casting units. In other words, Gold is given to everyone at the same time, even if say Player 1 casts the spell 0.25 seconds before Player 2. However, this only applies to the first tick of gold rewarded to a unit, it'll sort itself out after that and work as expected.

To get around this imprecision you can create and use a Timer variable for each unit. This can be rather complicated to do in GUI without a system, which even then is still somewhat complicated.

Alternatively, you can reduce the imprecision by using a smaller Periodic interval and reward less gold. IE: 25 gold every 0.25 seconds instead of 100 every 1 second.

Or if you want the interval to remain 1 second then you can use a technique like Unit Indexing + a Real array variable + a smaller interval and manage the elapsed time yourself on a per unit basis. IE: Every 0.10 seconds -> Pick every unit -> Increase unit's Real variable by 0.10 -> if Real >= 1.00 then Set Real to 0.00 and Reward 100 gold.
 
Last edited:
Top