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

[General] Making a wander ability with boundries

Status
Not open for further replies.
Level 6
Joined
May 26, 2012
Messages
177
OK my question is can I make a wander ability for a unit that it wanders through the map regularly but with bounds,I mean that the wandering unit don't move randomly everywhere and enter bases and get his shit kicked out of him,but moves randomly in a region around him and doesn't leave it unless attacked,then he returns after the attack ends.
Most will tell me:give him the wander ability and set a region for him that if he leaves;order him(By triggers)that the unit return to a random part in his region.

But this is wrong as:
1)if he gets attacked he will always return to the region and not chasing that unit which is stupid.
2)There would be hundreds of units and I can't trigger them one by one.


so if anyone knows how to do such a thing plz post triggers or attach a sample map.
Note:+rep and credits for helpers!
 
create a region in the area you want. then create a trigger like this
  • Untitled Trigger 001
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Current order of urUnit) Not equal to (Order(move))
          • (Current order of urUnit) Not equal to (Order(attack))
    • Actions
      • Set randomPoint = (Random point in urReg)
      • Unit - Order urUnit to Move To randomPoint
      • Custom script: call RemoveLocation( udg_randomPoint)
 
Using timer you do
if not IsUnitAttacked( your_unit ) then
IssueUnitPointOrder( your_unit, "move", UnitStartingX(your_unit) + GetRandomReal(-distance, distance), UnitStartingY(your_unit) + GetRandomReal(-distance, distance))
endif

UnitStartingX nad UnitStartingY takes unit returns real
using hastable you register unit X and Y at map initialization, something like
SaveReal( hashtable, GetHandleId( unit ), 1, GetUnitX( unit) )
SaveReal( hashtable, GetHandleId( unit ), 2, GetUnitY( unit) )
then UnitStartingX returns LoadReal( hashtable, GetHandleId( your_unit), 1)
and then UnitStartingY returns LoadReal( hashtable, GetHandleId( your_unit), 2)

Another trigger is simple damage engine
if unit takes damage then save boolean into hashtable as true
SaveBoolean( hashtable, GetHandleId( unit ), 0, true )
after some time set it to false (use counter to check last attack and so on)

finally IsUnitAttacked returns LoadBoolean( hashtable, GetHandleId( your_unit), 0)

3 triggers MAX in GUI.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
I believe he wants it done like in wow - you have a spawn point for each unit and the unit can move to a random point in ~500 radius around the spawn point.

In WoW, they have it done through dummy units I believe (as in an invisible unit stands where the actual NPC spawns).

Here you can do it more efficiently through point array like others said. This will probably be the most efficient choice if you want it to work like in WoW (i.e. 5 min respawn time, etc.), because you can use unit array (or better - custom value) to find out when unit dies, array points to find out where the unit should respawn and array reals to get a timer for each unit. Also using the unit's and point's same integer number you can easily set a "random" point in the XYZ radius around its spawn point.
 
Here you go, this should work for you just fine.
It has vjass elements but I didn't wanted to made it totally vjass like.

You should find it really easy to use. There are many API functions.
I added small respawn system as well, so you can see Flush function (recycler)
in action as well and so on.

Method I used is bad for 250+ units on the map, because of huge loop that
returns ID, it should not be problem in small maps, but if you code 5 hours long
RPG without any kind of refreshing data, this can become problem. I would like
to ask all of you not to upload this as resource, I will polish it later, and made
full vjass version of it and upload it myself. Right now it use single timer, but I
may add option so each unit use it's own timer if needed (ofc there is possibility
to group same timers into 1 and so on, but I don't want to bother you with
details).

All you need for this to work is Jass New Gen (both versions 5d or 5e works
just fine). Copy trigger with library into your map, and use other triggers to
see how to register (add new units) and flush (remove useless units,
something leak cleaning leaks).

Enjoy and have a nice day, -Kobas-.
 

Attachments

  • Wanderer.w3x
    20.1 KB · Views: 68
Status
Not open for further replies.
Top