Space Engineers

Space Engineers

AI Enemies - Waves of NPCs
 This topic has been pinned, so it's probably important
DarkkShadow0  [developer] 9 Dec, 2015 @ 2:42pm
Config File (Mostly for Dedicated Servers)
What is this feature
Even though you can now execute commands on dedicated servers (much as you would on locally-hosted ones), this feature can still be useful. Config files allow for setting several spawn points, and setting the type of attack that will be launched from each of them. Although designed primarily with Dedicated Servers in mind, it will work on single player and hosted games as well. It is a quick way to set-up a pre-configured, complex AI environment.

Using this feature
To begin, navigate to this mod's storage directory. The mod must be launched at least once for this directory to be created. This directory is located here:

%appdata%\SpaceEngineers\Storage\436731105.sbm_AiEnemiesV2

This directory contains files used internally by the mod. They are fairly self explanatory so if you feel adventurous and are tech-savvy, please feel free to go exploring.

Next create the config file in the aforementioned directory. If you name the file "autoload.cfg" it will be loaded automatically when the mod is launched. Otherwise it will have to be started in-game using the following commands:
/ai config load <filename> /ai config start

Please keep in mind that on a local server, debug information (script errors) will be printed in-game. It may be advantageous to test scripts in a local game before using them on a dedicated server. It should also be noted that when executing config files on a dedicated server, the files need to be present on the server itself, and not the computer you are playing on.

Debugging Config Files
Debugging config files is easy as it does not require restarting the mod. To begin with create your config file in the correct directory (as outlined above). Then load the mod as usual (I like to do this in an offline world on the 'Lone Survivor' map). Then execute these commands:
/ai config load <your script file name> /ai config start
Any errors in your config file will be displayed. If no errors are present you can wait and see if all is working as expected or use:
/ai config stop
This will ensure that your config stops spawning new ships. At this point you can alt-tab out of the game and edit your config file. When ready for another test run; alt-tab back into the game. Make sure you remember to save the changes you made to the config file before alt-tabbing back into the game. Then use the following commands:
/ai config reload /ai config start
The 'reload' command works just like the 'load' command except it automatically reloads the last config file which was loaded. It is important as though it ensures that the changes you made to the config file are loaded into the game. At this point you will again be shown any errors, or the config file will start working. You can then repeat the aforementioned steps until you are satisfied the config file does exactly what you want it to do. It can then be renamed to "autoload.cfg" and placed on your dedicated server. When given this name, the config file will be loaded automatically when your server starts. Otherwise you can always connect to the server and load the config manually using the appropriate commands.

