moonsense715 Posted January 19, 2018 Report Share Posted January 19, 2018 Author: moonsense715 Skill level: 4 Welcome to the second chapter of the tutorials that will show you how to add and configure more sophisticated bots to your maps. In this lesson, we will activate the player-logic AI system and tell bots how to attack in groups. If you are a mapper, you will be able to fully setup your map to support bots. This tutorial assumes you know the basic concepts about the advanced bots. If you haven't seen the corresponding tutorial yet, it is strongly recommended you check it out. You can find it here. 1. Adjust unit presets Let's set up the presets for the bots so they fit the requirements. Whether you are a mapper or a game core builder, you will have to edit them differently. A) If you are just creating a map: You will have to work with the existing presets. If any of their settings do not meet the requirements or your needs, you will need to clone the original preset into a new Temp preset, edit that and use it for the bot system. Note that if you Temp a preset, it will cost 0 credits for the bots and require no production buildings or tech level, unless it is placed on a Temp purchase list, overriding the regular one. If a preset is already configured properly, you can just use it. B) If you are building a game core: Since you are building the core preset list, you can outright forget Temp presets or having duplicate presets just for bot usage. You can use the same presets for bots that players purchase and use. Make sure all presets you wish bots to use are configured to fit their battle role. Now for the requirements. Select a soldier preset that you want the bots to be able to play as. Look at the attached scripts on the Scripts tab. Make sure there is NO MS_AI_Behaviour script present. If this is OK, rejoice! Bots can use this preset, you don't need to touch it. Otherwise, make these changes. Attach a MS_AI_Preferences script and adjust the parameters so the unit prioritizes and shoots the right targets. Note: You can skip attaching this script, the bot then will automatically attach it ingame at runtime with the default parameters. Do this for every preset that you want bots to use. If for whatever reason you want a bot to use a different weapon with a unit than the one players have, use the MS_AI_Replace_Weapon script. Attach it multiple times, if more weapons need replacing. Although if you are working with Temp presets already, you can just change the weapon on the Settings tab. Otherwise, using the same presets for bots and players is recommended for better maintainability. The MS_AI_Preferences script almost has the same parameters as MS_AI_Behaviour, but it has no ObjectiveType. Therefore this script solves 2 things: 1. There is no need for duplicate presets, one for players and one for bots, since the preferences script does not activate the AI on the unit on startup. A controller script will. 2. Every preset can become offensive or defensive, so you dont have to create one preset for an offensive variant, and one for a defensive one. Great, you have the bot presets ready! 2. Create bot purchase lists In this system, the bots go into battle after choosing a unit they want to use, just like players. They take a look at a collection of presets, which we are going to define now. Thanks to this, we can block bots from buying certain units on specific maps, or only allow a few for special gameplay. All up to our imagination. Note: skip this step if you want to let bots use ALL of the presets that players can buy, including resource collector vehicles, support units, etc. Warning: at least the existence/creation of an Engineering Infantry purchase list is recommended! Otherwise, you will see bots try to repair buildings with damaging weapons. Alternatively, you can set the engi list parameter to "AUTOENGINEER" to let the game automatically find all the presets that can heal buildings already existing on the map. If you have also skipped adjusting the MS_AI_Preferences scripts on all the units, the bots will definitely be using some units the wrong way (harvesters will think they can shoot, deployable units will try to fire a weapon that only works in deployed mode, etc). We have to define 4 different purchase lists for the bots per team: Offensive Infantry (place characters on this) Defensive Infantry (place characters on this) Engineering Infantry (place technicians, engineers, any repairing characters on this) Vehicles (place vehicles on this) Scroll down to twiddlers. These twiddlers might already exist and be usable, in which case you don't need to create new ones (check the available twiddlers, all lists for both teams must be present). If they already exist, and your map does not require to change the available bot units, skip this step. First, let's create the Offensive Infantry twiddler for Allies. Select Twiddler and hit Temp or Add (as described at "Adjust bot presets"). Name it (e.g. BotInfantryAllied), then switch to the Settings tab. Click Pick Presets. (edit list) Select Object->Soldier in the Preset Type dropdown. Now you need to add presets to this twiddler list. To add a preset, double click it in the Preset Pool. It should then appear in the Selected Preset(s) list. You can remove the preset by double clicking it in the Selected Preset(s) list. Add all the Allied/GDI infantry presets that you want bots to use. Remember: they all should have the MS_AI_Preferences script on them (you should have set these up in the previous step)! Click OK then OK again to finish editing the Twiddler. Create an offensive infantry twiddler for the other team as well (Soviets/Nod). If you want the defensive infantry to choose from a different list, create lists for them too (otherwise they can just use the offensive list). Also create a vehicle twiddler for both teams. Lastly, create an engineering infantry twiddler for both teams (place soldier presets on this, ones that have weapons to repair buildings, don't put anything else on this list - in APB, these twiddlers contain only 2 presets, the Technician and the Engineer). Note: bots spawn as the same preset players do (e.g. Rifle Soldiers). You don't need to add these startup units to the twiddlers! You can add a preset multiple times to a twiddler. The more times a preset is on the list, the higher the chance the bot will use it (if it has enough credits for that preset). If a barracks or war factory is destroyed, the presets now unavailable to players will also become unavailable to the bots automatically. These lists are merely for fine-controlling what bots are allowed to use, and you, the mapper can decide that. Right, you are done with the lists! 3. Setup bot player controllers You could now ask: "How will the bots appear on the map?" It's time to make that happen. In the previous tutorial, we have placed our soldiers and vehicles (or their spawners) manually. This time we will make use of the same spawn positions where players start, so we don't have to define separate positions for the bots. In this tutorial, all the bots will have a controller. This is a script that every bot will have a unique copy of, belonging only to them. It will keep track of available credits, help decide what is buyable and ultimately control the spawning and vehicle purchasing procedures. The controller script for every bot is MS_AI_Player_Controller. We are not going to configure or create them manually, because that will be the job of a global bot controller script. But for the sake of tutorial completeness, and because they actually work individually too, you can read here what it can do: Spoiler The MS_AI_Player_Controller script is the pure brain, the controller, the virtual AI person controlling one bot at a time. The team designation can be set to 1 (Allied/GDI) or 0 (Soviet/Nod) in the parameters. All bots receive the same amount of credits on start as players do. If the mechanics are setup right, bots also receive money from resource collector vehicle dumps and credit trickles. It spawns one bot controlled character, this soldier preset is the same as what players spawn as (depending on the team). The location of the spawning can be the same as the player spawners. For this to work, the SpawnAtPreset parameter must not be touched, keep it as default ("USEPLAYERSPAWNERS"). Alternatively, mappers can use any other simple object as the spawn position locations (e.g. Dave Arrows) if they change this parameter to the name of the desired preset. Both methods collect all the spawn locations and pick one randomly to spawn the bot character there. After spawning, the bot takes a look at the available Soldier and Vehicle presets (available means they have enough credits and the production structure is alive and usable). These presets are the twiddlers we defined in the previous step, and their names must be given to the script (SoldierTwiddlerPreset, VehicleTwiddlerPreset parameters). Offensive and Defensive ObjectiveType bots have a 33% chance of purchasing any infantry (otherwise they are happy with the spawned character), while Engineering types will always buy a repair unit (try to make sure one of the repair characters on their list costs 0). Additionally, only Offensive bot types will purchase vehicles and only with a 66% chance (otherwise they will go into battle with their character only). If a bot purchased a vehicle, it will wait for it to build, then it will run to it and enter it. If it died before getting into the vehicle, it will try to get into it again after respawning. They also search for empty vehicles around and will try to steal one, before considering vehicle purchases. After the character and vehicle are chosen, the controller activates the MS_AI_Behaviour on the bot character, so it will start running for objectives, as seen in the previous tutorial. If the vehicle dies while the bot was inside, it will get out of it just like players, and will pick an objective. If the character dies, it will respawn and the cycle restarts. To create the bot controllers and with it, spawn the bots, we will use the MS_AI_Player_Count_Controller script. This script will create/delete the individual bot controllers, driven by MS_AI_Player_Controller. First, create an invincible, editor-only preset. To do that, Temp the Object->Simple preset, set its model to o_davesarrow.w3d, make it have Blamo skin/shield on the Settings tab, and tick IsEditorObject. Now go to the Scripts tab and attach the MS_AI_Player_Count_Controller script. Set the Count parameter to 12, so you will have 6 bots per team ingame (feel free to change the count, this is just an example). Set the next 8 parameters (4 lists for both teams) to the purchase twiddler preset names that were set up in the previous step. (Leaving any list param as the default USEPLAYERPURCHASELISTS will make bots use all units from the purchase lists. Recommendation: set the Engineering ones at least or set them to AUTOENGINEER to make the game find infantry that can repair buildings automatically.) Leave the last 2 parameters as default (USEPLAYERSPAWNERS), so the bots will start at the player spawn positions. Alternatively, they can start at any object preset if you prefer them not to share spawning positions with players. In such case, set this param to the name of that object and make sure there is at least as many of these across your map as many bots should be able to play. Note that the bots are aware of buildings being attacked and will switch to defensive/repair duties automatically. Bots will be removed/added one by one as players join/leave the game, so the total sum of players ingame (Count) will be the number of human players and bot players added together. So if the Count parameter is set to 12, and there are 6 players ingame, then 6 bots will be spawned. If all those players leave, 6 new bots will appear one by one. Finish editing your controller preset (OK) and place it somewhere/anywhere (Make). Save and export your map. You should notice that bots will join the game and start buying available units. Good job, you've got your bots setup to spawn, then buy infantry and vehicles! 4. Organize group attacks Right now your bots act individually and never cooperate with eachother in a group rush, which are normally more effective. Teamwork is often needed for victory in team-based games such as APB and TSR to name a few. So now let's teach bots how to do group attacks. We will have to define gathering positions for both teams. Bots will "register" themselves for a group rush. At the gathering points, they will wait for eachother to catch up (some units are slower than others, some are faster than the average), before running to the next gathering point and then the next. After reaching the last point, they will all be "released" to do their primary objective. If many bots went together, this can be a massive attack on the enemy base with many infantry/vehicles. This rarely happens with individual attacks, so this is our goal with the group attack. First let's create an invincible editor-only preset to be the "host" of the script we'll be using. Get the settings up like you did for the player count controller script, but without attaching that script. Now, pick a position around the Allied/GDI base and place (Make) the preset there. Unlike before, we will attach the script on the placed objects this time. So double click the object you just placed, and attach MS_AI_Rally_Point on the Scripts tab. Parameters: Team: 1 (Allied/GDI gathering point) NodeGroup: 0 (this is a gathering point/node in the attack route of index 0, there can be multiple attack routes in both teams, indexing is 0,1,2, etc.) NodeNum: 0 (this is a 0 indexed node in this attack route = the first gathering position, order indexing is 0,1,2, etc.) If we stopped here, bots would gather at this position and then run to their primary objective (if the objectives are setup right, this should be the enemy base) without waiting for eachother. So if the objective is far away and the bots have different speed, this could make the group rush uneffective. Now create another Rally Point the same way as before for Allies, somewhere inbetween the Allied and Soviet bases. So place another instance of your editor only preset, and attach MS_AI_Rally_Point, but this time, set NodeNum to 1 (bots will first run to Node 0, then to Node 1 and so on). Place the last Rally Point next to the Soviet base, outside of the range of any existing defenses (otherwise they will get damaged while waiting). Set NodeNum to 2 to finish creating this attack route (the highest NodeNum is always the last position in a given attack route). Now create 3 Rally Points for the Soviet/Nod bots as well. Do the same steps as before, but set Team to 0. You can create more than 1 attack route for both teams so bots can use more of your map. For a second route, just create Rally Points and set the NodeGroup parameter of all belonging points to 1. If you define yet another attack route, set the NodeGroup to 2, and so on. Bots will randomly choose one attack route and carry on following your defined positions. You also have the ability to randomize the gathering positions a bit. Let's say you have a NodeGroup 0 but want the first gathering position to be randomly chosen from 2 different positions. To do that, just place an object with NodeGroup 0 and NodeNum 0 twice, and move them to different positions. Bots will choose one of them randomly, and then move on to NodeNum 1 (for which you can also define multiple locations). As for how the bots decide which one of them will join the group attack and when: - There is only 1 grouprush per team at a time. - The first rush registration starts at mapstart and a new one starts when the current group reached the last Rally Point or if they all died while trying to get there. - Once half of the bots on a team have registered for the rush (also a maximum limit of 8 bots), the registration closes and the bots will begin running towards the Rally Points. - While the registration is open, all offensive bots will join it after spawning immediately. Congratulations, you are done! 5. Optional: Bot names You have probably noticed that all the bots have a nickname tag: "Bot". If you want them to have individual names, this is the section you are looking for. Create a new text file, and name it bot_names.cfg. Copy this into it: [BotNames] BotName0=[Bot]Benny BotName1=[Bot]John So far you have 2 special bot names set up (feel free to change those 2 names). Using the "BotNameX=Name" syntax (where X is an index number), you can set as many as you wish, but make sure the indexing starts with 0. The AI Player Count Controller script will hand these names to the spawned bots randomly, but each name will only be given to just one bot at a time. If there are more bots ingame than names, the rest of them will get the default "Bot" name. You are done with everything now, please go and enjoy the bot battles you've just added to your map =) Q & A My bots are acting weird when seeing enemies/getting within attack range. Why? Make sure the primary weapon's Range it is using is always higher than the Max_Attack_Range script parameter. Bots refuse to attack my base defense/building. What did I do wrong? If it's a Simple/Vehicle object: - Either attach the MS_AI_Building script to it, or - Create a file called bot_config.cfg. and put this into it: ; List simple objects, base defenses, etc. here that need bot repairs but you cannot attach the bot building ; script to them for some reason (e.g. old games, no level sources) or you are lazy to do it in LE/Mammoth ; Replace the names with your preset names that should be attacked/repaired by bots, you can have more. [BotTargets] Target0=my_base_defense Target1=my_random_building ; Uncomment the settings below if you wish the game to create w3d models at the objective/target locations. ; This way you can check if something is wrong. ; Replace the entries in TargetModel/DebugObjectiveModel with model names that exist in your game. [Debug] ;EnableBuildingTargetsDisplay=true ;BuildingTargetModel=v_spotlight ;BuildingDebugObjectiveModel=o_davesarrow Bots have super good accuracy, they are too hard to fight against. Is there a way to nerf them? Increase the WeaponError value on the Settings tab of the preset. This will only affect bots, not players. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.