Questions from the forum

Top  Previous  Next

Q: I use the access code from Aum33 in my game and it works ok. What should I change in order to make the door move upwards?

A: Use the following improved snippet:

 

//////////////////////////////////////////////////////////////////////////////////

// place dialsmall.pcx in your level and attach it the "dial_small" action

// place a door in your level and attach it the "new_door" action

//////////////////////////////////////////////////////////////////////////////////

 

bmap dialpad_pcx = <dialpad.pcx>;

 

bmap one_pcx = <one.pcx>;

bmap two_pcx = <two.pcx>;

bmap three_pcx = <three.pcx>;

bmap four_pcx = <four.pcx>;

bmap five_pcx = <five.pcx>;

bmap six_pcx = <six.pcx>;

bmap seven_pcx = <seven.pcx>;

bmap eight_pcx = <eight.pcx>;

bmap nine_pcx = <nine.pcx>;

bmap zero_pcx = <zero.pcx>;

bmap asterisk_pcx = <asterisk.pcx>;

 

var number_of_digits;

 

string password_str = "6239"; // our password

string guess_str = "    ";

string temp_str;

 

entity* locked_door;

 

sound dial_wav = <dial.wav>;

sound error_wav = <error.wav>;

sound success_wav = <success.wav>;

 

function check_code(button);

function show_dialpad();

 

panel dialpad_pan

{

       bmap = dialpad_pcx;

       pos_x = 0;

       pos_y = 0;

       layer = 10;

       button = 143, 8, one_pcx, one_pcx, one_pcx, check_code, null, null;

       button = 270, 8, two_pcx, two_pcx, two_pcx, check_code, null, null;

       button = 398, 8, three_pcx, three_pcx, three_pcx, check_code, null, null;

       button = 143, 128, four_pcx, four_pcx, four_pcx, check_code, null, null;

       button = 272, 128, five_pcx, five_pcx, five_pcx, check_code, null, null;

       button = 397, 129, six_pcx, six_pcx, six_pcx, check_code, null, null;

       button = 144, 248, seven_pcx, seven_pcx, seven_pcx, check_code, null, null;

       button = 273, 249, eight_pcx, eight_pcx, eight_pcx, check_code, null, null;

       button = 397, 250, nine_pcx, nine_pcx, nine_pcx, check_code, null, null;

       button = 146, 368, zero_pcx, zero_pcx, zero_pcx, check_code, null, null;

       button = 272, 370, asterisk_pcx, asterisk_pcx, asterisk_pcx, check_code, null, null;

       flags = overlay, refresh;

}

 

action dial_small

{

       my.ambient = -40;

       my.oriented = on;

       my.passable = on;

       my.enable_click = on;

       my.event = show_dialpad;

}

 

function show_dialpad()

{

       number_of_digits = 0;

       str_cpy (guess_str, ""); // reset the string

       dialpad_pan.visible = on;

}

 

action new_door

{

       locked_door = me;

}

 

function check_code(button)

{

       number_of_digits += 1;

       snd_play (dial_wav, 30, 0);

       if (button <= 10) // pressed one of the 1...0 buttons?

       {

               str_for_num(temp_str, button); // convert the button number to a string

               if (str_len(temp_str) == 2) // the player has pressed 0 (10, in fact)

               {

                       str_clip(temp_str, 1); // so we remove the first character ("10" turns into "0")

               }

               str_cat(guess_str, temp_str); // add the resulting string to guess_str

       }

       if ((button == 11) || (number_of_digits > 4))

       {

               while (mouse_left == 1) {wait (1);}

               sleep (0.5);

               snd_play (error_wav, 70, 0);

               dialpad_pan.visible = off;

       }

}

 

starter compare_strings()

{

       while (1)

       {

               if (str_cmp (password_str, guess_str) == 1)

               {

                       str_cpy (guess_str, ""); // reset the string, don't allow the "if" branch to run several times

                       snd_play (success_wav, 20, 0);

                       dialpad_pan.visible = off;

                       while (locked_door.z < 150) // play with 150

                       {        

                            locked_door.z += 2 * time; // 2 = speed

                               wait (1);

                       }

                       locked_door.z = 150; // play with 150

               }

               wait (1);

       }

}

 

 

