Q: I'm using the stationary-gun code from Aum30. How do I control the weapon with the mouse (not with the arrow keys)?
A: Replace action sweapon with the one below; use Ctrl or the left mouse button to fire.

action sweapon
{
     while (player == null) {wait (1);}
     player._health = 100; // make sure that player._health > 0 at game start
     my.passable = on;
     while (player._health > 0) // fire only if the player is alive
     {
          if (player_immobile == 0) // if the player can move
          {
               while (vec_dist (player.x, my.x) > 100) {wait (1);} // wait until it has come close enough
               vec_set (players_speeds, strength); // store player's speed
               vec_set (players_angles, astrength); // and angular speed
               vec_set (strength, nullvector); // the player can't move from now on
               vec_set (astrength, nullvector); // nor rotate from now on
               player_immobile = 1; // can't move
               while (key_any == 1) {wait (1);}
               player.pan = 0;
               player.tilt = 0;
          }
          else // player_immobile == 1
          {
               player.x = -1250;
               player.y = -728;
               if ((mouse_force.y > 0) && (player.tilt < 30))
               {
                    player.tilt += 0.5 * time;
               }
               if ((mouse_force.y < 0) && (player.tilt > -10))
               {
                    player.tilt -= 0.5 * time;
               }
               if ((mouse_force.x > 0) && (player.pan > -30))
               {
                    player.pan -= 1 * time;
               }
               if ((mouse_force.x < 0) && (player.pan < 30))
               {
                    player.pan += 1 * time;
               }
               my.pan = player.pan;
               my.tilt = player.tilt;
               if ((key_ctrl == 1) || (mouse_left == 1))
               {
                    while (key_ctrl == 1) {wait (1);} // disable auto fire
                    while (mouse_left == 1) {wait (1);} // disable auto fire
                    vec_for_vertex (rocket_coords, my, 190); // get the vertex coords for the rocket
                    snd_play (fire_wav, 100, 0);
                    ent_create (rocket_mdl, rocket_coords, move_rocket);
               }
               if (key_space == 1)
               {
                    vec_set (strength, players_speeds); // the player can move from now on
                    vec_set (astrength, players_angles); // and can rotate
                    player.pan = 0;
                    player.tilt = 0; // restore pan and tilt
                    player_immobile = 0; // can move
                    while (vec_dist (player.x, my.x) < 200) {wait (1);} // allow the player to get away
               }
          }
          wait (1);
     }
}
 

Q: How could I edit your Perfect AI code? I want the player to come as close to an enemy as he wants; as long as he is hidden in the shadows, they won't see him.
A: Click here to get the modified ai5.wdl file and a test level. Don't forget to set proper alert_dist values for the enemies.
 

Q: I use your minimap from Aum27, but I'd like it to rotate when the player changes its pan angle. Can you help?
A: Replace the starter init_topcam function with the one below:

starter init_topcam()
{
     while (player == null) {wait (1);}
     while (1)
     {
          if (key_t == 1)
          {
               while (key_t == 1) {wait (1);}
               if (top_view.visible == on)
               {
                    top_view.visible = off;
               }
               else
               {
                    top_view.visible = on;
               }
          }
          top_view.x = player.x;
          top_view.y = player.y;
          top_view.z = 1000; // play with this value
          top_view.pan = player.pan;
          wait (1);
     }
}
 

Q: I've just started the code for my player. By default I want to have it playing a "stand" animation; when you press a specific key, I'd like it to play another animation, but only once through the cycle of frames.
A: Use the code below:

