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

[Solved] Order Unit to Attack System Issue

Status
Not open for further replies.
Level 13
Joined
Sep 25, 2013
Messages
717
Hello, i've been working on my own custom resource system with an additional resource. Its been a very complex process and i have mostly got it under control but i am having problem. This trigger is supposed to order workers to continue attacking (harvesting) more of the same resource in the general area after they have used up all the resources (killed) of the resource they are attacking.

Code:
Slaughtered Pig Continue
    Events
        Unit - A unit Dies
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Unit-type of (Triggering unit)) Equal to Slaughtered Pig (Nature)
            Then - Actions
                Set tempUnitGroup = (Units within 300.00 of (Position of (Triggering unit)) matching (((Matching unit) has buff Worker (All)) Equal to True))
                Unit Group - Pick every unit in tempUnitGroup and do (Actions)
                    Loop - Actions
                        Set tempUnitGroup2 = (Units within 300.00 of (Position of (Picked unit)) matching ((Unit-type of (Matching unit)) Equal to Slaughtered Pig (Nature)))
                        Unit - Order (Picked unit) to Attack (Random unit from tempUnitGroup2)
                        Custom script:   call DestroyGroup (udg_tempUnitGroup2)
                Custom script:   call DestroyGroup (udg_tempUnitGroup)
                Unit - Remove (Triggering unit) from the game
            Else - Actions

The problem is that some of the workers continue on to another resource while others become idle. The range shouldn't be the problem since i make sure there are plenty of resources around and within 300 range. Is there a better way i can do what I'm trying to do? Thank you for your time
 
Level 13
Joined
Sep 25, 2013
Messages
717
Please use the [trigger][/trigger] tags.
You leak locations in your trigger.

Are you sure there are plenty of resources within 300 range? How big the distance from one area to another?
I'm pretty sure the range is the problem here.

Thanks i'll fix those location leaks.
I figured it out actually lol! The problem is that when the workers kill a resource, they are ordered to attack a random resource of the same type within a range. Well, sometimes the workers randomly target the resource they just destroyed since that unit is part of the 2nd temp unit group. So since it no longer is alive, the workers just go idle. This is the new trigger

  • Slaughtered Pig Continue
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Slaughtered Pig (Nature)
        • Then - Actions
          • Set tempUnitGroup = (Units within 300.00 of (Position of (Triggering unit)) matching (((Matching unit) has buff Worker (All)) Equal to True))
          • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
            • Loop - Actions
              • Set tempUnitGroup2 = (Units within 300.00 of (Position of (Picked unit)) matching (((Unit-type of (Matching unit)) Equal to Slaughtered Pig (Nature)) and ((Matching unit) Not equal to (Triggering unit))))
              • Unit - Order (Picked unit) to Attack (Random unit from tempUnitGroup2)
              • Custom script: call DestroyGroup (udg_tempUnitGroup2)
          • Custom script: call DestroyGroup (udg_tempUnitGroup)
          • Unit - Remove (Triggering unit) from the game
        • Else - Actions
The main problem i have now is that if there happens to be another worker within range that is doing something else like harvesting lumber or repairing something they will be redirected to attack the resource.
 
Level 13
Joined
Sep 25, 2013
Messages
717
oh, that's a good idea, i've never used order comparisons before. Is there a repair order to check for also? Also, i was thinking of making so whenever a worker attacks a resource a dummy unit casts a spell on them with a buff related to the resource type. The buff would only last like 3 seconds, so if they stop attacking the resource it will go away soon. The trigger would only target those workers with the specific buff.

EDIT:

So i tried the command system and doesn't seem to work. I probably did something wrong.

  • Slaughtered Pig Continue
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Slaughtered Pig (Nature)
        • Then - Actions
          • Set tempPoint = (Position of (Triggering unit))
          • Set tempUnitGroup = (Units within 300.00 of tempPoint matching ((((Matching unit) has buff Worker (All)) Equal to True) and ((Current order of (Matching unit)) Equal to (Order(attack)))))
          • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
            • Loop - Actions
              • Set tempPoint2 = (Position of (Picked unit))
              • Set tempUnitGroup2 = (Units within 300.00 of tempPoint2 matching (((Unit-type of (Matching unit)) Equal to Slaughtered Pig (Nature)) and ((Matching unit) Not equal to (Triggering unit))))
              • Unit - Order (Picked unit) to Attack (Random unit from tempUnitGroup2)
              • Custom script: call DestroyGroup (udg_tempUnitGroup2)
              • Custom script: call RemoveLocation(udg_tempPoint2)
          • Custom script: call DestroyGroup (udg_tempUnitGroup)
          • Custom script: call RemoveLocation(udg_tempPoint)
          • Unit - Remove (Triggering unit) from the game
        • Else - Actions
EDIT:

Okay so i used my buff idea and it works perfectly. Thanks for your help +rep
 
Last edited:
Status
Not open for further replies.
Top