• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How To Make Stacked Ability?

Status
Not open for further replies.
Level 3
Joined
Apr 5, 2016
Messages
21
i want to make an ability like everytime you use the ability it will add 1 "Holy Wrath", it can release it like (Total of holy wrath stacked x 50)
how do i make something like that?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
One can use a hash table to map the charges to the unit. Every time it is cast the charges are read, incremented and then written back. The release ability looks up the charges and resets charges to 0.

If the unit gets removed the mapping must also be removed to prevent a leak from occurring.
 
There a 2 practical options like DSG said use a hashtable and save on the units-Handle Id this wrath counter.


  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Create the hashtable, without it won't work --------
      • Hashtable - Create a hashtable
      • Set Hash = (Last created hashtable)
  • Powerup
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Power UP
    • Actions
      • -------- Get HandleId of CastingUnit --------
      • Set UnitId = (Key (Triggering unit))
      • -------- Load Current Power, 11 is a random choosen number, other spells should not use it. --------
      • Set Power = (Load 11 of UnitId from Hash)
      • Set Power = (Power + 50.00)
      • -------- Save New Power --------
      • Hashtable - Save Power as 11 of UnitId in Hash
  • Unleash
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Unleash
    • Actions
      • -------- Load Current Power --------
      • Set UnitId = (Key (Triggering unit))
      • Set Power = (Load 11 of UnitId from Hash)
      • -------- 30 Base Damage --------
      • Set Power = (Power + 30.00)
      • Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing Power damage of attack type Spells and damage type Magic
      • -------- Save 0 as power uped. --------
      • Hashtable - Save 0.00 as 11 of UnitId in Hash
  • Killed
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in Hash


Other option is using an Unit Indexer and saving the Wraith counter on a variable with the index the Indexer gives you.
 
Level 21
Joined
Apr 8, 2017
Messages
1,530
This one too.

  • Stacking
    • Event
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Stack ability
    • Actions
      • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
  • Release
    • Event
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Unleash
    • Actions
      • Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (YouAmount x (Real((Custom value of (Triggering unit))))) damage of attack type Heroe and damage type Normal
      • Unit - Set the custom value of (Triggering unit) to 0
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
This one too.
Be aware, that this method does not work together with most unit indexers. If you have one of these unit indexers in your map, you can easily use it to achieve the same using an integer array.

So hastables are like "custom values" of units?.
A hashtable is like an array with two indexes. You can store value of any type (integer, real, unit, point,...) in a certain position (row, column) in the table.
The row and column are specified by integers.
There is a function to get the key of an object. This key is a unique integer for every object in the game. This key can then be used in the hashtable. With this key we can store data for a specific object (often times a unit).
For example to store an integer for a unit we can use:
  • Hashtable - Save 4 as (Key (Triggering unit)) of 0 in Table
This is very similar to setting custom value of the Triggering unit to 4. However with the hashtable you can store a basically unlimited number of variables (also non-integer variables) for a unit.
To store a unit as well, we can store it in a different position in the hashtable:
  • Hashtable - Save Handle Of(Target unit of ability being cast) as (Key (Triggering unit)) of 1 in Table
The key function can also be used for other objects, so you can store values for basically every object in the game (destructible, unit type, item, timer, region, player, unit group, point, ...)

For more information check out some of the tutorials on this site. For example:
Hashtables and MUI
A Complete Beginners Guide to Hashtables
 
Status
Not open for further replies.
Top