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

[Solved] Custom AI Script Causing Crash In Game

Status
Not open for further replies.
Level 13
Joined
Oct 12, 2016
Messages
769
I've got a fatal error happening after about 2 hours of gameplay for my map. I suspect it to be some form of memory leak, and I suspect it to be in the following periodic triggers. I am not sure if any of them leak, or if there's a more efficient way to do this.

Older post, no longer an issue:

Can anyone look over these for me?

1) Fishing Boat Auto-fish trigger:
Simply put, a fishing boat enters the map and gets put into a unit group.
If it dies, it gets removed from the group.
My goal with this trigger is to make the fishing boat automatically "fish" the fishing spots with an ability based of Finger of Death.

2) Backpack follow system with auto-loot function:
Basically, the backpack unit constantly gets moved to the position of a specific hero.
The backpack unit counts as a flying hero structure, to avoid certain complications with shops and pathing. It is also an invisible, invulnerable dummy unit with zero movement speed and pathing.

The backpack is a hero that uses an autocast ability based on "replenish" to add the backpack unit to an auto-loot unit group, and automatically moves around while auto-loot is functioning.
HERO(player#) is created and assigned at game startup, same with BAG(player#).


EDIT:
I have pinpointed the source of my crash. It is the AI scripts themselves.
For some reason, whenever a player moves a unit near an computer player's base when it has a blacksmith, it crashes the game.
 
Last edited:
No leaks in the triggers shown here. Instead of ordering the bag to pickup the items, it would be more efficient to just add the item to the inventory.

If you use any power ups, like tomes, you have to remove the item or it will persist, causing lag. Additionally, periodically issuing orders to a high number of units for some reason causes serious lag over time.

There will always be more efficient ways of doing things, but for the task at hand, your triggers should suffice. I would look to other triggers to look for the culprit.
 
Level 13
Joined
Oct 12, 2016
Messages
769
Yea, I'm using Bribe's system to remove used powerups from the game:
  • Item Cleanup
    • Events
      • Time - Every 15.00 seconds of game time
      • Time - ItemCleanupTimer expires
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemCleanupFlag Equal to True
        • Then - Actions
          • Set ItemCleanupFlag = False
          • -------- --------
          • -------- Loop through all dead items and remove them --------
          • -------- --------
          • For each (Integer Loop) from 0 to ItemsToClean, do (Actions)
            • Loop - Actions
              • Item - Set life of CleanedItem[Loop] to 1.00
              • Item - Remove CleanedItem[Loop]
              • Set CleanedItem[Loop] = No item
        • Else - Actions
          • -------- --------
          • -------- Clean up all dead items on the map every 15 seconds --------
          • -------- --------
          • Set ItemsToClean = -1
          • Item - Pick every item in (Playable map area) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current life of (Picked item)) Equal to 0.00
                • Then - Actions
                  • Set ItemsToClean = (ItemsToClean + 1)
                  • Set CleanedItem[ItemsToClean] = (Picked item)
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ItemsToClean Greater than or equal to 0
            • Then - Actions
              • -------- --------
              • -------- Start a 1.50 second timer to give time for any death animations to play --------
              • -------- --------
              • Countdown Timer - Start ItemCleanupTimer as a One-shot timer that will expire in 1.50 seconds
              • Set ItemCleanupFlag = True
            • Else - Actions
However, in me map, there could be up to 9 of these backpack units being constantly moved around with the auto loot function on.
There are quite a few other periodic events, and I am currently looking over each one.

I could look into adding non-powerup items to the inventory, if that is more efficient. I am looking to improve everything as much as possible.


EDIT:
Could AI scripting made in the AI editor cause crashing over time?
 
Last edited:
Moving an item using triggers to a unit's inventory will trigger the same, "Unit acquires an item," event. So there is no issue doing this with powerups or regular items. Just a suggestion of course, your way will work, so will this way. Only difference is, less orders issued.

AI scripting may be an issue, but I have no experience in that field. Feel free to post other suspicious periodic triggers if you'd like.
 
Level 13
Joined
Oct 12, 2016
Messages
769
I can give an example for what's going on, and how I've got it structured.
I have this trigger as a startup command, and to make loading saved games possible:
  • Timer On
    • Events
      • Map initialization
      • Game - A saved game is loaded
    • Conditions
    • Actions
      • Trigger - Turn on Bag Position <gen>
      • Trigger - Turn on Item Cleanup <gen>
      • Trigger - Turn on Tree Revival <gen>
      • Trigger - Turn on Timer 1 Sec <gen>
      • Trigger - Turn on Timer 5 Sec <gen>
      • Trigger - Turn on Timer 12 Sec <gen>
      • Trigger - Turn on Timer 30 Sec <gen>
      • Trigger - Turn on Caravans <gen>
Then for the periodic events, for organization purposes, they are put into control groups:
  • Timer 12 Sec
    • Events
      • Time - Every 12.00 seconds of game time
    • Conditions
    • Actions
      • Trigger - Run Iron Mining <gen> (ignoring conditions)
      • Trigger - Run Zombies <gen> (ignoring conditions)
Afterwards, I have the actions for each periodic event:
  • Iron Mining
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in IronDepositGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Equal to 0
            • Then - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is dead) Equal to True
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from IronDepositGroup
                • Else - Actions
                  • Animation - Play (Picked unit)'s work animation
                  • Set TempInt = (Random integer number between 1 and 3)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TempInt Less than or equal to 2
                    • Then - Actions
                      • Hero - Create Iron Ore and give it to (Picked unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Current research level of Dig up 35 objects for (Owner of (Picked unit))) Equal to 1
                          • TempInt Equal to 1
                        • Then - Actions
                          • Hero - Create Iron Ore and give it to (Picked unit)
                        • Else - Actions
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • TempInt Equal to 3
                        • Then - Actions
                          • Hero - Create Coal and give it to (Picked unit)
                        • Else - Actions
As a reference, this is how units are added to that "IronDepositGroup"
  • Mining Deposit Groups
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Quarry
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Iron Mine 1 <gen> contains (Constructed structure)) Equal to True
        • Then - Actions
          • Set TempGroup = (Units in Iron Mine 1 <gen> matching ((Unit-type of (Matching unit)) Equal to Quarry))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Equal to 1
            • Then - Actions
              • Animation - Play (Constructed structure)'s work animation
              • Unit Group - Add (Constructed structure) to IronDepositGroup
            • Else - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
        • Else - Actions
How is this structure?
 
Level 13
Joined
Oct 12, 2016
Messages
769
Alright. I finally stumbled across what's causing the problem. And, I've been able to repeat the crash.
Every time I enter a computer player's base once it's built up to a blacksmith, the game just crashes.
I think this means it's an AI script problem. I am using a custom script made with the AI editor.

I'll upload the script being used. I have no idea what would cause the crash.

EDIT:
Apparently I can't load the .wai files by themselves.
Here is the map. There are 3 AI scripts, but the ones for computer playes are: "Warlord", and "Commander"

Seems the crash happens when I attack something in their base after they have a blacksmith?
I wonder if it's because I used cheats to make them build up faster ...
 
Last edited:
Level 13
Joined
Oct 12, 2016
Messages
769
I finally figured out the problem:
One of the AI buildings didn't have "requires buildable" ticked off in the object editor.

For some reason, this causes crashes sometimes when entering an AI player's base.
 
Status
Not open for further replies.
Top