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

Spawn/attackmoving problem

Status
Not open for further replies.
Level 2
Joined
Dec 2, 2014
Messages
10
Hey guys, i am having big trouble getting my spawn/attack move system done. It intends to spawn units periodically and tells them to attack a random unit from a random player in Team 1. The spawned units do attack the target but if the target dies and there is no other target in range it will just stop walking :( can you help me fix that? i posted the same thing in world editor help zone but thought this forum fits my problem better.
  • Variable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Force2 = (All allies of Player 12 (Brown))
      • Set Force1 = (All allies of Player 1 (Red))
  • TownTier1UnitSpawn
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set AnyPlayerForce1 = (Random player from Force1)
      • Unit - Create 1 Town Slave for Player 11 (Dark Green) at (Center of SpawnLeft <gen>) facing Default building facing degrees
      • AI - Ignore (Last created unit)'s guard position
      • Unit - Order (Last created unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce1)))
      • Set AnyPlayerForce1 = (Random player from Force1)
      • Unit - Create 1 Town Slave for Player 11 (Dark Green) at (Center of SpawnRight <gen>) facing Default building facing degrees
      • AI - Ignore (Last created unit)'s guard position
      • Unit - Order (Last created unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce1)))
 
Add all created units to group "UnitGroup". (Do only use this group for this purpose. Don't work with it in other triggers)

Periodicly check "Current Order of PickedUnit == Order(null)" for each unit in this unit group.

If the mentioned condition is true, the unit currently has no attack/move order, so you can arrange a new evaluation to attack an enemy.

Read the tutorial "Things That Leak" in my signature, because you have memory leaks in your current trigger.
 
Level 2
Joined
Dec 2, 2014
Messages
10
Add all created units to group "UnitGroup". (Do only use this group for this purpose. Don't work with it in other triggers)

Periodicly check "Current Order of PickedUnit == Order(null)" for each unit in this unit group.

If the mentioned condition is true, the unit currently has no attack/move order, so you can arrange a new evaluation to attack an enemy.

Read the tutorial "Things That Leak" in my signature, because you have memory leaks in your current trigger.

Hey, what you suggested works :grin: thanks for your help unfortunately i have another problem, the trigger i will post will do just the same as the one i already posted but unfortunately it does, for some reason, not work. They will spawn but they do not move.


  • Variable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Force2 = (All allies of Player 12 (Brown))
      • Set Force1 = (All allies of Player 1 (Red))
  • MurlocSpawns
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set AnyPlayerForce2 = (Random player from Force2)
      • Unit - Create 1 Low-waters Murloc for Player 7 (Green) at (Center of MurlocLair <gen>) facing Default building facing degrees
      • AI - Ignore (Last created unit)'s guard position
      • Unit - Order (Last created unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce2)))
      • Set AnyPlayerForce2 = (Random player from Force2)
      • Unit - Create 1 Low-waters Murloc for Player 7 (Green) at (Center of MurlocLair <gen>) facing Default building facing degrees
      • AI - Ignore (Last created unit)'s guard position
      • Unit - Order (Last created unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce2)))
      • Set AnyPlayerForce2 = (Random player from Force2)
      • Unit - Create 1 Low-waters Murloc for Player 7 (Green) at (Center of MurlocLair <gen>) facing Default building facing degrees
      • AI - Ignore (Last created unit)'s guard position
      • Unit - Order (Last created unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce2)))



EDIT: heres also the trigger i made to check if the unit was not having an order, is it good like this?

  • Variable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set SpawningUnits = (Units owned by Player 11 (Dark Green))
  • CheckForOrder
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SpawningUnits and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(<Empty String>))
            • Then - Actions
              • Unit - Order (Picked unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce1)))
            • Else - Actions
              • Do nothing
 
You don't add created units to the unit group. You only set it once at initialization.

Also... are you sure you use correct players? You create units for Player 7, but at initialization you set your group to all units by Player 11.

- Responses like "PickedUnit" should be stored into a variable, and then the variable should be used, if used multiple times.
- When doing the same operations more often, it's recommended to use a loop to improve readability. (your unit creation)
- Already mentioned in post before, you have memory leaks.
- Never use "Do nothing". It is a completly useless blizzard function which does nothing.
 
Level 2
Joined
Dec 2, 2014
Messages
10
Why are you creating two threads for the same problem?
http://www.hiveworkshop.com/forums/world-editor-help-zone-98/spawn-attackmove-problem-259978/

Ask a moderator for the thread to be moved if needed, no need to have people answer your question twice.