Q: I want to use your exequte function from Aum37 by attaching it to a clickable entity. How do I do that?

A: Use this example:

 

var success = 0;

 

dllfunction Exequte(x);

 

function buy_now();

 

text error_txt

{

       pos_x = 200;

       pos_y = 200;

       layer = 30;

       font = _a4font;

       string = "Error while trying to run the command!";

}

 

function buy_now()

{

       success = Exequte("C:\\Program Files\\Internet Explorer\\iexplore.exe www.randombyte.com");

       if (success <= 31) // WinExec failed?

       {

               error_txt.visible = on; // show an error message

       }

       dll_close (dll_handle);

}

 

action clickable_entity

{

   my.enable_click = on; // the entity is sensitive to clicking

   my.event = buy_now;

}

 

 

Q: I'm using your camera code from Aum2's faq. When the player turns, the camera turns with the same speed, but I want the camera to turn slower. Can you help me?

A: Use the following example:

 

var camera_dist = 300; // play with this value

 

view topview // set for 800x600 pixels

{

       pos_x = 0;

       pos_y = 0;

       size_x = 800;

       size_y = 600;

       layer = 25;

       flags = visible;

}

 

starter top_view

{

       camera.visible = off; // disable the default view

       while (player == null) {wait (1);}

       topview.tilt = -90; // look down

       while (1)

       {

               vec_set (topview.x, player.x);

               topview.z += camera_dist;

               topview.pan -= ang(topview.pan - player.pan) * 0.1 * time; // 0.1 = turning speed

               wait (1);

       }

}

 

 

Q: When I run my game after building the wmb, the splash screen stays there instead of my game starting.

A: Your script contains an error that doesn't allow the game to continue. Disable the splash screen temporarily (comment the “your_splash_screen_panel.visible = on;”) line until you find and fix the problem.

 

 

Q: Your serious grass script from Aum50 is great, but is it also possible to recreate it as a action and assign it to an entity? For example, if the player comes close to a entity, the entity random creates the grass models.

A: Use the following snippet:

 

// make sure to have a big nexus value set (nexus > 50 for 500 grass models, and so on)

var number_of_bushes = 0; // counts the number of grass models that are placed in the level

 

string grass1_mdl = <grass1.mdl>;

string grass2_mdl = <grass2.mdl>;

 

function place_grass();

 

action grass_generator

{

       while (player == null) {wait (1);} // wait until the player is created

       while (vec_dist (player.x, my.x) > 500) {wait (1);} // wait until the player has come closer than 500 quants

       while (number_of_bushes < 500) // create 500 models around the grass_generator entity

       {

               vec_set (temp.x, my.x);

               temp.x += 500 - random(1000);

               vec_set (temp.y, my.y);

               temp.y += 500 - random(1000);

               temp.z = my.z + 200;

               if (random(1) > 0.1)

               {

                       ent_create (grass1_mdl, temp.x, place_grass);

               }

               else

               {

                       ent_create (grass2_mdl, temp.x, place_grass);

               }

               number_of_bushes += 1;

       }

}

 

function place_grass()

{

       my.passable = on;

       my.transparent = on;

       my.pan = random(360);

       vec_set (temp, my.pos);

       temp.z -= 3000;

       trace_mode = ignore_me + ignore_sprites + ignore_models + use_box;

       my.z -= trace (my.pos, temp); // place the grass model on the ground

}

 

 

Q: I have a question concerning your Aum21 "Thanks" game. How can I shoot a rocket even if there is another one in the level already?

A: Use the modified script:

 

var video_mode = 7; // 800x600

var video_depth = 16; // 16 bit mode

var rocket_coords;

var player_speed;

var erocket_speed; // rocket speed -> enemy rocket

var turret_offset;

var barrel_offset;

var enemy_speed;

var fall_speed = 0.9;

var engine_handle = 0; // sound handle for the tank

var turret_handle = 0; // sound handle for the turret

 

sound tank_snd = <tankrun.wav>;