action my_player
{
     while (1)
     {
          if (key_any == 0) // default animation
          {
               ent_cycle("stand", my.skill46);
               my.skill46 += 4 * time;
               my.skill46 %= 100;
          }
          else // the player is pressing one of the keys
          {
               if (key_a == 1) // if the "A" key is pressed
               {
                    while (key_a == 1) {wait (1);} // wait until "A" is released
                    my.skill46 = 0;
                    while (my.skill46 < 100)
                    {
                         ent_cycle("attack", my.skill46);
                         my.skill46 += 5 * time;
                         wait (1);
                    }
               }
               if (key_b == 1) // do something else
               {
                    // when the player presses the "B" key
                    wait (1);
               }
          }
          wait (1);
     }
}

 
Q: I would like to display something like a one way portal that allows the player to teleport to another part of the level. Is it possible?
A: Attach action portal_eye to any entity and set its position and angles until it fits your needs. Attach action portal_sprite to the sprite that will display the "portal". Read the article in Aum15 if you need more info about teleporting.

view my_portal
{
     pos_x = 0;
     pos_y = 0;
     size_x = 128; // size of the view on x and y
     size_y = 64;
     layer = 5;
     flags = visible;
}

action portal_eye
{
     my.invisible = on;
     my.passable = on;
     my_portal.x = my.x;
     my_portal.y = my.y;
     my_portal.x = my.x;
     my_portal.pan = my.pan;
     my_portal.tilt = my.tilt;
     my_portal.roll = my.roll;
}

action portal_sprite // 128 x 64 pixels
{
     my.oriented = on;
     my.passable = on;
     my_portal.bmap = bmap_for_entity (my, 0);
}
 

Q: Could you show me a simple event_trigger example?
A: Take a look at the code below:

function hide_entity()
{
     if ((event_type == event_trigger) && (you == player))
     {
          my.invisible = on;
     }
}

action my_trigger
{
     my.enable_trigger = on;
     my.trigger_range = 200; // come closer than 200 quants to remove the entity
     my.event = hide_entity;
}
 

Q: Is there any script that corrects position of the pistol if you change camera to 3rd person? The pistol used in A5's templates has a weird position...
A: The weapons used in the A5 templates share the same x, y and z coordinates with the player. However, you can change the origin of the weapon models in Med until their position looks good in 3rd person view too.

 
Q: I was wondering how you can get your guy to start with a weapon...
A: Place a weapon model anywhere in the level and attach it the desired weapon action.  Add two lines of code to that action.

ACTION logangun
{
     while (player == null) {wait (1);}
     vec_set (player.pos, my.pos);
     MY.__ROTATE = ON; // gun rotates before being picked up
     MY.__REPEAT = ON; // repeats (Auto-fire)
     MY.__BOB = ON;   // 'bobs' when the player moves
     MY._OFFS_X = 42;   // x,y,z pos of the gun
     MY._OFFS_Y = 20;
     MY._OFFS_Z = 7;
     MY._AMMOTYPE = 0.0;   // type of ammo '.' rounds in gun
             //(0 means no ammo needed)

     if(MY._WEAPONNUMBER == 0) { MY._WEAPONNUMBER = 3; }   // weapon number (press 3 to equip)
     MY._BULLETSPEED = 1000.25; // bulletspeed '.' recoil
     MY._FIRETIME = 5;          // time to cycle (reload)

     // SHOOT damage (immediate)
     // + flash at hit point
     // + smoke at hit point
     // + sparks at hit point
     // 50 points of damage per shot
     MY._FIREMODE = DAMAGE_SHOOT + HIT_FLASH + HIT_SMOKE + HIT_SPARKS + FIRE_PARTICLE + 0.50;
     gun();
}
 

Q: I want to output to a text file and am looking for a tabspace character; \t or 'tabspace' do not work, although line feed (\n) works! Help me!
A: Here's a workaround:

var file_handle;

string tab_str;

function write_text()
{
     file_handle = file_open_write ("test.txt");
     file_str_write (file_handle, "first column");
     file_str_write (file_handle, tab_str); // tab
     file_str_write (file_handle, "second column");
     file_str_write (file_handle, tab_str); // tab
     file_str_write (file_handle, "third column");
     file_close (file_handle);
}

on_w write_text; // press "W" to write the text

starter init_string()
{
     str_cpy (tab_str, "    "); // 4 spaces, change this value
}