I'm writting this tutorial with the assumption that you already know how to build rooms, manipulate the polygons, and a lot of the other basic MaxED functions. If not you'll probably want to check out some other tutorials first.
The FSM may seem complex at first but once you get a hang of it its a breeze. Not only that, you begin to realize just how dynamic Max Payne really is. Here are some example scripts and I'll explain what each part of the script does.
Note: These pages might take a bit to load on dialup connections. There are a lot of pictures ;)
The Syntax this->a_play3dsound(breakable, glass_shatter, "");
This Refers to the object that the FSM is attached to(the one you're editing at that moment.)
-> This tells the engine that you're done adding objects for it to interact with and you now want to type the command.
a_play3dsound() The command that we're using. It does what it sounds like and plays a 3D sound for the specified object(s). In this case, this.
breakable, glass_shatter, "" These attributes go in the paranthesis for the command a_play3dsound. Breakable refers to the sound library 'breakable.txt', glass_shatter is the sound to be played from the text. The double quotes at the end are used for defining which bone the sound plays from. Since we're not referring to a character we leave it empty.
You can also use an object to refer to another object. If an object is in the same room as the first one you can use:
This will get the program to look for item2 in room2.
Things to note
One of the nice features in MaxED is that it will show all of the items in the room that you're currently pointing to. It shows them in the right box in the FSM Messages menu. Good that you don't have to remember the names of everything ;)
The FSM is not case sensitive.
The command part of the script must be the same as the one specified in the help.htm file that comes with MaxED and the attributes must match the command.
Attributes that don't apply are symbolized by empty quotes ""
Every line must end with a semicolon.
Category names must match with the definement in the corrosponding *.txt(Glass_Shatter isn't the same name as the *.wav filename that it uses.)
You can refer to the player by using player->
FSM commands are valid in the game console
Now that we have a basic understanding its time to do something fun =) For our first FSM trick we're going to make a breakable televison. First, make a true room and make yourself something that looks something like a TV. When you're done, copy and paste the TV and tie both of them to your room. You'll probably want to put a broken glass looking texture for the screen of the television. I did this by making another polygon, sizing it to the screen, and placing the broken computer screen texture from the Official library on it. Also added a light grey alpha layer to it to give a nice transparent look.
Make both of the TVs dynamic by selecting each in Transform Mode(F5) and pushing 'D' Say yes to making it dynamic and yes to keeping the lightmaps. Rename one TV to TV_Normal and the other to TV_Broken. Turn on the BulletCollides and DynamicCollisions flags for each.
Now, select the non-broken one and push '4' to get to the FSM menu and push the 'Messages' button. We want the TV to break when its shot so we need to edit the category for DO_BulletCollides. Push the Add button under 'Send Before'. For each of the lines I type below you'll need to add a new line in the same section.
DO_Hide(); tells the object to hide from view(which also makes it passable by all means.)
PS_StartEffect(); initiates the particle system and plays the effect in parathesis(again the double quotes are used for a bone.)
parent::TV_Broken->DO_Hide(false); tells the soon-to-be hidden 2nd TV to show itself.
Now accept all changes and select the broken TV. Goto its FSM menu the same way but this time select the Startup tab. Enter this:
this->do_hide(true);
This makes the 2nd TV hidden as it's initial state. All we have to do now is to drop the TVs on top of each other and its all set.
If you compiled your map to check it out you might be wondering why the particle effect doesn't show or only shows partially. It seems that the particle effect will emminate from the object's center. I've heard from a pretty reliable source that it depends on the pivot point. If this is the case then I must be doing something horribly
wrong. No matter where I put that sucker the particles stay where they are. This is how I worked around it:
Create a trigger of any type, the size doesn't matter, and name it Shatter. Place it near the face of the TV and center it
across the face.
Now, go into your TV_Normal FSM Messages and edit this->ps_starteffect(glass_shatter_window_50x50cm, "");
to parent::Shatter->ps_starteffect(glass_shatter_window_50x50cm, ""); Next edit your trigger's FSM. Under the
startup tab and add this->t_enable(false); We do this last bit so that the trigger isn't affected by anything but
the TV being shot.
Just for Fun
Look at the particles.txt then load up maxpayne in developer mode. See if you can't get confetti to spray from max's head bone.
Make a few misc objects in a room and try to get them to play sounds and spray particles with the console.