sound tankexplo_snd = <tankexplo.wav>;

sound turret_snd = <turret.wav>;

sound tankrocket_snd = <tankrocket.wav>;

sound beep_sound = <beep.wav>;

 

bmap tanksmoke_pcx = <tanksmoke.pcx>;

 

string level1_wmb = <level1.wmb>;

string challenger_turret = <chturret.mdl>;

string challenger_barrel = <chbarrel.mdl>;

string tank_rocket = <tankrock.mdl>;

string explosion_pcx = <explo+6.pcx>;

 

define shield skill20;

 

function attach_player_barrel();

function attach_player_turret();

function player_rocket();

function explode_rocket();

function tank_damaged();

function animate_explosion();

function tank_smoke();

function fade_smoke();

function enemy_rocket();

 

function main()

{

       clip_size = 0; // show all the triangles for all the models

       on_d = null; // disable the standard "debug" key

       level_load (level1_wmb);

}        

 

function attach_player_barrel()

{

       proc_late(); // prevent shaking

       my.passable = on;

       my.metal = on;

       while(you) // as long as the creator exists

       {

               vec_set(my.x,you.x);

               my.pan = you.pan + turret_offset;

               my.tilt = you.tilt + barrel_offset;

                 my.frame = you.frame;

                 my.next_frame = you.next_frame;

               vec_for_vertex(rocket_coords, my, 33); // vertex for player's rocket

               if (mouse_left == on && player.shield > 0)

               // if we press the LMB and the tank isn't destroyed

               {

                       while (mouse_left == on) {wait (1);}

                       ent_create (tank_rocket, rocket_coords, player_rocket);

                       snd_play (tankrocket_snd, 100, 0);

               }

                 wait(1);

       }

       ent_remove(my);

}

 

function attach_player_turret()

{

       proc_late(); // prevent shaking

       my.passable = on;

       my.metal = on;

       while(you) // as long as the creator exists

       {

               vec_set(my.x, you.x);

               my.pan = you.pan + turret_offset;

                 my.frame = you.frame;

                 my.next_frame = you.next_frame;

                 wait(1);

       }

       ent_remove(my);

}

 

action player_tank

{

       player = me;

       my.enable_impact = on;

       my.enable_entity = on;

       my.event = tank_damaged;

       ent_create(challenger_turret, nullvector, attach_player_turret);

       ent_create(challenger_barrel, nullvector, attach_player_barrel);

       my.shield = 250; // 250 shield points for player's tank

       while (my.shield > 0) // the 10th hit will destroy player's tank

       {

               camera.pan = my.pan;

               camera.x = my.x - 500 * cos (my.pan); // the camera is placed 500 quants behind the tank

               camera.y = my.y - 500 * sin (my.pan);

               camera.z = my.z + 300; // and 300 quants above the tank

               camera.tilt = -20; // the camera looks down

               if (mouse_force.x != 0) // if we move the mouse on x

               {

                       if (turret_handle == 0)

                       {

                               turret_handle = snd_play (turret_snd, 70, 0);        

                       }

                       turret_offset -= 2 * mouse_force.x * time;

               }

               else

               {

                       turret_handle = 0;

               }

               if (mouse_force.y != 0) // if we move the mouse on y

               {

                       barrel_offset += 2 * mouse_force.y * time;

               }

               if (player_speed.x != 0) // if we are moving the tank

               {

                       my.pan -= 0.1 * (key_d - key_a) * player_speed.x * time;

                       if (engine_handle == 0) // if the engine sound isn't playing

                       {

                               engine_handle = snd_loop (tank_snd, 50, 0);

                               snd_tune (engine_handle, 25, 100, 0); // play the sound at its original frequency (100%)

                               my.skill10 = 100;

                       }

               }

               else

               {

                       my.skill10 -= 5 * time; // decrease the frequency

                       snd_tune (engine_handle, 25, my.skill10, 0); // using snd_tune

                       if (my.skill10 < 20) // if we go below 20% of the original frequency

                       {

                               snd_stop (engine_handle); // stop the engine sound

                               engine_handle = 0;

                       }

               }

               player_speed.x = 1.5 * (key_w - key_s) * time + max (1 - time * 0.15, 0) * player_speed.x;

               player_speed.y = 0;

               player_speed.z = 0;

               move_mode = ignore_you + ignore_passable;        

               ent_move(player_speed, nullvector);

               wait (1);

       }

}        

       

