• 🏆 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!

Pathing Help

Status
Not open for further replies.
Level 5
Joined
Jun 29, 2009
Messages
142
I've been doing some NPC (non-player computer) pathing for my city in my map. One feature I've added is so when you click a person within a certain range he turns to look at you. If you deselect him or walk away it looks back to its original facing direction.

This is all good and works perfectly, but there is one flaw. I have a guy that walks around the city. When I click him he look at me, but when i walk away he doesn't continue on his walk. I did see that there was a variable called "order(ordercode)" and I'm assuming that it saves the current order of the unit. Now the only problem is to give that unit the saved order code...


How do I save the current order a unit was given and then later give that order to the unit again?

Ex:
  • Events
  • Unit - Unit is clicked
  • Conditions
  • (Owner of (Triggering unit)) Equal to (==) Neutral Passive
  • Actions
  • Set CurrentOrder = (Current order of (MyHero))
  • Wait 2.0 seconds
  • Unit - Order NPC to (CurrentOrder)
 
Last edited:
Well, you can add him in a unit group in the map initialization and once he gets clicked, he is removed from it. Then, he is issued an additional order to move towards a random point, after you deselect him or go away enough. The unit group is the group where you issue him to move. I guess you are using a custom walking system, not a Wander (Neutral) ability, right?
 
Well anyway, just order him to move to the center of the next region, so that you "wake him up".
  • Trigger
  • Events
    • Map Initialization
  • Conditions
    • Set Regions[1] = Region 0001 <gen>
    • Set Regions[2] = Region 0002 <gen>
    • Set ...
  • For each (IntegerA) from 1 to X, do (Actions)
  • Loop - Actions
    • If (All conditions are true) then do (Actions) else do (Actions)
      • If - Conditions
        • (Regions[(IntegerA)] contains (Your unit)) Equal to True //This is Boolean comparison
      • Then - Actions
        • Set Point1 = (Center of (Regions[((IntegerA) + 1)])
        • Unit - Order (your unit) to Move to Point1
        • Custom script: call RemoveLocation (udg_Point1)
      • Else - Actions
"X" defines the maximum number of arrays you used in the first trigger; if you have 20 regions for example, you will use 20 as a number.
 
I don't get it; since this unit is a reference through the "Player 1 (Red) deselects a unit" and it's a reference of "Triggering unit" it can be done. If it is "got away from the source", then you need a periodic event to check the distances between your character and the wandering person. If the distance is greater than or equal to X, then order your wandering person to move to the next region. They only wander, right? They don't cast spells and stuff/attack. If they did, then you would need their current order variabled. Even if they are doing other stuff as well, just save the order via hashtable on the unit (Current order of (Triggering unit)) and once the distance explained above is greater than or equal to X, then custom script it:
  • Set Order = (Load (Key(order)) of (Key(Picked unit)) from Hashtable //Picked unit, because it will be a Unit Group pick
  • Set Destructible = (Load (Key(destructible)) of (Key(Picked unit)) from Hashtable
  • Set Point1 = (Load (Key(location)) of (Key(Picked unit)) from Hashtable
  • Custom script: call IssueImmediateOrder (GetEnumUnit(), udg_Order)
  • If (All conditions are true) then do (Actions) else do (Actions)
    • If - Conditions
      • (Destructible) Equal to No Destructible // Destructible comparison: this defines whether the current order of his was towards a destructible or a unit
    • Then - Actions
      • Set Unit = (Load (Key(target)) of (Key(Picked unit)) from Hashtable
      • Custom script: call IssueTargetOrder (GetEnumUnit(), udg_Order, udg_Unit)
    • Else - Actions
      • Custom script: call IssueTargetOrder (GetEnumUnit(), udg_Order, udg_Destructible)
  • Custom script: call IssuePointOrder (GetEnumUnit(), udg_Order, udg_Point1)
  • Custom script: call RemoveLocation (udg_Point1)
The above trigger contains every possible order your unit had. If it was a point order/a target order/an instant order, it will issue it to do so.
The Point1 is a Point variable, the Order is a String variable, the Unit is a unit variable and the Destructible is a destructible variable. So, it restores the order and up to what the object of the order was, it issues to do it anyway.
 
Level 10
Joined
Mar 31, 2009
Messages
732
Ex:
  • Events
  • Unit - Unit is clicked
  • Conditions
  • (Owner of (Triggering unit)) Equal to (==) Neutral Passive
  • Actions
  • Set CurrentOrder = (Current order of (MyHero))
  • Wait 2.0 seconds
  • Unit - Order NPC to (CurrentOrder)

Couldnt you do something like...

  • Events
  • Unit - Unit is clicked
  • Conditions
  • (Owner of (Triggering unit)) Equal to (==) Neutral Passive
  • Actions
  • Custom Script - local currentOrder = GetUnitCurrentOrder(GetTriggerUnit())
  • Unit - Tell it to stop
  • Unit - Tell it to do what youre wanting
  • Wait 2.0 seconds
  • Custom Script - call IssueImmediateOrder(currentOrder)
 
Also notice that the "Pause" action (Unit - Pause unit) lets the units remember the action and, once unpaused, it continues its previous action, so I guess that would be your back-up solution (cause I'm not sure if a paused unit can face something). If it can face something you order it to, then here is your answer. It displays this little info on Unit - Pause unit action (the explanatory grey text on the window).
 
Status
Not open for further replies.
Top