[Solved] How can I obatin a unit's Sight Range?

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
You can write sight-range at compile time, and access the same constant in runtime. See Cokemonkey11 / dragons / source / wurst / systems / Units.wurst — Bitbucket
I don't understand, what it does ?

Unit-types are integers in JASS. You can store the unit-type into an integer using Custom script and use that as the parent key for the hashtable.
I'm using this after creating the hashtable:
  • storing values
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- PEASANT --------
      • Set UnitType = Peasant
      • Custom script: set udg_TempInteger = udg_UnitType
      • Hashtable - Save 800 as 0 of TempInteger in STESYS_Hash
      • -------- PEASANT --------
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • Set STESYS_TempUnit1 = (Triggering unit)
      • Set UnitType = (Unit-type of STESYS_TempUnit1)
      • Custom script: set udg_TempInteger = udg_UnitType
      • Set TempInteger2 = (Load 0 of TempInteger in STESYS_Hash)
      • Game - Display to Player Group - Player 1 (Red) the text: (String(TempInteger2))
 
Last edited:
Level 11
Joined
Oct 9, 2015
Messages
721
the storing of the values and the creating of the hashtable are both triggered by map initialization but in separated triggers, the storing trigger is over the hashtable creating trigger could be the issue ? I'll test it when I get home!
 
Level 11
Joined
Oct 9, 2015
Messages
721
Ok, I'll be home in about one hour I'll try it out and come back with the results. Thanks KILLCIDE, you've been very helpful as always!

EDIT: Ok, so now I'll post the functions structered as in my map:

Trig1
  • storing values
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set STESYS_Hash = (Last created hashtable)
      • -------- PEASANT --------
      • Set UnitType = Peasant
      • Custom script: set udg_TempInteger = udg_UnitType
      • Hashtable - Save 800 as 0 of TempInteger in STESYS_Hash
      • -------- PEASANT --------
Trig2
  • actions
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
    • Actions
      • Set STESYS_TempUnit1 = (Triggering unit)
      • Set UnitType = (Unit-type of STESYS_TempUnit1)
      • Custom script: set udg_TempInteger = udg_UnitType
      • Set STSYS_TempInteger = (Load 0 of TempInteger in STESYS_Hash)
      • Game - Display to Player Group - Player 1 (Red) the text: (String(STESYS_TempInteger))
All that is displayed when the unit is ordered is "0"
 
Last edited:
I went ahead and created this in a test map to make sure my intuition is right. It works perfectly fine for me. Are you sure that the triggering unit is in fact the same unit type? Print out the value of TempInteger after you store the unit type into it in both the map init and actions trigger.

  • MapInit
    • Eventsp
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hash = (Last created hashtable)
      • Set UnitType = Peasant
      • Custom script: set udg_Integer = udg_UnitType
      • Hashtable - Save 500 as 0 of Integer in Hash
  • PointOrder
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
    • Actions
      • Set UnitType = (Unit-type of (Triggering unit))
      • Custom script: set udg_Integer = udg_UnitType
      • Game - Display to (All players) the text: (String((Load 0 of Integer from Hash)))
The above prints out 500 for me.
 
Level 11
Joined
Oct 9, 2015
Messages
721
My integer variable somehow was set as a unit group and that messed everything up! The trigger you posted showed me what I was doing wrong, plus I wasn't loading integer value in the hastable, I was loading key handles... I tested it and it returned 800 as it should! Thanks a lot!
 
Level 11
Joined
Oct 9, 2015
Messages
721
Yeah, maybe I could launch a spell containing all that data pre-stored so people won't have to go throught setting all unit's attack range, sight radius etc manualy. I'm still trying to figure out a method to spare time... I saw many units have the same sight range (800/600 for workers, 1400/800 for melee ground units, 1800/800 for heroes). Any suggestions on how to approach this ?
 
Status
Not open for further replies.
Top