function player_rocket()

{

       var procket_speed; // rocket speed -> player's rocket

       wait (1);

       my.skill40 = 1; // it is a rocket

       my.pan = you.pan;

       my.tilt = you.tilt;

       my.enable_impact = on;

       my.enable_block = on;

       my.enable_entity = on;

       my.event = explode_rocket;

       my.skill5 = 0; // used for vertical movement

       procket_speed.x = 100;

       procket_speed.y = 0;

       procket_speed.z = 0;

       procket_speed *= time;

       while (my != null)

       {

               my.skill5 += time;

               if (my.skill5 > 20)

               {

                       procket_speed.z -= fall_speed * time;

               }

               move_mode = ignore_you + ignore_passable; // ignores the barrel -> can't collide with it

               ent_move (procket_speed, nullvector);

               wait (1);

       }

}

 

function explode_rocket()

{

       wait (1);

       exclusive_global;

       // the following piece of code replaces A5's ent_playsound with a linear function

       my.skill10 = vec_dist (player.x, my.x);

       if (my.skill10 < 1000) {my.skill10 = 1000;} // all sounds below 1000 quants will be played with maximal volume

       my.skill10 = 100000 / my.skill10; // bigger distance -> lower volume;

       snd_play (tankexplo_snd, my.skill10, 0);

       vec_set (temp, my.pos);

       temp.z += 50; // create the explosion sprite a little higher

       ent_create(explosion_pcx, temp, animate_explosion);

       ent_remove (me);

}

 

function animate_explosion()

{

       wait (1);

       my.passable = on;

       my.ambient = 100;

       while (my.frame < 7)

       {

               my.frame += 1 * time;

               wait (1);

       }

       ent_remove (me);

}

 

function tank_damaged()

{

       if (you.skill40 != 1) {return;} // it wasn't hit by a rocket (maybe the 2 tanks collided)

       wait (1);

       my.shield -= 25;

       if (my.shield <= 0) // player's tank was hit 10 times or the enemy tank was hit twice

       {

               while (1)

               {

                       effect (tank_smoke, 5, my.pos, normal);

                       sleep (0.2);

               }

       }

}

 

function tank_smoke()

{

       temp.x = random(2) - 1;

       temp.y = random(2) - 1;

       temp.z = random(2) + 1;

       vec_add (my.vel_x, temp);

       my.alpha = 30 + random(30);

       my.bmap = tanksmoke_pcx;

       my.size = 100;        

       my.flare = on;

       my.move = on;

       my.lifespan = 100;

       my.function = fade_smoke;

}

 

function fade_smoke()

{

       my.alpha -= 0.5 * time;

       if (my.alpha < 0)

       {

               my.lifespan = 0;

       }

}

 

// enemy - related stuff from here on

action enemy_tank

{

       while (player == null) {wait (1);}

       my.ambient -= 30; // make the skin darker - it is too bright imho

       my.enable_impact = on;

       my.enable_entity = on;

       my.event = tank_damaged;

       my.shield = 50; // 2 rockets will destroy the enemy tank

       while (my.shield > 0)

       {

               vec_set (temp.x, player.x);

               vec_sub (temp.x, my.x);

               vec_to_angle (my.skill4, temp); // turn towards the player        

               my.skill5 = 0; // tilt = 0

               if (abs(my.skill4 - my.pan) < 1)

               {

                       vec_for_vertex(my.skill1, my, 41); // vertex for the enemy rocket

                       ent_create (tank_rocket, my.skill1, enemy_rocket);

                       sleep (3);

               }

               else

               {

                       my.pan += ang(my.skill4 - my.pan) * 0.03 * time; // smooth rotation code

                       enemy_speed.x = 5 * time;

                       enemy_speed.y = 0;

                       enemy_speed.z = 0;

                       move_mode = ignore_you + ignore_passable;        

                       ent_move(enemy_speed, nullvector);

               }                

               wait (1);

       }

}

 

