Questions from the forum

Top  Previous  Next

Q: I want a car to go down the street. When the car is at the end of the street, it should teleport at the starting point and do it again.

A: There you go.

 

action street_car() // attach this action to your car model

{

       VECTOR init_pos;

       vec_set(init_pos.x, my.x);

       while (1)

       {

               // 10 sets the speed of the car

               c_move (my, vector (10 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

               // the car has move 2000 quants away from the starting point? (play with 2000)

               if (vec_dist (my.x, init_pos.x) > 2000)

                       vec_set(my.x, init_pos.x); // then teleport it at its starting point

               wait (1);

       }

}

 

 

Q: I need a panel window with a circular shape but I don't know how to do it; anyone has an idea?

A: This method works for panels that can have any shape you can think of. First of all, open the bitmap in your favorite image editor - I'll use Paint Shop Pro 9.

 

aum105_faq1

 

Use one of the selection tools to select the exact shape that will be displayed on the screen as a panel.

 

aum105_faq2

 

Now save the selection as an alpha channel.

 

aum105_faq3

 

Finally, save the file as a .tga (the .png format also uses transparency, so you can use it as well). Use this piece of code to display the panel.

 

PANEL* round_pan =

{

       bmap = "round.tga";

       pos_x = 300;

       pos_y = 200;

       layer = 15;

       flags = SHOW;

}

 

aum105_faq5

 

 

Q: I'm working with WED and the shooter template. I made a second level where the characters can buy weapons. When the player enters the second level without weapons, it looks good (no entities equipped). As soon as the player collects weapons in the 2nd level, random entities get equipped as weapons (a random box or plant) and they act as working weapons. How can I fix this?

A: Check the actions you've attached to your entities; those boxes and plants can't act as weapons if they don't have a weapon action attached to them. Also, please note that the template enemies can't pick up weapons; they should have their weapons at game start, so you must have a single enemy+weapon model, just like the template enemy does.

 

 

Q: I'd like to have my main menu buttons slide down and stop at their final positions, but I don't know how to do that.

A: There you go.

 

function new_game();

function exit_game();

 

BMAP* newgame1_pcx = "newgame1.pcx";

BMAP* newgame2_pcx = "newgame2.pcx";

BMAP* exit1_pcx = "exit1.pcx";

BMAP* exit2_pcx = "exit2.pcx";

 

PANEL* main_pan =

{

       layer = 10;

       bmap = "main.jpg";

       pos_x = 0;

       pos_y = 0;

       button (250, 0, newgame2_pcx, newgame1_pcx, newgame2_pcx, new_game, NULL, NULL);

       button (250, 0, exit2_pcx, exit1_pcx, exit2_pcx, exit_game, NULL, NULL);

       flags = SHOW;

}

 

function buttons_startup()

{

       var button_offset = 0; // the first button will move until its y position is 200

       fps_max = 75; // limit the frame rate to 75 fps in order to keep the panel sliding smoothly

       wait (-3); // give the computer a few seconds to display the main panel bitmap

       // the buttons will slide downwards until the first one is place at y = 250

       // the second button will be placed 100 quants below the first one, etc

       while (button_offset < 250)

       {

               pan_setbutton(main_pan, 1, 0, 250, button_offset, newgame2_pcx, newgame1_pcx, newgame2_pcx, NULL, new_game, NULL, NULL);

               // notice that the second button has an extra 100 pixels offset on the y axis

               pan_setbutton(main_pan, 2, 0, 250, button_offset + 100, exit2_pcx, exit1_pcx, exit2_pcx, NULL, exit_game, NULL, NULL);                

               button_offset += 1; // add 1 pixel / frame (about 75 pixels per second) to the offset

               wait (1);

       }

}

 

function new_game()

{

       wait (1); // use your own code here        

}

 

function exit_game()

{

       sys_exit(NULL);

}

 

BMAP* pointer_tga = "pointer.tga";

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

 

Q: I have created a shooter game using Gamestudio's template script but I can't get my player to grab the gun. The character's arms move like they are firing a gun but the gun is hanging in the air.

A: This happens because the weapons have different sizes, offsets, etc. Simply click the desired weapon in Wed, bring up its "Behaviour" tab, and then tweak its offset_x... offset_z parameters until you like the position of the weapon.

 

aum105_faq4

 

 

Q: When my player get close to steps (model blocks or level blocks from WED) he automatically lifts and goes up to the block, but I want it to keep always on the floor and only get on the steps when I jump on them.

A: You need to lower your player's origin in Med; if it is higher than the height of the steps, it will climb them.

 

 

Q: I'd like to have an mp3 file that plays one time after pressing a key. If the sound is still playing and you press the same key, the sound must start over.

A: Here's an example.

 

var track_handle;

 

function play_track()

{

       if (track_handle) // the sound is playing already?

               media_stop(track_handle); // then stop it!

       track_handle = media_play("track1.wav", NULL, 100); // play the sound track from its beginning

}

 

function init_startup()

{

       on_p = play_track;

}

 

 

Q: How can I use ptr_for_handle to make an entity pointer save-proof?

A: Use the "handle" instruction to save a handle to the entity in a normal variable, just like below:

 

t_mace = ent_create(mace_mdl, player.x, t_attach_mace);

mace_handle = handle(t_mace);

 

and then use ptr_for_handle to create the entity again when you will need it, like this:

 

t_mace = ptr_for_handle(mace_handle);

 

You will see a fully functional example in the t_rpg_inventory.c script, which is a part of the RPG template that's being developed right now.

 

 

Q: I need a menu to pop up when I right click a button on a panel. Can anyone help?

A: Here's the code that does what you want.

 

BMAP* mainpanel_pcx = "mainpanel.pcx";

BMAP* options_pcx = "options.pcx";

BMAP* options1_png = "options1.png";

BMAP* options2_png = "options2.png";

BMAP* menuoption1_png = "menuoption1.png";

BMAP* menuoption2_png = "menuoption2.png";

BMAP* pointer_tga = "pointer.tga";

 

function mouse_over();

function cancel_options();

 

PANEL* main_pan =

{

       bmap = mainpanel_pcx;

       layer = 15;

       button(40, 10, options2_png, options1_png, options2_png, NULL, NULL, mouse_over);

       flags = SHOW;

}

 

PANEL* options_pan =

{

       bmap = options_pcx;

       pos_x = 300;

       pos_y = 200;

       layer = 15;

       button(100, 150, menuoption2_png, menuoption1_png, menuoption2_png, cancel_options, NULL, NULL);

}

 

function mouse_over()

{

       // the loop below will run for as long as the mouse pointer wasn't moved away from the button

       while (event_type != EVENT_RELEASE)

       {

               if (mouse_right) // the right mouse button was clicked while the cursor was placed over the button?

                       set(options_pan, SHOW);

               wait (1);

       }

}

 

function cancel_options()

{

       reset(options_pan, SHOW);                

}

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

 

Q: Is there any way to use the mouse button to move the barrels in my warehouse one by one to another position?

A: Sure; attach the my_barrels action to all your barrels, and then click and move them. Use the mouse pointer and the mouse wheel to move them exactly where you want them to be.

 

BMAP* pointer_tga = "pointer.tga";

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function move_entity()

{

       VECTOR temp;

       var entity_offset = 0;

       my.skill1 += 1;

       temp.z = 200; // the default value places the entities

       if ((my.skill1 % 2) == 1) // clicked the entity?

       {

               while (mouse_left) {wait (1);} // wait until the player releases the left mouse button

               while (!mouse_left) // move the entity until the player presses the mouse button again

               {

                       temp.x = mouse_cursor.x;

                       temp.y = mouse_cursor.y;

                       temp.z = 200 + entity_offset;

                       entity_offset += mickey.z; // use the mouse wheel to bring the entity closer or farther away from the camera

                       vec_for_screen(temp.x, camera);

                       vec_set (my.x, temp.x);

                       set (my, PASSABLE);

                       wait (1);

               }

       }

       else // drop the object here

       {

               vec_set (temp.x, my.x);

               temp.z -= 3000; // trace up to 3,000 quants below

               // make sure to drop the object on the ground

               my.z -= c_trace (my.x, temp.x, IGNORE_ME + IGNORE_SPRITES + USE_BOX);

               reset (my, PASSABLE);

       }

}

 

action my_barrels()

{

       my.skill1 = 0;

       my.emask |= ENABLE_CLICK;

       my.event = move_entity;        

}