I'm attempting to use the event, Unit enters/leaves range of unit, but I can't find a way to reference the unit the unit with the range.
Event unit refers to the unit entering/leaving.
When the function is created (the actions portion of the trigger) is there anyway to pass the variable of the unit with range to it?
Or pass any sort of variable that can lead back to the source unit?
Any help is much appreciated!
I guess it's assumed you know the source unit because the event itself only allows for direct unit reference.
Otherwise you could try to pick all units around triggering unit and check is distance between triggering and picked == your trigger distance. This obviously could be inaccurate in rare scenarios.
Funny, I ran into that same problem just yesterday. The reference unit was stationary (a structure) in my case, so I just ended up using a "Unit Enters Region" event instead. I made a record that included a source unit and a circular region around it with the desired radius, so when the event fired I would reference the source unit associated with the triggering region. It might not apply in your case, but just thought I'd mention a possible workaround.
I see. Well it looks like that's a dead end.
Do you know of any clever and effective way to somehow pass the unit as a variable to the trigger?
Basically when I add a unit to a unit group, they're added to the event "Unit within range" so if anything gets close to them, an action will occur.
I have tons of units going through this at random points throughout the game. It's really a collision detection between particles.
What exactly do u want to do? I'm confuzzled... So u want this unit to check around it at a certain distance correct? What do you want to happen when this "collision" is detected?
I see. Well it looks like that's a dead end.
Do you know of any clever and effective way to somehow pass the unit as a variable to the trigger?
Basically when I add a unit to a unit group, they're added to the event "Unit within range" so if anything gets close to them, an action will occur.
I have tons of units going through this at random points throughout the game. It's really a collision detection between particles.
You can look into dynamically adding events to triggers using the "TriggerAddEvent..." native functions. A good tutorial on the subject can be found here: http://starcraft-2-galaxy-editor-tutorials.thehelper.net/tutorials.php?view=155774 (make sure you check the "Use Reference" box for variable types like unitref, which the author did not do in his example)
This allows you to make and use some pretty useful functions that are not normally available in the GUI. In this case you'll be looking into creating a custom action that will add the "Unit within range of Unit" event to a trigger with specific unit(s) defined at runtime (instead of in the editor). You'd still have to specify a single unit for the second parameter in that event, so you'd have to ditch the idea of using a Unit Group to do it, but at least you could reference the unit some other way (as simple variable or event response) at the time of adding the event.
As a disclaimer, just know that I haven't been able to find very much information about adding events to triggers at runtime. I've been using it is many different ways without any trouble, but I'm sure it has its limits. I'd say give it a shot and see what happens.
Ah yes, this is actually what I've been trying to do in galaxy.
The unit referenced when adding the event to the trigger is the one that has the range around it, but there's no way to link anything more from that trigger to that unit. Unless the variable for that unit is automatically carried over?
Like,
TriggerAddEventUnitRange(checkParticleCollision, null, u, GCV(u, 6), true);
'u' being the unit with the range, checkParticleCollision is the name, GCV(u,6) is the range.
Maybe u carries over and can be referenced? I doubt it though, there's no parameter for it.
I have a few ideas on ways to do this,
Perhaps there's a way to add more parameters to this so I can add in a second variable?
Or the range could actually be a number relating to an global array of units? (unitgroup) but this would get rid of the idea of using a range:(
Or could a data table be of use here?
Possibly when the event is added with the unit u, u and the trigger can be saved in a data table which relates the two?
By finding the position on the data table of the trigger, then the unit u can be found?
I've never used data tables or hash tables in maps sadly
Edit: Sorry Oparcus didn't see your post at first...
Basically what's happening is a player casts an ability, a unit, u, is created. This unit u will have the event UnitWithinRange tagged with it. The problem is that once this function ends, there's no way to recall this unit U even when the event is triggered. It seems to dissapear and there's no way to reference it again.
After the event is called it should pass the eventunit and unit u to another function.
As you pointed out, there is no galaxy function that will return the reference unit of that event. Why? I think it's simply because Blizzard did not include it.
But I do think there's a way you could logically find the unit you're asking about. Here's how:
Add the event "Any unit enters range R of Unit Y" to a trigger and place Unit Y in Unit Group G.
When the event fires, have the trigger check find all units within distance R of the triggering unit that are members of Unit Group G. That should give you the desired unit(s).
There might be some other checks you'll have to make to take into consideration the possibility of the triggering unit being within range R of multiple members of Unit Group G at the same time (if the triggering unit was teleported or walked into range of more than 1 member of Unit Group G at the same time).
I've definitely thought about having a distance checker, but I think that it may accidentally grab the wrong unit under certain circumstances...
Nerfpl, do you know if attaching regions to units that are moved (trigger-wise) very quickly can be done without causing delay with many units?
If so, this may just be the answer!
you could attach new region to created unit, add simple unit enters region event and use 'Unit attached to trigerring region'
Wow, didn't know you could do that. Thanks for pointing that out!
Guess I need to spend some more time looking at native functions. BTW, is there an organized list of them anywhere? For some reason I have trouble finding text in the editor browser window.
there is easily missable search box when choosing function.
For functions with return, create local variable of given type, click it's value and search, all listed will return this type.
There's no list as it's fairly sorted already by categories
So I started working with your region idea, but I can't get it to properly find the unit that enters the region now.
Here's the portion of the code that has it:
voidMakeParticleCollidable(unitu){regionR=RegionCircle(UnitGetPosition(u),UnitGetCustomValue(u,6));UnitGroupAdd(ActiveParticles,u);UnitSetCustomValue(u,0,ParticleCount);checkParticleCollision=TriggerCreate("checkParticleCollisionFunc");TriggerAddEventUnitRegion(checkParticleCollision,null,R,true);}boolcheckParticleCollisionFunc(booltestConds,boolrunActions){unitu=RegionGetAttachUnit(EventUnitRegion());if(libNtve_gf_PlayerIsEnemy(UnitGetOwner(u),UnitGetOwner(EventUnit()),4)){Collide(u,EventUnit());PrintValue(StringToText("Collision"),5);//To print a value to see if this ran.UnitKill(u);//Just to make sure the right unit is being selected.UnitKill(EventUnit());//Just to make sure the right unit is being selected.}returntrue;}
After this, only the EventUnit() dies, which is the unit with the region attached?? It doesn't make sense.
U can also use the data editor, make a buff that has a periodic effect that searches your desired range, and when the search finds a unit, execute a trigger dummy on the particle.
In triggers u would then want to make a trigger with the event "player any player uses [whatever u called your triggering effect]".
With this event you can get the unit that the effect was casted on, and the unit that casted the triggering effect with "triggering effect unit(caster)" and "triggering effect unit(Target)". When you have these 2 units it should be a problem to do what u want to do :)
So I started working with your region idea, but I can't get it to properly find the unit that enters the region now.
Here's the portion of the code that has it:
Attach means attach. What you currently doing is just creating region at current position of unit.
Also add EventUnit() != RegionGetAttachUnit(EventUnitRegion()) to your trigger to prevent unit triggering itself initially
EventUnit() = unit entering/leaving
RegionGetAttachUnit(EventUnitRegion()) = unit to which region is attached
so initially first time this unit enters the region since it's in middle of it.
Just check the map. In triggers click Data -> View Script if you prefer galaxy
I'm attempting to use the event, Unit enters/leaves range of unit, but I can't find a way to reference the unit the unit with the range.
Event unit refers to the unit entering/leaving.
When the function is created (the actions portion of the trigger) is there anyway to pass the variable of the unit with range to it?
Or pass any sort of variable that can lead back to the source unit?
Any help is much appreciated!
I guess it's assumed you know the source unit because the event itself only allows for direct unit reference.
Otherwise you could try to pick all units around triggering unit and check is distance between triggering and picked == your trigger distance. This obviously could be inaccurate in rare scenarios.
@Juxtapozition: Go
Funny, I ran into that same problem just yesterday. The reference unit was stationary (a structure) in my case, so I just ended up using a "Unit Enters Region" event instead. I made a record that included a source unit and a circular region around it with the desired radius, so when the event fired I would reference the source unit associated with the triggering region. It might not apply in your case, but just thought I'd mention a possible workaround.
I see. Well it looks like that's a dead end.
Do you know of any clever and effective way to somehow pass the unit as a variable to the trigger?
Basically when I add a unit to a unit group, they're added to the event "Unit within range" so if anything gets close to them, an action will occur.
I have tons of units going through this at random points throughout the game. It's really a collision detection between particles.
What exactly do u want to do? I'm confuzzled... So u want this unit to check around it at a certain distance correct? What do you want to happen when this "collision" is detected?
You can look into dynamically adding events to triggers using the "TriggerAddEvent..." native functions. A good tutorial on the subject can be found here: http://starcraft-2-galaxy-editor-tutorials.thehelper.net/tutorials.php?view=155774 (make sure you check the "Use Reference" box for variable types like unitref, which the author did not do in his example)
This allows you to make and use some pretty useful functions that are not normally available in the GUI. In this case you'll be looking into creating a custom action that will add the "Unit within range of Unit" event to a trigger with specific unit(s) defined at runtime (instead of in the editor). You'd still have to specify a single unit for the second parameter in that event, so you'd have to ditch the idea of using a Unit Group to do it, but at least you could reference the unit some other way (as simple variable or event response) at the time of adding the event.
As a disclaimer, just know that I haven't been able to find very much information about adding events to triggers at runtime. I've been using it is many different ways without any trouble, but I'm sure it has its limits. I'd say give it a shot and see what happens.
Ah yes, this is actually what I've been trying to do in galaxy.
The unit referenced when adding the event to the trigger is the one that has the range around it, but there's no way to link anything more from that trigger to that unit. Unless the variable for that unit is automatically carried over?
Like,
TriggerAddEventUnitRange(checkParticleCollision, null, u, GCV(u, 6), true);
'u' being the unit with the range, checkParticleCollision is the name, GCV(u,6) is the range.
Maybe u carries over and can be referenced? I doubt it though, there's no parameter for it.
I have a few ideas on ways to do this,
Perhaps there's a way to add more parameters to this so I can add in a second variable?
Or the range could actually be a number relating to an global array of units? (unitgroup) but this would get rid of the idea of using a range:(
Or could a data table be of use here?
Possibly when the event is added with the unit u, u and the trigger can be saved in a data table which relates the two?
By finding the position on the data table of the trigger, then the unit u can be found?
I've never used data tables or hash tables in maps sadly
Edit: Sorry Oparcus didn't see your post at first...
Basically what's happening is a player casts an ability, a unit, u, is created. This unit u will have the event UnitWithinRange tagged with it. The problem is that once this function ends, there's no way to recall this unit U even when the event is triggered. It seems to dissapear and there's no way to reference it again.
After the event is called it should pass the eventunit and unit u to another function.
@Juxtapozition: Go
As you pointed out, there is no galaxy function that will return the reference unit of that event. Why? I think it's simply because Blizzard did not include it.
But I do think there's a way you could logically find the unit you're asking about. Here's how:
There might be some other checks you'll have to make to take into consideration the possibility of the triggering unit being within range R of multiple members of Unit Group G at the same time (if the triggering unit was teleported or walked into range of more than 1 member of Unit Group G at the same time).
you could attach new region to created unit, add simple unit enters region event and use 'Unit attached to trigerring region'
see the map
I've definitely thought about having a distance checker, but I think that it may accidentally grab the wrong unit under certain circumstances...
Nerfpl, do you know if attaching regions to units that are moved (trigger-wise) very quickly can be done without causing delay with many units?
If so, this may just be the answer!
i don't understand what moving a unit have to do with attaching region to it. Attached is attached. it moves with unit.
just add some unit filter condition to trigger to exclude missiles and other crap.
Wow, didn't know you could do that. Thanks for pointing that out!
Guess I need to spend some more time looking at native functions. BTW, is there an organized list of them anywhere? For some reason I have trouble finding text in the editor browser window.
there is easily missable search box when choosing function. For functions with return, create local variable of given type, click it's value and search, all listed will return this type.
There's no list as it's fairly sorted already by categories
So I started working with your region idea, but I can't get it to properly find the unit that enters the region now.
Here's the portion of the code that has it:
After this, only the EventUnit() dies, which is the unit with the region attached?? It doesn't make sense.
U can also use the data editor, make a buff that has a periodic effect that searches your desired range, and when the search finds a unit, execute a trigger dummy on the particle.
In triggers u would then want to make a trigger with the event "player any player uses [whatever u called your triggering effect]".
With this event you can get the unit that the effect was casted on, and the unit that casted the triggering effect with "triggering effect unit(caster)" and "triggering effect unit(Target)". When you have these 2 units it should be a problem to do what u want to do :)
You checked the map i attached earlier?
Attach means attach. What you currently doing is just creating region at current position of unit.
Also add EventUnit() != RegionGetAttachUnit(EventUnitRegion()) to your trigger to prevent unit triggering itself initially
Just check the map. In triggers click Data -> View Script if you prefer galaxy
Ah, now I got it working!
Haha that was quite the ordeal for such a simple way to do it.
Thanks for all the help Nerfpl, Oparcus, and Khaztr!