Setting up Enemy AI


Tutorial Info


Tutorial
1 – Introduction
Enemy AI is rather simple with the MaxFX engine. It does all of the needed node-work for you when you initialize your map, but for special circumstances, that’s where the work on your part comes in. For this tutorial, you do need to have some understanding of the message system.

2 – Placing Your Enemies
To place an enemy, you need to be in model mode (F3) and then press ‘n’. Choose ‘enemy’ from the list and click ‘ok’. Now choose whichever enemy model you like, and then click ‘ok’. You now have placed your enemy.

3 – Setting Up Your Enemy
Now you need to tell your enemy how to act. He can just stand there and let himself be shot at, or shoot back at you, among other options. In transform mode, select your enemy, and press ‘4’, then choose ‘messages’. Before entering your message, you should decide what you want your enemy to do. You can use many different messages to set up your enemy (namely those that start with “C_”), but for this tutorial we’re only going to focus on the C_SetStateMachine(); message. From the list of possible states below, you can choose what you want your enemy to do.
Crouch
CrouchAndShoot
CrouchAndShootStatic
CrouchWaitAndShoot
CrouchWaitAndShootStatic
Idle
IdleUntilEnemySeen
IdleUntilHit
MeleeCombat
MercCombat
MercCombatDefensive
MobsterCombat
MobsterCombatDefensive
Nonreactive
RunWalkAndShoot
SingleJump
SingleDodgeLeft
SingleDodgeRight
SingleDodgeForward
SingleDodgeBackward
SingleShootDodgeLeft
SingleShootDodgeRight
SingleShootDodgeForward
SingleShootDodgeBackward
StandAndIdle
StandAndShoot
StandAndShootStatic
WalkAndShoot
WalkStopAndShoot
SingleShootAccurately
Delay500ms
Delay1s
Delay2s
Now click the Startup tab and choose ‘add’ for the top section. We’re going to make this guy be able to do combat with you, so enter “this->C_SetStateMachine(mobstercombat);” There you go, now once you compile your map in a special way, you can have enemies do whatever you want.

4 – Compiling Your AI
Now in order to get Max Payne to create the AI node network for you, you have to do some extra editing of the levels.txt and menu.txt files. The extra lines you need to edit are as follows:
In levels.txt,
EnableAI = FALSE change to TRUE

In menu.txt
[Message] String = "maxpayne_gamemode->gm_init( basic_room );"; change to GM_InitAndCalcAI( basic_room);”;
Now compile the mod and run it in Max Payne. Now make sure you don’t use GM_InitAndCalcAI unless the level geometry is different since you last ran it. It is time consuming, up to an hour for very large, open levels.

5 – Conclusion
So now that you can create AI for your maps, get working on learning the intricacies between the different messages and states available to you. Try and get an enemy to run around a room and then shoot you when he sees you. Or try to have an enemy stand in a doorway and then dodge out of your range when Max is seen. Good luck.