![]() Mechstorm's Complete Map Making Tutorial or MCM for Short. Covering Mechwarrior4, Mechwarrior4:BK and Mechwarrior4:Mercs. If you have any questions feel free to drop by our Mechstorm Editor/Scripting help Forum after you have registered on our forums. |
|
Updated Jan 23 2005 AI Brain FilesAI Brain file are used for any map object that interacts with the map (or in english mostly Bots), be it moving, shooting or just sending a message when it's destroyed. You can make an object look as smart or as dumb as you like using Brain file. The Brain files supplied by the devteam are functional but some require editing. They can never replace a Brain file created by you for your own map though. Customising Brain files can result in some rather smart bots. How far you take this is entirely up to you but to know how it can be done is the first step to making it happen. Just like the previous chapters, this one requires you to study the commands available to you. I cannot teach you how to learn those commands. I can only show you where to use them, giving you some practical examples along the way. Step 1: Exploring an AI Brain FileLets start our tour of the AI Brain files with a look at an Easybot script. We will use the devteams own bot scripts for this first look at an AI brain file. You will need to understand how to make an empty script as explained in previous sections of this tutorial before you can make that empty script do anything interesting. Looking down the script below you will notice the abl script follows all the same rules we have talked about in the first two scripting chapters. The var's, functions and states are all the same. However if you look at the function section you see some very strange commands. These commands seem to be oddly specific when we compare them to other commands we have used. These are commands that only work inside AI Brain files. You can find a full list in the ABL_orders doc. Use it to find out the meanings of the commands below. Remember the introduction to var's in the previous chapters as you do so. The AI Brain file makes use of one of those vars more than almost any other script. The var in question is the Static Real var. Remember the decimal point chat we had. This is where you make use of it. Now study the script below, apply what you have learnt in the other chapters to this script and try and understand what is going on. All the same basic rules apply here so you should understand how the script below works even if your totally confused by the actually commands. Learning how to read how a script flows is the first skill you need to master and the command that lets the game move to another state is called Trans. The name that follows the Trans Command is the state name its sending the game too next. So see if you follow how the game moves around the script below. The only new reference you will see is the word ME. ME = the object the script is attached to. So all values that are referred to as ME are talking about the AI using the script. You will also find this information in the ABL_Orders doc.
// EasyBot: //------------------------------------------------------------------ //------------------------------------------------------------------ const //------------------------------------------------------------------ type //------------------------------------------------------------------ var //------------------------------------------------------------------ function Init; SetIgnoreFriendlyFire (ME,true); EnablePerWeaponRayCasting (ME,TRUE); endfunction; //------------------------------------------------------------------ state StartState; endstate; //------------------------------------------------------------------ state WaitToAmbushState; OrderMoveLookOut; //------------------------------------------------------------------ state AttackState; OrderAttack(TRUE); //------------------------------------------------------------------ state DeadState; endstate;
Step 2: Looking closer at AI bot commandsLets look at some of the values from the script above. Again you can find full information on these in the ABL_Orders doc so I'll talk you through how these can be used to create different effects instead. The attack and withdrawrange commands help the AI select its target. the values below will mean the AI will find a target at extreme range and won't stop until it's dead. This may sound good but it's not. Suppose I had one team mate in a cougar run within range of this bot and then run away. The bot will try and follow the cougar as long as it could. I could then stand next to that bot in a diashi and I would be ignored completely. It is important therefore to make sure attack and withdraw ranges are understood and balanced correctly to allow the bot to shoot at a closer target if the need arises. Of course you could configure a group of mechs with different ranges and make sure the weapons they carry are good at those ranges. This would be the correct way to use these commands in the game. attackRange = 9999; Most of these tell you what they do and do not need explaining but some have special meanings. For instance, the set minfiringdelay can be used to speed up the mechs shooting in the game. Setattackthrottle is the movement speed of the mech but the good stuff is the last 4 commands SetisShot is used to determine if a mech has been shot at, it creates an invisible bubble around the mech. Any shot that hits that bubble will be considered an attack on the mech itself and it will respond. Right now its set to 160 but suppose we were using the mech to defend a fortified position. A combination of the combat leash command and a SetisshotRadius of 400m would mean anything units shot near by would trigger this mech to act as if it too was shot. Thereby giving your AI frontline ability to respond en masse. However this is not the correct way to do this. There is another command that is designed for this in the ABL_Orders doc. Now I could lay it all out for you here and tell you exactly how it is done but as learning to script requires you to read about the commands and what they do, I won't.Instead I will simply tell you to look up the command SetGroupAI. See if you can figure out how this works and how you can use it to do the same job. One tip though, before you can use it, you will need to add all your mechs to a single group. That means you will have to look up how this is done in Group/Team Functions in the ABL_Orders doc. So lets make it your first task to creating a group of mechs and then apply the SetgroupAI command to that group to make them act as if they were one single mech. SetIgnoreFriendlyFire (ME,true); EnablePerWeaponRayCasting (ME,TRUE); The Setentropymood and Setcurmood also affect reaction speeds and these tend to change during combat. Setting this to a more aggressive level will make the Mech more aggressive in its actions. EnableperweaponRaycasting simply makes the weapons more accurate but the cost to the server is quite high so only use it when needed. You'll be thinking ahead of me now, pre-empting my tutorial hints and wanting this tutorial to simply end so you can experiment yourself. If you feel that way right now then the tutorial has done its job and I look forward to having some fun against your AI's on your map. IF you're still scratching your head, don't worry. The key here is learning the commands in the ABL_Order Doc. It just means you need to study the doc more. Step 3: Brain files are so much like gametypes it hurts.Time for me to make a point about Brain files and Gametype scripts. Lets work in the states from any AI Brain file you care to pick. We won't deal with var's and functions. If you want to use some of these examples in your own brain files you have to spot what var's and functions these parts of a script will need and add them. Now lets show you how to make a mean AI follow a path. I will assume you have placed your path on the map and called it mypath. With the path var set to mypath in functions and the rest of the required commands in place this next state will allow your mech to do patrols along routes you have laid out in the map editor state followmypath; if (FindEnemy(attackRange1,findTypes)) then if (path <> -1) then The thing here is everything, all the important details are not in this state. It looks complicated but they are actually controlled from functions. Path, speed, movetype etc are declared at the top of our script as var's and setup in functions. Lets look at the functions now so you can compare the two. function Init; whoToJoin = NO_UNIT; attackRange2 = attackRange1; takeOffDistance = 150; // driver settings endfunction; You can now see what the var path means and what speed and movetype are set too. So you know not to edit the state followmypath but to edit the functions meaning instead. This saves you a lot of time going through an entire script changing path names when you have used functions in this way. This doesn't stop you from changing a value in say gunnery or withdrawrange2 later in the script. Most of these can be changed several times in a script. for instance if your mech is plodding along between two boring waypoints and when it reaches waypoint muchoaction you might want to wake up the pilot and make him more aggressive. so you change the mood and the gunnery skill when he reaches that waypoint. We have already talked about how to make waypoints in your scripts, the information needed for an AI brain file is EXACTLY the same code. So you see, we are now repeating ourselves. If you skipped Chapters 6 and 7 this will be a mystery to you. My advice would be to read those chapters then come back here. Step 4: Making paths for AI units.Now we will look at how to make mechs follow a path. In the map editor, select the resources window and go to misc. Scroll down the list of misc items until you find node. Select node and open the overview window so you can see your map. Zoom in to the area where you want to place the path and with the shift key pressed start placing nodes on the map. Keep hold of the shift key until you're finished. When you are finished, make sure the full path is selected and double click on a node. This should bring up the full path's properties. Name your path anything you want. remembering not to use spaces or the minus sign. Now in your script you simply use path = yourpath name and any AI script that is setup for patrols will use your path. You can see how the devteam lay out their path scripts and create your own based on those. Now all the pieces to making paths work are clearly visible to you. You should have no trouble getting them to work. Step 5: Using AI Brain files on map objects.To get any script to be available on your map you must first copy it to your maps scripts directory. The path to my grandcanyon scripts directory for example would be....... mechwarrior4\content\Missions\GrandCanyon\Scripts So make sure all the scripts you want to use are in that directory. You can use the map editor to add some of the devteams scripts to your maps script directory but your own will have to be manually copied across. Now double clicking on an object on your map that you want to add a script to will bring up its properties window. The left hand side of the object properties window was explained in a previous chapter as it concerns object naming and placement. Whilst the name matters to us here, you don't have to know it in a brain file as the script is attached to the AI already, we dont have to name it to identify it. So we will deal with the right hand side options on the object properties window. Skin: You use this to set an AI mechs skin, you can choose from any of the MW4 skins found in the game. I personally like skins 8 to 13. Alignment: Here you assign the AI to a team or leave it at default. Driver: This is where you choose the type of AI you want to use. Turrets use an AI shooter but clicking on different objects on the map changes the options on this list. Script: Here you choose your script, you can use the add script button to add a devteam script to your maps scripts directory but you will have to give it a new name. This option will ask you to enter a new name. Remember to do so. Memory cells: These are used to fine-tune some parts of the AI behavour. The Editor_Tutorial Doc contains the info about Memory cells and how to use them. ABL_Orders Doc tells you about memory cells commands and how to use them in your script. Memory cells can be set or changed in your scripts. So they are worth reading about. They can also be used to get single player scoring to work but all my attempts proved to be too much of a load on the server. General tip: If you want your map objects to have a working AI script then you should not make them indestructable. Doing so seems to prevent the script from working in all our Mechstorm tests. Step 6: Using memory cells[Inspired by a chat between Ash and RichardVictory in the Mechstorm forum]An objects memory cells offer the map maker a way to change values in the game, it is probably best to think of these as triggers for actions as the cells value is meaning less without some able code to execute in the case fields. Memory cells are normally set and controlled through an AI Brain file, but the options that you write in to the CASES that follow need not be for that AI. You could change any setting for any unit or map object via 1 single units memory cell settings. Considering the use of Var's in a commands arguments can cause problems, memory cells may off you an alternative way of doing the same thing. In the official Editor Tutorial, you will notice the Devteam only use noncomms as an example of how to use memory cells. You can set up their meaning with in a script your self. You should not automatically assume the Devteams instructions are set in stone and always mean what they say they mean in that tutorial. Remember, memory cells are available for buildings, tanks and mechs as well as noncoms so it follows that a building would not always want to walk around clockwise figgeting like noncoms do. You can set the initial starting values of a memory cell via the objects properties window in the Mission Editor. You can also change these values in your own AI brain file for that unit during the game and use the case option to supply different actions for the unit to carry out if something is found to be true. Lets look at a practical example. In this example we have 2 tanks, one tank for team 1 and one tank for team 2. Lets assume all out vars for teams have been setup already and we are just dealing with the memory cells here. Now, we want team 2's tank to explode if team 1s tank reaches a waypoint. We will use memory cells to handle this. Our tank objects will be called eve_tank1 and eve_tank2. The clever bit here is we will modify tank 2's memory cells using tank 1 which will result in tank 2 exploding. Tank 1's Brain file State blowupteam2tank; if (IsWithin(eve_tank1,epa_navpoint1l,radius) == true) then SetMemoryInteger(eve_tank2,1,2); endstate; What we have done here is check to see if Tank1 has reached navpoint 1 and if it has we change tank 2s memory cell 1 to a value of 2. Tank 2's Brain file. We place the following line in the function init section or set it up from within the editor as described above. SetMemoryInteger(me,1,1) State doIblowupnow; code Switch (GetMemoryInteger(me,1)) case 1: endcase; orderdie; endstate; Tank 2's brain file simply checks if memory cell 1 has a value of 1 or 2 and then decides what to do about it. If the value is still 1, it does nothing. If the value is 2 it will explode. The value is changed by tank1's brain file once it reaches navpoint 1. So you can see how handy memory cells can be and you can see how you can set memory cells from other units for the unit your dealing with. These commands only work inside AI Brain files but they offer a way around the var used in commands problem. "If/then/else" statements have to be used if the memory cell commands do not work, as is the case in custom gametypes. This can make for a very long winded scripted. In theory you could use one master control units memory cells to control all AI units on a map. By changing that one units memory cells and using the GetMemoryInteger(unit,cellnumber) from within every other AI units brain file you could check the settings of the command unit and have your entire force react accordingly. The advantage would be you could use the same script for all units except the command unit. If I quickly draw up a table of actions for a command unit and set the values in the memory cells, then we could build up a very complex system of communication between the AI units on the command units team. For instance. The command units memory cells would be setup like this to start with. Cell 1 = 1, here we check for the enemy presence near by. 1 = no enemy is present 2 = enemy has been spotted Cell 2 = 1, here we check if we are attacked 1 means we have not been attacked for 5 minutes 2 means we have been attacked in the last 5 minutes Cell 3 = 1, here we check our teams orders 1 continue on your patrols 2 go to last unit to be attacked 3 watch out for enemy units and engage when spotted Cell 4 = 1, here we count how many units we have left each unit reports in and modifies this cell. We will assume a value of 5 means no loses and a value of 2 means heavy loses Cell 5 = 1 here we attack or retreat 1 = all units accounted for by cell 4, time to attack 2 = we have suffered heavy losses time to retreat. Now, as each AI unit uses the GetMemoryInteger(commandunit,cellnumber) to receive its orders via the case option of the switch command or changes the command units memory cells using the SetMemoryInteger(commandunit,index,value) which then effects the orders of all over units reading that cell. We can see how the value of the command units memory cells can determine the actions of the rest of our forces. This is a slightly more complex way of explaining memory cells but it clearly shows how easily you can use them to achieve some fantastic results. Most people will probably only use them to control a single unit but I wanted the readers of this tutorial to understand just how much could be done with memory cells. The commands you need to look in the orders doc from the devteam are. GetMemoryInteger SetMemoryInteger And learn out to use the Switch command and case options. Then you can do anything you want with memory cells.
|