Referencing Units From Trigger Events

Jinxx

New Member
Reaction score
4
Okay, maybe not the most clear thread title, so let me explain. Since the "unit comes within range" event only allows checks for pre-placed units, I used one trigger to add a hero (let's call the hero 'John') that learns a particular ability as an event which fires when other units come within range of said hero.

Now, the problem I'm having is referencing John. Within the trigger, "triggering unit" and "entering unit" returns the unit which entered within range of John, but none of the event responses can be used to reference John himself. Also, I can't store John into a global since I need this MUI (there will probably be multiple Johns running around the map).

So how the hell do I save John's handle? I need to know who John is so I can make some checks regarding the level of his abilities, and to check whether or not the unit entering within range of John is his enemy.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, I am not completely sure about this, but I think there is a native in Jass called "GetDetectedUnit()" which will give you the unit you want ;)

Just do a quick custom script and set a global GUI variable to [ljass]GetDetectedUnit()[/ljass] and then you can use that variable ;)
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
if what Komaqtion said doesnt work you can still use a workaround using a damage detection system and permanent immolation with 0.01 damage every 0.1 seconds.
 

Moridin

Snow Leopard
Reaction score
144
I would suggest using a hashtable or a simple 2D array to store lots of global variables. That would solve your problem of MUI while at the same time allow you to easily edit it later on.

Komaqtion's solution would probably work just as well. It's just a personal bias against using something that I won't know how to change.
 

Azylaminaz

Vox Populi
Reaction score
91
Pretty sure GetDetectedUnit() is a response to EVENT_UNIT_DETECTED.

You can use Trigger - Add New Event to add the event for non-preplaced units.


The only way I know how to do it with a single trigger would be a reverse solution by finding units in the range and matching it to the units in the event.


An absolute solution can be done with a little JASS. Instead of adding the events at the beginning like normal, add them via actions.
Trigger:
  • Actions
    • Custom script: set udg_unitApproachTrigger[0] = CreateTrigger()
    • Custom script: set udg_unitApproachUnit[0] = <your unit>
    • Custom script: call TriggerRegisterUnitInRange(unitApproachTrigger[0], udg_unitApproachUnit[0], 256., Trig_NAME_Conditions)
    • Custom script: call TriggerAddAction(unitApproachTrigger[0], function Trig_NAME_Actions)
This requires the global array variables unitApproachTrigger and unitApproachUnit (note caps do matter). In the custom script you must change <your unit> to the unit you want. Change NAME to the trigger that does the actions. If the triggering doing the actions is called Alpha Charlie, the function call would be Trig_Alpha_Charlie_Actions (spaces become underscores).
Note the [0] will increase by 1 for every added unit.

Then to get the approached unit, you would just run a loop checking if the triggers match....
Trigger:
  • For each (Integer A) from 0 to 0, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (This trigger) Equal to unitApproachTrigger[0]
        • Then - Actions
          • Unit - Kill unitApproachUnit[0]
        • Else - Actions

Note the loop only goes 0 to 0 because I've only declared 0 int he array, if you add units, this should match the maximum value.
Killed the unit in this example.



A tad complicated, especially when mixing in JASS and GUI. ^^
If you still don't understand and you want to do it this method, I can make a basic maze-death trigger (heroes die when other units approach) utilizing this method.
 

Jinxx

New Member
Reaction score
4
Just do a quick custom script and set a global GUI variable to GetDetectedUnit() and then you can use that variable
Tried it, it doesn't work... :(

Well, for the storing part, I believe that hashtable will do the job nicely.
Sure, but once I store the unit into the hash, how would I reference it? How can I know which of the units within the hash that were stored were the ones that caused a trigger to fire when another unit came within range of them?

If you still don't understand and you want to do it this method, I can make a basic maze-death trigger (heroes die when other units approach) utilizing this method.
Honestly, your workaround lost me there... It'd be great if you could set up this small maze map; it's much easier understanding things when you see them in action than when people try to describe them. :thup:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top