• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Leave within range?

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
there are some Jass functions called:

JASS:
constant native IsUnitInRange       takes unit whichUnit, unit otherUnit, real distance returns boolean
constant native IsUnitInRangeXY     takes unit whichUnit, real x, real y, real distance returns boolean
constant native IsUnitInRangeLoc    takes unit whichUnit, location whichLocation, real distance returns boolean

Which checks if a unit is in range of something else (unit, position or location depending on which one you use).
It returns a boolean as you can see.

You could do something like:

JASS:
if not(IsUnitInRange(myUnit, otherUnit, 200)) then
//do something
endif

This will check if the unit is not in 200 range of the other unit.
Couldn't that work with a periodic event?

In custom script it looks like this:
  • Custom script: if not(IsUnitInRange(udg_myUnit, udg_otherUnit, 500)) then
  • Some actions here...
  • Custom script: endif
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Ah, it is in Jass. Thanks, Hashjie.

You're welcome ;)

I suppose it is pretty simple to put this in a periodic event trigger that gets activated at a certain point? It's not an event so that's something you'll have to figure out. Or you could simply use it at a certain point to check whether something is still in range.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
How should I replace myUnit and otherUnit? With variables?

If you use udg_ in jass this means that it represents a variable in GUI.
so in other words: udg_myUnit is a GUI variable called myUnit.
The Jass native shows which types of variables can be used (takes) and which types of variables are returned (returns).
This is the same for any function in Jass.

You could even do something like:
  • Custom script: set udg_myBoolean = IsUnitInRange(udg_myUnit, udg_myOtherUnit, 500)
this way myBoolean will be set to true if myUnit is in 500 range of myOtherUnit, or will be set to false if it's not.

You can also use jass functions like: GetTriggerUnit() to refer to the triggering unit.

Here is a little list:

GUI FormJass Form
Attacked unitGetAttackedUnitBJ()
Cancelled structureGetCancelledStructure()
Constructing structureGetConstructingStructure()
Decaying unitGetdecayingUnit()
Dying unitGetdyingUnit()
Entering unitGetEnteringUnit()
Hero manipulating itemGetManipulatingUnit()
Learning HeroGetLearningUnit()
Leaving unitGetLeavingUnit()
Leveling HeroGetLevelingUnit()
Loading unitGetLoadedUnitBJ()
Ordered unitGetOrderedUnit()
Ownership-changed unitGetChangingUnit()
Researching unitGetresearchingUnit()
Revivable HeroGetrevivableUnit()
Reviving HeroGetrevivingUnit()
Selling unitGetSellingUnit()
Summoned unitGetSummonedUnit()

Remember that triggering unit is faster ;)
 
Status
Not open for further replies.
Top