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

unit within range

Status
Not open for further replies.

007

007

Level 6
Joined
May 3, 2009
Messages
175
there is the trigger "a unit comes within range of ..." but for the ... i can only use real units that are in the map already but no variables although there is a button "edit variables". so i thought it might be possible although a normal unit variable does not work. is there any way to use this trigger with a variable?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Yes, link 2 triggers by using Event from another trigger
Your 2nd trigger should look like this:
  • Second Trigger
    • Events
    • Conditions
    • Actions
      • Unit - Kill (Triggering unit)
The trigger will kill (Triggering unit) which is NOT that caster, (Triggering unit) in this case refers to "A unit comes within..", yeah, that unit is killed
Also, you can add conditions too
 

007

007

Level 6
Joined
May 3, 2009
Messages
175
if i do the action "pick every unit of type X" and then "add event "a unit comes within range of 100 of (picked unit)" to trigger Y" does it work for every unit that comes within range of any unit of type X?

and then, in trigger Y how can i refer to X (the picked unit of the first trigger)? if i use picked unit in the trigger with the added event (Y) can i then also usit (picked unit) for unit X?

and to refer to the unit coming in range... (triggering unit) does not work.

am i doing it correct that trigger Y originally does not have an event?
 
If you are interested in a hell of a hack which might lag the game if you got too many units I can give you this

  • InRangeEvent
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- If there is no triggering unit it is the first time this trigger runs --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering unit) Equal to No unit
        • Then - Actions
          • -------- Range at which the new triggers are supposed to fire off --------
          • Set r = 300.00
          • -------- Create and save a hashtable to store stuff for later --------
          • Hashtable - Create a hashtable
          • Set InRangeHashtable = (Last created hashtable)
          • -------- Pick all units in playable map area --------
          • Custom script: call GroupEnumUnitsInRect(udg_g, bj_mapInitialPlayableArea, null)
          • -------- Start a loop --------
          • Custom script: loop
          • -------- Get first unit from group --------
          • Custom script: set udg_u = FirstOfGroup(udg_g)
          • -------- Remove unit from group --------
          • Custom script: call GroupRemoveUnit(udg_g, udg_u)
          • -------- If there is no first unit left exit group because its empty now --------
          • Custom script: exitwhen udg_u == null
          • -------- Create a new trigger --------
          • Custom script: set udg_t = CreateTrigger()
          • -------- Get handle id of trigger --------
          • Custom script: set udg_id = GetHandleId(udg_t)
          • -------- Register event for unit --------
          • Custom script: call TriggerRegisterUnitInRange(udg_t, udg_u, udg_r, null)
          • -------- Add actions (which are the actions of this trigger) --------
          • Custom script: call TriggerAddAction(udg_t, function Trig_InRangeEvent_Actions)
          • -------- Save unit to trigger --------
          • Hashtable - Save Handle Ofu as 0 of id in InRangeHashtable
          • -------- Endloop --------
          • Custom script: endloop
        • Else - Actions
          • -------- Load id of trigger created for that unit --------
          • Custom script: set udg_id = GetHandleId(GetTriggeringTrigger())
          • -------- Load unit of trigger --------
          • Set u = (Load 0 of id in InRangeHashtable)
          • -------- Display name of triggering unit and loaded unit --------
          • Game - Display to (All players) for 0.00 seconds the text: ((Name of u) + ( comes within range of + (Name of (Triggering unit))))
else I'd recommend to check the distance between your units periodically (if you have to test against all units in your map you might be interested in something called "sweep line algorithm")

unfortunately it seems like a FristOfGroup loop is the only way to preserve the order after GUI is compiled to JASS
else I would have used a ForGroup loop
abusing autogenerated triggers is fun ^_^

btw the name of the trigger is important
if you change it you will have to change the function name in the custom script to Trig_NewTriggerName_Actions
 

Attachments

  • InRange.w3x
    13.9 KB · Views: 116
Status
Not open for further replies.
Top