Questions from the forum |
Top Previous Next |
Q: How do I change the "eball" snippet from Aum14 so that I can fire the energy balls by clicking a panel? A: Use the modified snippet.
string energyball_mdl = <energy.mdl>;
bmap eball_pcx = <eball.pcx>;
sound energy_snd = <energy.wav>;
var eball_speed; var eball_pos;
function fire_eball(); function energy_ball(); function remove_eball();
panel eball_pan // click this panel to fire the eballs { bmap = eball_pcx; pos_x = 500; pos_y = 200; layer = 15; flags = overlay, refresh, visible; on_click = fire_eball; }
function fire_eball() { vec_set (eball_pos.x, camera.x); ent_create (energyball_mdl, eball_pos, energy_ball); snd_play (energy_snd, 70, 0); }
function energy_ball() { wait (1); my.passable = on; my.enable_entity = on; my.enable_block = on; my.event = remove_eball; my.pan = camera.pan; my.tilt = camera.tilt; my.lightred = 250; my.lightgreen = 150; my.lightrange = 200; eball_speed.x = 20; eball_speed.y = 0; eball_speed.z = 0; eball_speed *= time; while (my != null) { if (vec_dist (camera.x, my.x) > 30) {my.passable = off;} my.roll += 20 * time; c_move (my, eball_speed, nullvector, ignore_passable); wait (1); } }
function remove_eball() { wait (1); if (you != null) { you.skill10 -= 60; // decrease health (if skill10 stores the entity's health) } ent_remove (me); }
Q: How can I put a looping avi in my space simulation game, inside the level? A: Use the following example.
action movie_loop // attach this action to a sprite or a model { sleep (1); media_loop ("test.avi", bmap_for_entity (my, 0), 100); // use your own movie name }
Q: How can code it so when the player touches a model, that model plays an animation? A: Use this example.
function play_animation() { proc_kill(4); // don't allow more than 1 instance of this function to run my.skill10 = 0; while (my.skill10 < 100) { ent_animate(my, "jump", my.skill10, null); // play the "jump" animation my.skill10 += 4 * time; wait (1); } }
action sensitive_model { my.enable_impact = on; my.event = play_animation; }
Q: I am trying to create menu that isn't using the mouse. How can I "click" a button if the cursor is placed over the button and I press a key on the keyboard? A: Use this snippet.
bmap arrow_pcx = <arrow.pcx>; // this is your mouse pointer bitmap bmap button1_pcx = <button1.pcx>; bmap button2_pcx = <button2.pcx>;
function test_clicks(); function button_was_clicked();
panel menu_pan { layer = 15; // test_clicks() runs when the pointer is placed over the button button = 50, 250, button2_pcx, button1_pcx, button2_pcx, null, null, test_clicks; flags = overlay, refresh, visible; }
starter simulate_mouse() { mouse_map = arrow_pcx; mouse_mode = 2; while (1) { mouse_pos.x -= 10 * (key_cul - key_cur) * time; mouse_pos.y -= 10 * (key_cuu - key_cud) * time; wait (1); } }
function test_clicks() { if (event_type == event_touch) // the mouse was placed over the button? { while (event_type != event_release) // wait until the pointer is moved away from the button { if (key_space == on) // press "space" to execute the needed action { button_was_clicked(); break; } wait (1); } } }
function button_was_clicked() { // do what you need here beep; }
Q: My player character is blocked by an invisible box around the objects, and not the objects' shapes. I seem to remember reading that A6 has polygon precise collision; how can I activate it? A: Check the "polygon" flag for the entities that need to use polygon-based collision detection or put the following line of code in your entities' action. Don't forget that you have to use c_move for all the entities that are supposed to move.
my.polygon = on;
Q: Is it possible to copy the value of a variable into a string? A: Use str_for_num to do it:
string average_string[120]; string temporary_string;
text average_txt { layer = 50; pos_x = 30; pos_y = 250; font = _a4font; flags = visible; }
starter compute_average() { randomize(); sleep (3); var i = 0; var average = 0; while (i < 100) { temp = random(10); average += temp / 100; i += 1; } str_cpy (average_string, "The average of 100 random numbers from 0 to 10 should be 5.000 but now it is... "); // now convert "average" to its string representation and store it in temporary_string str_for_num(temporary_string, average); str_cat (average_string, temporary_string); average_txt.string = average_string; }
Q: Is there any event that happens if an object doesn't touch any other object? Or is there any possibility to script that? A: Examine the code below.
function touched_me() { my.skill40 = 1; }
action cant_touch_me { my.enable_impact = on; my.enable_entity = on; my.event = touched_me; while (my.skill40 == 0) // nothing has touched this object yet? { my.pan += 5 * time; // then do whatever you want to do here wait (1); } // the object was touched here beep; }
Q: How can I activate a switch using the middle mouse button? A: Use the following example.
action my_switch { // make sure that your player action includes this line of code: "player = null;" at its beginning while (player == null) {wait (1);} while (1) { if (vec_dist (player.x, my.x) < 100) // the player has come closer than 100 quants to the switch? { if (mouse_middle == on) // the middle mouse button was pressed? { while (mouse_middle == on) {wait (1);} // wait until the button is released // put your own code here camera.ambient = (camera.ambient == off) * 100; // make the level brighter or darker } } wait (1); } }
Q: How can I create a panel at runtime using the new pan_create function? A: Use this piece of code.
starter create_panel() { pan_create("bmap = weapon.pcx; pos_x = 50; pos_y = 140; flags = overlay, visible;", 10); // layer = 10 }
Q: How can I attach a non-animated sword to my player model? A: Go through the following steps:
1) Set the proper orientation and position for your sword in Med, as shown in the picture below:
2) Get (from player's palm) the numbers of the vertices that will define the orientation of the sword:
3) Use this snippet to add the sword to the player:
string sword_mdl = <sword.mdl>;
function attach_sword() { proc_late(); my.passable = on; // the sword shouldn't slow down the player while (you != null) { // get the vertex at the bottom of the palm in Med vec_for_vertex (my.skill1, you, 28); // get the vertex that separates the thumb and the pointer finger in Med vec_for_vertex (my.skill4, you, 9); // compute the vector that will be used by the sword vec_diff (my.skill7, my.skill4, my.skill1); // rotate the sword accordingly vec_to_angle (my.pan, my.skill7); // put the origin of the sword in the vertex that is placed at the bottom of the palm vec_set (my.x, my.skill1); wait (1); } }
action my_players_action // this would be your player's action { ent_create (sword_mdl, my.x, attach_sword); // put this line in your player's action // the rest of the code for your player goes here // ......................................... }
|