Keeping units together - Alternative to Unit Leaves Region... Why won't this work?

NuQ

Member
Reaction score
8
I have a watchman type unit that is supposed to wander, but obviously not too far away from the town it is guarding... I didnt want to have to create a bunch of regions and then move them to the position of the watchmen everytime one is trained... so i gave the town hall an aura and had it check to see if the unit had the buff when it was given an order. if it didnt it would order the unit to return to the town hall... but it doesn't work. here is the trigger:

Trigger:
  • Herding
    • Events
      • Unit - A unit Begins channeling an ability
      • Unit - A unit Begins casting an ability
      • Unit - A unit Starts the effect of an ability
      • Unit - A unit Finishes casting an ability
      • Unit - A unit Stops casting an ability
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Watchman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has buff Home ) Equal to True
        • Then - Actions
          • Do nothing
        • Else - Actions
          • Set CustomValue = (Custom value of (Triggering unit))
          • Set TempGroup = (Units in (Playable map area) matching ((((Matching unit) is A town-hall-type unit) Equal to True) and ((Custom value of (Matching unit)) Equal to CustomValue)))
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempPoint = (Position of (Picked unit))
              • Unit - Order (Triggering unit) to Move To TempPoint
      • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: call DestroyGroup (udg_TempGroup)


each unit is assigned a custom value when it is created, the custom value assigns it to which town it was created at, and is unique to each town. so all the custom value stuff is a way of refferencing each town hall. any clues why this won't work?

Edit: Shura has pointed out the infinite loop problem caused by the "Unit is issued an order targeting a point(move) event. that's just there as a relic of when I've tried changing triggering unit to ordered unit, casting unit, etc, to try to get it to detect when the wander ability is used. which just isn't happening. if i can't get this configuration to work, is there another way to keep wandering units in a general area (other than creating a region and a specific unit leaves region event)
 

Shura

New Member
Reaction score
45
Wouldn't that trigger cause an infinite loop? You order the unit to move to the point, which fires the trigger, which loops? So wouldn't it crash the game?
 

NuQ

Member
Reaction score
8
The loop only fires once for each unit as it is picked, doesn't it? and since there is only one unit in the playable map area that is a town hall type unit, with the same custom value as the triggering unit, it should only fire once.
 

Shura

New Member
Reaction score
45
I'm referring to the fact your ordering a unit to move in your trigger. This would cause your trigger to fire, which would cause your unit to be ordered to move again, which would cause the trigger to fire etc. If your map doesn't crash when this trigger should run, then the unit is never being ordered to move.
 

NuQ

Member
Reaction score
8
It would only order the unit to move until it was back in the aura and wouldn't be all that different from a user spamming the move command on the same location (ie, yes, its a spam, but the unit continues to move while being spammed.) at least, thats the intention...
 

Shura

New Member
Reaction score
45
The moment the trigger orders the unit to move, it fires, which loops instantly. This crashes the game.
Trigger:
  • trigger
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
    • Actions
      • Unit - Order (Triggering unit) to Move To (Center of (Playable map area))

You could try this if you wanted to. This trigger would crash the game once a unit is issued as order targeting a point.
Anyway, the point is, the unit is never being issued its order, which means there's a problem somewhere before that point in your trigger. You will also need to turn off the trigger, and then turn it on again when ordering the unit to move.
 

NuQ

Member
Reaction score
8
Theres got to be a way of keeping units together other than using pre-defined regions. bah.
 

Shura

New Member
Reaction score
45
Your trigger should work. You should go check to confirm the units are being given correct custom values. Then put in actions that display messages in your code at different places, to confirm that the code reaches the point where it displays the message.
 

Wratox1

Member
Reaction score
22
there is an ability called wander, its normally used on critters to make them run around in the forest, add that ability to your watchman;)
 

NuQ

