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

AI collecting items

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
In my map I tried to integrate an very simple AI, which basically just walks around the map and collects items, but also defends itself when attacked.

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Group_AI = (Units owned by Neutral Hostile.)
      • Unit Group - Pick every unit in Group_AI 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)) Not equal to (Order(move))
              • (Current order of (Picked unit)) Not equal to (Order(attack))
            • Then - Actions
              • Set VariableSet loc_Arena = (Random point in Region 000 <gen>)
              • Unit - Order (Picked unit) to Attack-Move To loc_Arena
              • Custom script: call RemoveLocation(udg_loc_Arena)
            • Else - Actions
          • Unit Group - Order Group_AI to Right-Click (Random item in (Region centered at (Position of (Picked unit)) with size (300.00, 300.00)))
The problem now is: The game instantly crashes as soon as the ai picks up an item. Has anybody an idea from which part of my trigger the crash is caused?

Edit: Another question: How can I add a loop to the random movement so the AI walks to another random point after reaching the first random point (not just to the first one and then stops)
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,850
In my map I tried to integrate an very simple AI, which basically just walks around the map and collects items, but also defends itself when attacked.

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Group_AI = (Units owned by Neutral Hostile.)
      • Unit Group - Pick every unit in Group_AI 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)) Not equal to (Order(move))
              • (Current order of (Picked unit)) Not equal to (Order(attack))
            • Then - Actions
              • Set VariableSet loc_Arena = (Random point in Region 000 <gen>)
              • Unit - Order (Picked unit) to Attack-Move To loc_Arena
              • Custom script: call RemoveLocation(udg_loc_Arena)
            • Else - Actions
          • Unit Group - Order Group_AI to Right-Click (Random item in (Region centered at (Position of (Picked unit)) with size (300.00, 300.00)))
The problem now is: The game instantly crashes as soon as the ai picks up an item. Has anybody an idea from which part of my trigger the crash is caused?

Edit: Another question: How can I add a loop to the random movement so the AI walks to another random point after reaching the first random point (not just to the first one and then stops)
I think its because you have the order of the group inside of the loop of the same group but I'm not sure, and if you wanna pick a unit that is not doing nothing use "Current order Equal to <Empty String>".

PD: You have a memory leak with "Position of Picked Unit" and the regions also leak, you have to do the same as point and groups with "Region centered at (Position of (Picked unit) with size (300.00, 300.00))".
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
I think its because you have the order of the group inside of the loop of the same group but I'm not sure, and if you wanna pick a unit that is not doing nothing use "Current order Equal to <Empty String>".

PD: You have a memory leak with "Position of Picked Unit" and the regions also leak, you have to do the same as point and groups with "Region centered at (Position of (Picked unit) with size (300.00, 300.00))".

You mean like this?

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Group_AI = (Units owned by Neutral Hostile.)
      • Unit Group - Pick every unit in Group_AI 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 VariableSet loc_Arena = (Random point in Region 000 <gen>)
              • Unit - Order (Picked unit) to Attack-Move To loc_Arena
              • Custom script: call RemoveLocation(udg_loc_Arena)
            • Else - Actions
      • Set VariableSet TempPos_Unit = (Position of (Picked unit))
      • Unit Group - Order Group_AI to Right-Click (Random item in (Region centered at TempPos_Unit with size (300.00, 300.00)))
      • Custom script: call RemoveLocation(udg_TempPos_Unit)
      • Custom script: call DestroyGroup(udg_Group_AI)
 
Level 24
Joined
Jun 26, 2020
Messages
1,850
You mean like this?

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Group_AI = (Units owned by Neutral Hostile.)
      • Unit Group - Pick every unit in Group_AI 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 VariableSet loc_Arena = (Random point in Region 000 <gen>)
              • Unit - Order (Picked unit) to Attack-Move To loc_Arena
              • Custom script: call RemoveLocation(udg_loc_Arena)
            • Else - Actions
      • Set VariableSet TempPos_Unit = (Position of (Picked unit))
      • Unit Group - Order Group_AI to Right-Click (Random item in (Region centered at TempPos_Unit with size (300.00, 300.00)))
      • Custom script: call RemoveLocation(udg_TempPos_Unit)
      • Custom script: call DestroyGroup(udg_Group_AI)