Hi.. sorry for creating the same thread twice, i tried to delete the old one but i didnt find the button :( also i thought this was the better forum to ask for my problem

You don't add created units to the unit group. You only set it once at initialization.

Also... are you sure you use correct players? You create units for Player 7, but at initialization you set your group to all units by Player 11.

- Responses like "PickedUnit" should be stored into a variable, and then the variable should be used, if used multiple times.
- When doing the same operations more often, it's recommended to use a loop to improve readability. (your unit creation)
- Already mentioned in post before, you have memory leaks.
- Never use "Do nothing". It is a completly useless blizzard function which does nothing.

Hey, ty for your tips, for the leaks, i already fixed that with the callRemoveLocation, as for the player thing, i dont really know what you mean, i have 2 forces 1 with player 1-8, player 7-8 are neutral camps that the other 6 players can capture, when they capture it units will spawn for player 7 . Enemies are players 11-12 (Force 2). Also, i dont know what you mean that i can set the unit group once in map initialization, can you give me an idea of the trigger?
 
Last edited by a moderator:
So the attack order, immediatly after creation does not work if I understand you correctly?

Also read carefully. I never said you should set it the group only once at initialization, but I said:
You don't add created units to the unit group. You only set it once at initialization.
That means, that you have to add the created unit to the group.

And with players.... I meant why do you do this? :
  • Set SpawningUnits = (Units owned by Player 11 (Dark Green))
... if you spawn units for Player 7, but Player 11 is the enemy, which they should attack.

Last, do not double post. It is against site rules. Use the "Edit" button instead.
 
Level 2
Joined
Dec 2, 2014
Messages
10
So the attack order, immediatly after creation does not work if I understand you correctly?

Also read carefully. I never said you should set it the group only once at initialization, but I said:

That means, that you have to add the created unit to the group.

And with players.... I meant why do you do this? :
  • Set SpawningUnits = (Units owned by Player 11 (Dark Green))
... if you spawn units for Player 7, but Player 11 is the enemy, which they should attack.

Last, do not double post. It is against site rules. Use the "Edit" button instead.

Yep you are right the attack order did not apply after the units were spawned, but i got it to work doing the same thing i did with the town units, made a unit group, added the spawned units to that group and force them to attack. One thing though i am really confused about. In the CheckForOrderMurloc Trigger(last one i posted), when i set the AnyPlayerForce 2 Variable to = Random Player from Force 2 it does not work o_O but when i set it to Force 1 it will even though, as described in the first trigger, Player 7 is a part of Force 1... it works but i dont understand it o_O . THANKS for your help so far by the way(+ to your reputation)


  • Variable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Force2 = (All allies of Player 12 (Brown))
      • Set Force1 = (All allies of Player 1 (Red))
      • Set SpawningUnitsMurloc = (Units owned by Player 7 (Green))
  • MurlocSpawns
    • Events
      • Time - Every (Random real number between 4.00 and 6.00) seconds of game time
    • Conditions
    • Actions
      • Set MurlocSpawn = (Center of MurlocLair <gen>)
      • Set AnyPlayerForce2 = (Random player from Force2)
      • Unit - Create 1 Low-waters Murloc for Player 7 (Green) at MurlocSpawn facing Default building facing degrees
      • AI - Ignore (Last created unit)'s guard position
      • Unit - Order (Last created unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce2)))
      • Unit Group - Add (Last created unit) to SpawningUnitsMurloc
      • Custom script: call RemoveLocation(udg_MurlocSpawn)
  • CheckForOrderMurloc
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SpawningUnitsMurloc and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(<Empty String>))
            • Then - Actions
              • Set AnyPlayerForce2 = (Random player from Force1)
              • Unit - Order (Picked unit) to Attack-Move To (Position of (Random unit from (Units owned by AnyPlayerForce2)))
            • Else - Actions
 
Level 2
Joined
Dec 2, 2014
Messages
10
Hm I'm not sure, because I don't have the map opened. But maybe it's ok, if it works. :D

Btw, "Units owned by AnyPlayerForce2)" leaks a unit group.

Hi, i just thought it was working properly but it didnt, the units were always moving to one of my units and then to another one of mine and if they were to meet an enemy they would attack him. But i did get it to work using this:

  • CheckForOrderMurloc
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set SpawningUnitsMurloc = (Units owned by Player 7 (Green))
      • Unit Group - Pick every unit in SpawningUnitsMurloc and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(<Empty String>))
            • Then - Actions
              • Set Force2 = (All enemies of Player 1 (Red))
              • Set AnyPlayerForce2 = (Random player from Force2)
              • Unit - Order (Picked unit) to Attack-Move To (Position of (Random unit from (Units in (Playable map area) matching ((Owner of (Target unit of issued order)) Equal to AnyPlayerForce2))))
              • Custom script: call DestroyGroup(udg_SpawningUnitsMurloc)
            • Else - Actions

edit: ok nevermind that i think i fucked up completely this time... i made a trigger that spawns units with arrays and i forgot to add the index number to the callRemove custom script thingy,when i tested it the game did not start as it would normally disabling corrupt triggers, it got stuck in the progress thingy... when i used task manager to force close it and opened it again all my names and descriptions got renamed to something with TRIGSTR_ ... i guess i must rename all my stuff now?
 
Last edited:
Only destroy the group after the unit group iteration. At the moment you destroy it after first match.

You leak forces. (Player group)

"Unit - Order (Picked unit) to Attack-Move To (Position of (Random unit from (Units in (Playable map area) matching ((Owner of (Target unit of issued order)) Equal to AnyPlayerForce2))))"
^Here you leak a location + unit group.

"(Owner of (Target unit of issued order)" -> will not work, because it's a respone for the event "Unit gets order to a target". (or something similar)
"MatchingUnit" would be the correct response.

I'm not sure with your problem with strings. I never had it. Do you maybe have a backup map? Or maybe still a normal version in your Editor - Test folder?
 
Status
Not open for further replies.
Top