• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Custom Unit Instance Variables

Status
Not open for further replies.
Level 1
Joined
Dec 2, 2018
Messages
1
I am working on a MOBA type map. I want to be able figure out which lane a unit belongs to.

One solution I have considered is using the unit custom value to store the lane number. After a unit is created I would set the custom unit value of last created unit to its lane number, then I would check this number whenever I needed to know the lane.

Another solution I have thought of is a set of custom units for each lane that are identical in stats. If I wanted to spawn footmen, I would have a separate custom footman for each lane. (Footman1, Footman2, ...). This is definitely too much work and unnecessary.

I know this is something that can be accomplished using hashtables but most tutorials on hashtables talk about multi unit instantiable spells. Maybe a less complex tool would be better suited for something simple like my problem. Is this something hashtables were meant to deal with?

What is the most simple, efficient way to give a unit a lane number when it is created?
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Although the custom value trick you're thinking about would work, I would advise against it. A lot of the spells & systems in the Spell section use a unit indexer as a dependency, so you'd have a lot of unwanted behavior if you have more than one "system" modifying custom values in one map.

The best option is to use hashtables. Something like this would work:

  • Set TopLane = 1
  • Set MidLane = 2
  • Set BottomLane = 3
  • -------- --------
  • Set LaneIdentifier = 0
  • Set Unit = (Your unit)
  • Custom script: set udg_HandleId = GetHandleId(udg_Unit)
  • -------- --------
  • -------- if the unit is in top lane... --------
  • Hashtable - Save TopLane as LaneIdentifier of HandleId in (Your hashtable)
  • -------- if the unit is in mid lane... --------
  • Hashtable - Save MidLane as LaneIdentifier of HandleId in (Your hashtable)
  • -------- if the unit is in bottom lane... --------
  • Hashtable - Save BottomLane as LaneIdentifier of HandleId in (Your hashtable)
  • -------- --------
  • -------- finding out which lane the unit belongs to --------
  • Set TempInt = (Load LaneIdentifier of HandleId from (Your hashtable))
 
Status
Not open for further replies.
Top