No, because you have "Picked Unit" outside the loop, I mean something like this:
  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Group_AI = (Units owned by Neutral Hostile.)
      • Unit Group - Pick every unit in Group_AI 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 VariableSet loc_Arena = (Random point in Region 000 <gen>)
              • Unit - Order (Picked unit) to Attack-Move To loc_Arena
              • Custom script: call RemoveLocation(udg_loc_Arena)
            • Else - Actions
              • Set VariableSet TempPos_Unit = (Position of (Picked unit))
              • Set VariableSet Temp_Rect=(Region centered at TempPos_Unit with size (300.00, 300.00))
              • Unit - Order (Picked Unit) to Right-Click (Random item in Temp_Rect)
              • Custom script: call RemoveRect(udg_Temp_Rect)
              • Custom script: call RemoveLocation(udg_TempPos_Unit)
      • Custom script: call DestroyGroup(udg_Group_AI)
 
Level 7
Joined
May 30, 2018
Messages
290
No, because you have "Picked Unit" outside the loop, I mean something like this:
  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Group_AI = (Units owned by Neutral Hostile.)
      • Unit Group - Pick every unit in Group_AI 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 VariableSet loc_Arena = (Random point in Region 000 <gen>)
              • Unit - Order (Picked unit) to Attack-Move To loc_Arena
              • Custom script: call RemoveLocation(udg_loc_Arena)
            • Else - Actions
              • Set VariableSet TempPos_Unit = (Position of (Picked unit))
              • Set VariableSet Temp_Rect=(Region centered at TempPos_Unit with size (300.00, 300.00))
              • Unit - Order (Picked Unit) to Right-Click (Random item in Temp_Rect)
              • Custom script: call RemoveRect(udg_Temp_Rect)
              • Custom script: call RemoveLocation(udg_TempPos_Unit)
      • Custom script: call DestroyGroup(udg_Group_AI)


Thanks for your help mate! I implemented your advice, but unfortunately the game still crashes as soon as the Ai collects an item. Maybe I really need to put the order outside of the loop...
 
Level 24
Joined
Jun 26, 2020
Messages
1,850
@Mechcash Thats weird, because I did the same myself and works fine, maybe the problem is another trigger that creates an infinty loop, what other triggers do you have with collect that item?

PD: How do you plan get the order outside the loop, if the order depends of the picked unit of that loop?
 

Attachments

  • Prueba.mp4
    12.2 MB · Views: 25
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
@Mechcash Thats weird, because I did the same myself and works fine, maybe the problem is another trigger that creates an infinty loop, what other triggers do you have with collect that item?

PD: How do you plan get the order outside the loop, if the order depends of the picked unit of that loop?


I found the problem...the items I wanted the ai to collect where of the type "power up"...with normal items the trigger works fine, with power ups the game crashes. Unfortunately I need them to pick up power ups, is there way to specify this ?

Edit: I even turned off all other item related triggers to see if they influence this trigger here, but it still crashes...I will investigate further

SOLVED: Iam a big dummie, I used non hero units to test the trigger, who have no level/exp gain. The game crashed, because my power ups gave them EXP. With hero units it works perfectly fine!
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,850
I found the problem...the items I wanted the ai to collect where of the type "power up"...with normal items the trigger works fine, with power ups the game crashes. Unfortunately I need them to pick up power ups, is there way to specify this ?

Edit: I even turned off all other item related triggers to see if they influence this trigger here, but it still crashes...I will investigate further

SOLVED: Iam a big dummie, I used non hero units to test the trigger, who have no level/exp gain. The game crashed, because my power ups gave them EXP. With hero units it works perfectly fine!
LOL
 
Status
Not open for further replies.
Top