Example Config File
An example file is shown below. It is fully documented. You can copy and paste the contents directly. If you want to look at the config file in order to understand the various commands; I recommend you read this file in notepad or another text editor because it looks confusing in the browser due to the long lines and insufficient space.
#Automated script for AI mod #Please note that all lines starting with a hashtag (#) are comments. They are a form of documentation and can be removed. #This config will be automatically loaded and started if it is called "autoload.cfg" (automatic load only takes place when the server starts, if the config file is modified at runtime it needs to be reloaded using the following commands) #Alternatively the following commands can be used to execute config files: # /ai config load <filename> (can be used to reload a config from drive at runtime) # /ai config reload (will reload the currently loaded config from drive) # /ai config start (this will start or restart the currently loaded config) # /ai config stop (this will stop the currently running config) #Disable safety so that we can spawn more than 15 ships safety = false #Delete ships when they become incapacitated (debris cleanup can help performance) remove_dead = true #Warn the player about the incoming attack waves #Note: This will only warn the host, not the other players warn_player = true #Sets up a spawn point #Multiple entries of this kind can be defined (feel free to remove or change any of the pre-configured ones) spawn { #Define the spawn position # x y z gps = 1000 1000 1000 #Define ships that will spawn #Accepts the custom-ship format too. e.g. 2:1 3:1 4:2 ships = sl 2 #How often should the ships spawn? #In this case ships will spawn every 180 (3 minutes) to 240 (4 minutes) seconds. (the range is there to make it more random) interval = 180-240 #Spawn if the previous wave is still alive? (i.e. when false; a new wave will not spawn until the previous wave dies) #Be careful; If this is set to true, and the interval is low; the game may spawn too many ships and become unstable. overflow = false #How long should a wave remain in_game before being removed? #This is useful in case an AI ship goes adrift (but is still alive) #This only works when 'overflow = false' overflow_timeout = 900 #delete ships after 900 seconds #WARNING: There is no safety check; i.e. If you set interval to 0-0 and oveflow to true, ships will start spawning VERY FAST. Expect a very big crash } #another spawn location spawn { gps = 1000 0 0 ships = s 3 interval = 600-660 #every 10 to 11 minutes overflow = true } spawn { #This entry will make AI ships spawn next to a random player instead of a specific GPS position. It cannot be used together with the 'gps' entry spawn_near_random_player = true #The randomized spawn distance in meters (in this case enemy ships will spawn between 1k and 10k meters of a random player) distance_to_player = 1000-10000 ships = s 2 interval = 60-120 #every 1-2 minutes overflow = false overflow_timeout = 600 # remove ships if they have been alive for more than 10 minutes } #Feel free to add more "spawn" instances or remove/change any of the ones above.
Last edited by DarkkShadow0; 3 Mar, 2016 @ 6:42pm
< >
Showing 1-8 of 8 comments
i wasn't able to get the file to load automatically so I'm trying to start it in-game. This may be a dumb question so I apologize in advance but what do u mean by /ai script load <filename>? Like what's the file name we have to put in? Thanks!
DarkkShadow0  [developer] 13 Dec, 2015 @ 1:44am 
You can have multiple config files. Lets say that one of them is abc.cfg . To load that file you would use "/ai script load abc.cfg" and then "/ai script start" . To make the file load and start automatically uppon mission start, all you have to do is name the file "autoload.cfg". Make sure you place all the cfg files in the right directory (as explained in the discussion).
Last edited by DarkkShadow0; 13 Dec, 2015 @ 1:50am
DarkkShadow0  [developer] 13 Dec, 2015 @ 1:51am 
Also I just found and fixed a little bug in the script example. Perhaps that was why it was failing to load for you? The "another spawn location" line was meant to be a comment (I forgot to put the '#' before it).
Abe Lincoln's B0N3R 14 Dec, 2015 @ 12:26pm 
so was able to get the example shown above to load but when I try to change any of the spawn instances when i load it to a new world it either does nothing or just continues to behave like the orginal example. I am loading it all up exactly how it's described above, is there anything else I should/shouldn't be doing?
DarkkShadow0  [developer] 15 Dec, 2015 @ 4:20am 
Hmmm. That is strange. Noting in the config-side of the mod is hard-coded. It loads up all the information from the config file. See if you can post your modified config here, and I will take a look at it. Hopefuly the contents of the file will fit in a comment.
Abe Lincoln's B0N3R 15 Dec, 2015 @ 10:09pm 
The file is made on notepad and it is pretty much the exact same as the example file provided above. I haven't touched anything except for the two spawn instance. I have tried taking all the lines with hashtags out and just changing the spawn instances. When I load it into a new world nothing happens at all. When I leave the #'s in the script just behaves as if it wasn't changed at all. So the only thing I can get to work is just the example. Here's what I did to the spawn instances. I left out the top half, it is the exact same as the example above. Thank you for taking a look into it!

spawn {

#Define the spawn position
# x y z
gps = 2000 2000 2000

#Define ships that will spawn
#Accepts the custom-ship format too. e.g. 2:1 3:1 4:2
ships = s 2

#How often should the ships spawn?
#In this case ships will spawn every 180 (3 minutes) to 240 (4 minutes) seconds. (the range is there to make it more random)
interval = 300-360

#Spawn if the previous wave is still alive?
overflow = false

#How long should a wave ramin in_game before being removed?
#This is useful in case an AI ship goes adrift (but is still alive)
#This only works when 'overflow = false'
overflow_timeout = 900 #delete ships after 900 seconds

#WARNING: There is no safety check; i.e. If you set interval to 0-0 and oveflow to true, ships will start spawning VERY FAST. Expect a very big crash
}

#another spawn location
spawn {

gps = -2000 -2000 -2000
ships = s 3
interval = 600-660 #every 10 to 11 minutes
overflow = true

}
DarkkShadow0  [developer] 16 Dec, 2015 @ 3:54am 
I will look into it and get back to you tomorrow or Friday with the answer. In the mean time you could examine the mod-log file (same directory as the script). The first few lines of that file should contain information about what is happening (or not happening) with the script.
DarkkShadow0  [developer] 16 Jan, 2016 @ 6:16am 
I am sorry for the wait. I was extremely busy in the time before the holidays, and didn't have time to properly investigate the issue. I have just tried loading the config you provided, and it worked for me. I am not sure what the problem was. The newest version of the mod will now clearly indicate when the config file is successfully loaded (in locally hosted games). I should point out; in your config you specified a time interval of 300-360 seconds. That is quiet a while, so perhaps you simply failed to wait long enough for the spawn? Either way, I am fairly sure that if you give it another shot (perhaps with a shorter interval), the feature will now work for you. If you still can't get it working, let me know.
Last edited by DarkkShadow0; 16 Jan, 2016 @ 6:18am
< >
Showing 1-8 of 8 comments
Per page: 1530 50