function enemy_rocket()

{

       wait (1);

       my.skill40 = 1; // it is a rocket

       my.pan = you.pan;

       my.tilt = you.tilt;

       my.enable_impact = on;

       my.enable_block = on;

       my.enable_entity = on;

       my.event = explode_rocket;

       erocket_speed.x = 100;

       erocket_speed.y = 0;

       erocket_speed.z = 0;

       erocket_speed *= time;

       while (my != null)

       {

               move_mode = ignore_you + ignore_passable; // ignores the barrel -> can't collide with it

               ent_move (erocket_speed, nullvector);

               wait (1);

       }

}

 

 

Q: I have a large sky cube because I want high detail, but I have noticed that it consumes a lot of memory. What would be the best method of keeping good detail but not killing the game?

A: Tga files will use x * y * 3 bytes of video memory, where x is the width of the bitmap and y is its height. If your sky cube uses a (let's say) 3072 x 512 pixels picture, it will consume 3072 x 512 x 3 = 4.5 MB of video memory. If you plan to use bmp or pcx files, they'll only need x * y * 2 bytes, which means that the same 3072 x 512 pixels bitmap would consume 3 MB of video memory.

 

 

Q: Is there a way to display the movement of an entity on a panel?

A: Here's an improved version of my radar code from Aum9; don't forget to read the article before using this snippet:

 

var level_minx = -1800; // get these values in wed (level boundaries in quants)

var level_maxx = 1800;

var level_miny = -1500;

var level_maxy = 1500;

var scalex = 0.035; // play with these values until you get a good map coverage for the player

var scaley = 0.036;

var scanning_range = 0;

 

function appear_on_radar();

 

bmap radar_map = <radarpan.pcx>;

 

panel radar_pan

{

       bmap = radar_map;

       layer = 20;        

       pos_x = 0;

       pos_y = 0;

       flags = overlay, refresh, d3d, visible;

}

 

starter start_scanning

{

       while (player == null) {wait (1);}

       scanning_range.x = 360; // pan

       scanning_range.y = 180; // tilt

       scanning_range.z = 5000; // radar's range

       while (1)

       {

               scan_entity (player.x, scanning_range.x);

               wait (1);

       }

}

 

action test_entity // this action will be attached to your enemies

{

       my.enable_scan = on;

       my.event = appear_on_radar;

       // put the rest of the code for your enemies here, remove the test loop from below

       while (1)

       {

               my.x += 3 - random(6); // show some activity on the radar

               my.y += 3 - random(6); // to be used only during the test phase

               wait (1);

       }

}

 

function appear_on_radar()

{

       if (event_type == event_scan)

       {

               draw_text( "*", scalex * (abs(my.x - level_maxx)), scaley * (abs(my.y - level_miny)), vector(0, 0, 255));

       }

}

 

 

Q: How can I use "bounce" to set the orientation of a bouncing object?

A: Examine my tiny game sample:

 

function ball_event()

{

       vec_to_angle (my.pan, bounce);

}

 

action bouncing_ball

{

       randomize();

       my.pan = random(360);

       my.enable_block = on;

       my.enable_impact = on;

       my.enable_entity = on;

       my.event = ball_event;

       while(1)

       {

               c_move (my, vector(10 * time, 0, 0), nullvector, ignore_passable);

               wait(1);

       }

}

 

 

Q: Can anyone give me a sliding doors script that I can use in together with my non-template wdl? I need to open a number of different doors by using the space bar.

A: Use this example:

 

action sliding_door

{

       while (player == null) {wait (1);} // wait until the player is created

       while (1)

       {

               if (vec_dist (player.x, my.x) < 100) // the player has come close to the door

               {

                       // if the player presses "space" and the door hasn't been opened yet

                       if ((key_space == on) && (my.skill2 == 0))

                       {

                               my.skill2 = 1;

                               while (my.z < 200) // play with this value

                               {

                                       my.z += 5 * time;

                                       wait (1);

                               }

                               break;

                       }

               }

               wait (1);

       }

}