Member
Reaction score
8
I have given them wander... The problem is they wander too, far eventually, and i want to order them to return home. No matter what i do i can't get it to detect when the wander ability is sued (unit begins casting an ability, unit begins effect of an ability, etc, nothing seems to pick up on it.)

@Shura: I know the custom value association thing is working because of this, here is the code to respawn the peasants if they die... using the same way of refering to their "home" town hall.

Trigger:
  • Spawn Peasants
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Peasant Dummy
    • Actions
      • Set CustomValue = (Custom value of (Dying unit))
      • Set TempGroup = (Units in (Playable map area) matching ((((Matching unit) is A town-hall-type unit) Equal to True) and ((Custom value of (Matching unit)) Equal to CustomValue)))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set TempPoint = (Position of (Picked unit))
          • Set RandomValue = (Random integer number between 1 and 7)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 1
            • Then - Actions
              • Unit - Create 1 Peasant (Mil) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 2
            • Then - Actions
              • Unit - Create 1 Peasant (Mil) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 3
            • Then - Actions
              • Unit - Create 1 Peasant (Mil) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 4
            • Then - Actions
              • Unit - Create 1 Peasant (Arc) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 5
            • Then - Actions
              • Unit - Create 1 Peasant (Arc) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 6
            • Then - Actions
              • Unit - Create 1 Villager (Female) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomValue Equal to 7
            • Then - Actions
              • Unit - Create 1 Villager (Female) for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to CustomValue
              • AI - Ignore (Last created unit)'s guard position
            • Else - Actions
              • Do nothing
          • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: call DestroyGroup (udg_TempGroup)


And that works, the peasants respawn at the village their were killed/first spawned at, without any problems(no duplicates at other town halls, either)

Initially i wanted it to just detect the wander ability when used, if it doesnt have buff, send back to town hall but i can't even get it to run the trigger in the first place. :confused:

I might jsut break down and create a hundred regions to be moved in the event one of these "watchmen" is created...
 

Shura

New Member
Reaction score
45
Why don't you try something like this?
Trigger:
  • test
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Watchman) and (((Matching unit) has buff Home) Equal to False))) and do (Actions)
        • Loop - Actions
          • Set Temp_Unit = (Picked unit)
          • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is A town-hall-type unit) Equal to True) and ((Custom value of (Matching unit)) Equal to (Custom value of (Picked unit))))) and do (Actions)
            • Loop - Actions
              • Unit - Order Temp_Unit to Move To (Position of (Picked unit))

You would need to clean the leaks yourself.
 

NuQ

Member
Reaction score
8
I tried doing a periodic event at sundown and sunrise, but it lags signifigantly when called and some of the units weren't being ordered to move for as much 2 hours of game time later than they should have been. i've of course done the "unit leaves region" thing which responded perfectly without any lag... but the whole point of this pursuit is to find another way of doing that.

here's an example of some of the weirder things i've tried.

Trigger:
  • Watchmen
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Watchman
    • Actions
      • Trigger - Add to Herding Test <gen> the event (Unit - A unit leaves (Region centered at (Position of (Trained unit)) with size (500.00, 500.00)))


and then here is the actual trigger that event is added to...

Trigger:
  • Herding Test
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Leaving unit)) Equal to Watchmen
        • Then - Actions
          • Set CustomValue = (Custom value of (Leaving unit))
          • Set TempGroup = (Units in (Playable map area) matching ((((Matching unit) is A town-hall-type unit) Equal to True) and ((Custom value of (Matching unit)) Equal to CustomValue)))
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempPoint = (Position of (Picked unit))
              • Unit - Order (Leaving unit) to Move To TempPoint
        • Else - Actions
          • Do nothing


Obviously it would leak if it worked in the first place... but just an example of some of the crazy things i've tried, all in the name of being lazy i guess.

Edit: Using the "(Region centered at (Position of (Trained unit)) with size (500.00, 500.00)))" thing works ifyou're using it in "Random point in region" move orders, but it doesnt seem to actually create a region that endures and can be used for "unit leaves region." :(
 
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