Q: I need some code that will play a specific animation when certain events occur.
A: Here's some code that changes the animation when you press "S", "W" or "R" :

var anim_mode = 1; // default = "stand"

action anim_test // use a model with "stand", "walk", "run" animation frames
{
while (1)
{
if (key_s == on)
{
anim_mode = 1; // stand
}
if (key_w == on)
{
anim_mode = 2; // walk
}
if (key_r == on)
{
anim_mode = 3; // run
}
if (anim_mode == 1) // stand animation
{
ent_cycle("stand", my.skill20);
my.skill20 += 2 * time; // animation speed
my.skill20 %= 100;
}
if (anim_mode == 2) // walk animation
{
ent_cycle("walk", my.skill20);
my.skill20 += 3 * time; // animation speed
my.skill20 %= 100;
}
if (anim_mode == 3) // run animation
{
ent_cycle("run", my.skill20);
my.skill20 += 5 * time; // animation speed
my.skill20 %= 100;
}
wait (1);
}
}
Q: Why do you put this line in some of your functions? while (player == null) {wait (1);}
A: The functions should look like this:

function kill_player()
{
while (player == null) {wait (1);}
.........
player._health = 0;
}

The while loop will keep this function waiting until the player entity is created because we want to change some of its properties. We can't be sure what entity is created / loaded first.
Q: Can someone tell me how can I use Q2 models in A5? When I try to use them they animate the whole sequence.
A: Make sure that the animation frames include at least some of these animations: "walk", "run", "jump", "death", "attack" named like this: walk01...walk15 and so on. Copy the model to your game folder, place it in your level and attach it the actor_ai_one action. Now you've got yourself an enemy that will chase the player, trying to kill it!

Q: I would like to link 3 models under one action, to make a vehicle kinda like those in HALO.
A: Here's some code for a tank from one of my projects:

string challenger_turret = <chturret.mdl>;
string challenger_barrel = <chbarrel.mdl>;

function attach_challenger_barrel();
function attach_challenger_turret();

action challenger
{
ch_turret = ent_create(challenger_turret, nullvector, attach_challenger_turret);
ch_barrel = ent_create(challenger_barrel, nullvector, attach_challenger_barrel);
while (1)
{
...........
wait (1);
}
}

function attach_challenger_barrel()
{
my.metal = on;
while(you) // as long as the creator exists
{
vec_set(my.x,you.x);
vec_set(my.pan, you.pan);
vec_set(my.tilt, you.tilt);
my.frame = you.frame;
my.next_frame = you.next_frame;
wait(1);
}
ent_remove(my);
}

function attach_challenger_turret()
{
my.metal = on;
while(you) // as long as the creator exists
{
vec_set(my.x,you.x);
vec_set(my.pan,you.pan);
my.frame = you.frame;
my.next_frame = you.next_frame;
wait(1);
}
ent_remove(my);
}

Q: How do I create a switch that changes the color of a light source?
A: Place two entities in your level and attach them the light_source and light_switch actions. The code below changes the color from red to green and back when you click the switch with the mouse:

var red = 200;
var green = 0;
var blue = 0;

entity* light_bulb;

function change_color();

action light_source
{
light_bulb = me;
my.lightrange = 200;
while (1)
{
my.lightred = red;
my.lightgreen = green;
my.lightblue = blue;
wait (1);
}
}

action light_switch // click the switch with the mouse to change the light color
{
my.enable_click = on;
my.event = change_color;
}

function change_color()
{
green = (red == 200) * 200;
red = (green == 0) * 200;
}

Q: Are F2 and F3 hardcoded to quicksave and quickload? I would like to modify them...
A: Yes, they are hard coded but you can modify them. Put these lines in main:

on_f2 = null;
on_f3 = null;

and then use something like this:

on_f2 = my_quick_save; // your functions
on_f3 = my_quick_load;

Q: I've been working on an arena style shooter similar to UT but I can't get the weapons to respawn!
A: Here's a code sample that uses one of the template weapons:

string weapon1_mdl = <rocket.mdl>;

var weapon_exists = 0; // will be set to 1 if the weapon exists at the spawning point

action create_weapon
{
my.passable = on;
while (1)
{
if (vec_dist (my.x, player.x) < 200) // if the player has picked up the gun - play with this value
{
weapon_exists = 0; // we can create a new gun
}
sleep (10); // wait 10 seconds before creating a new weapon
if (weapon_exists == 0) // if the previous weapon was picked up
{
vec_set (temp, my.pos);
temp.z += 50; // create the weapon 50 quants above the spawning point
ent_create (weapon1_mdl, temp, flashgun);
weapon_exists = 1;
}
}
}

Q: I have scaled my player down to 25%, trying to get a big world look and feel. Now I want to move the camera upwards - how can I do that?
A: If your game has a 3rd person player, put this line in main:

camera_dist.z -= 100; // play with this value

Q: Is there any script to open a door with a mouse click instead of spacebar?
A: The code inside the new templates will open the doors when you click them.

Q: Does anyone know a way to disable the z axis movement in Steroidz (Aum10)?
A: Comment this line in action players_ship:

// player.tilt += 0.5 * (key_cuu - key_cud) * time;

Due to an engine bug that was fixed, the asteroids don't show up with newer engine versions. To fix the code, place this line before every ent_move instruction that appears in steroidz.wdl:

move_mode = ignore_passable;