Questions from the forum |
Top Previous Next |
Q: I am using the flares from Aum37. I'd like to give them the ability to bounce off walls and entities - can you help? A: Use these flares (player movement code included as well).
define burn_time skill20;
string flare_pcx = <flare.pcx>;
function change_direction() // handle collisions { vec_to_angle (my.pan, bounce); // change direction }
function show_flare() { var flare_speed; var dist_covered = 0; var total_distance = 0; var stop_me = 0; my.flare = on; my.bright = on; my.ambient = 100; my.red = 255; my.pan = camera.pan; // use player.pan instead of camera.pan for 3rd person games my.tilt = camera.tilt; // use player.tilt instead of camera.tilt for 3rd person games my.enable_block = on; my.enable_impact = on; my.enable_entity = on; my.event = change_direction; my.passable = on; while (stop_me == 0) { if (total_distance < 200) { flare_speed.x = 50 * time; } else { flare_speed.x = max (0, flare_speed.x - 0.2 * time); } flare_speed.y = 0; flare_speed.z = 3 * time; if (vec_dist (player.x, my.x) > 50) { my.passable = off; } if (bounce.z != 0) { flare_speed.z = -flare_speed.z * 0.9; if (abs(flare_speed.z) < 0.1) { my.passable = on; flare_speed.x = 0; flare_speed.y = 0; flare_speed.z = 0; stop_me = 1; } } flare_speed.z -= 2 * time; my.skill10 -= 1 * time; dist_covered = c_move (my, flare_speed.x, nullvector, ignore_passable); if (dist_covered < 1) // got stuck? { break; // then get out of the loop } total_distance += dist_covered; wait (1); } my.passable = on; // become passable my.burn_time = 10; while (my.burn_time > 0) { my.lightred = 255; my.lightgreen = 200 + random(55); my.lightblue = 230; my.lightrange = 200 + random(50); my.scale_x = 0.9 + random(1) / 10; // scale = 0.9 to 1.9 my.scale_y = my.scale_x; my.scale_z = my.scale_x; my.burn_time -= time / 16; // subtract "1" from burn_time every second wait (1); } while (my.scale_x > 0.1) { my.scale_x -= 0.1 * time; my.scale_y = my.scale_x; my.scale_z = my.scale_x; my.lightrange -= 2 * time; wait (1); } ent_remove (my); }
action player1 { var movement_speed = 7; // movement speed player = my; // I'm the player my.invisible = on; my.skill40 = 100; // let's store the health in skill40 while (my.skill40 > 0) { if (key_f == on) // press "F" to fire a bouncing flare { while (key_f == on) {wait (1);} ent_create (flare_pcx, my.x, show_flare); } player.pan -= 7 * mouse_force.x * time; camera.x = player.x; camera.y = player.y; camera.z = player.z + 50 + 1.1 * sin(my.skill44); // play with 50 and 1.1 camera.pan = player.pan; camera.tilt += 5 * mouse_force.y * time; vec_set (temp.x, my.x); // trace 10,000 quants below the player temp.z -= 10000; temp.z = -c_trace (my.x, temp.x, ignore_me | ignore_passable | use_box); temp.x = movement_speed * (key_w - key_s) * time; temp.y = movement_speed * (key_a - key_d) * 0.6 * time; c_move (my, temp.x, nullvector, ignore_passable | glide); if (key_w + key_s > 0) // if the player is walking { my.skill44 += 25 * time; ent_cycle("walk", my.skill46); // play its "walk" frames animation my.skill46 += 5 * time; my.skill46 %= 100; // loop the animation } else // if the player is standing { ent_cycle("stand", my.skill48); // play the "stand" frames animation my.skill48 += 2 * time; // "stand" animation speed my.skill48 %= 100; // loop animation } wait (1); } // the player is dead here my.skill40 = 0; // use the same skill40 to control the "death" animation my.invisible = off; // let's show player's body now while (my.skill40 < 90) { ent_cycle("death", my.skill40); my.skill40 += 2 * time; // "death" animation speed camera.roll -= 0.3 * time; camera.tilt += 0.8 * time; wait (1); } my.passable = on; // player's corpse will be passable from now on }
Q: I have tried to use the shader from Aum XY but it didn't work; when I run the code I get the error "Malfunction ...". What should I do? A: You need to buy a newer video card; the one that you are using isn't supporting the needed VS / PS version. Each shader article from Aum lists the VS / PS requirements; check Aum48 and you'll find a snippet that tells you the capabilities of your video card.
Q: How can I set the speed of the animation the way the animator wanted it to run? I want to play the animation at 25 fps no mater what the current frame rate is. A: Use the following example. Replace 25 / 32 with your own values; 25 is the desired number of animation frames per second and 32 is the number of animation frames.
action test_animation { while (1) { ent_animate(my, "walk", my.skill10, anm_cycle); // play the "walk" animation // 25/32 controls the animation speed, 25 = desired frame rate, 32 = the number of "walk" animation frames my.skill10 += 25 / 32 * (100 * time_step / 16); my.skill10 %= 100; wait (1); } }
Q: Can you tell me how can I prevent the rifle from Aum58's workshop to go through the walls? A: You're making me reveal some content from this month's workshop, but there you go... Use an "entity" definition; my example adds a new weapon which doesn't penetrate the walls.
entity weapon_ent // paste the code at the top of the weapons.wdl file { type = <subtech.mdl>; // weapon model pan = 0; // weapon angle x = 55; // 55 quants ahead of the view, play with this value y = 22; // 22 quants towards the left side of the screen, play with this value z = -22; // 22 quants below, play with this value flags = visible; // make the weapon visible }
Q: How do I get my player to move regularly over an mdl surface? Right now the player just falls or walks through the terrain and doesn't detect it all. A: The new versions of the engine include polygon-based collision detection for models. Check the "polygon" flag for your mdl surface and use a c_move - based movement snippet for your player. Here's a tiny, fully functional example:
action player1 { var movement_speed = 7; // movement speed player = my; // I'm the player my.invisible = on; while (1) { player.pan -= 7 * mouse_force.x * time_step; camera.x = player.x; camera.y = player.y; camera.z = player.z + 50 + 1.1 * sin(my.skill44); // play with 50 and 1.1 camera.pan = player.pan; camera.tilt += 5 * mouse_force.y * time_step; vec_set (temp.x, my.x); // trace 10,000 quants below the player temp.z -= 10000; temp.z = -c_trace (my.x, temp.x, ignore_me | ignore_passable | use_box); temp.x = movement_speed * (key_w - key_s) * time_step; // WSAD to move temp.y = movement_speed * (key_a - key_d) * 0.6 * time_step; c_move (my, temp.x, nullvector, ignore_passable | glide); wait (1); } }
Q: How do I turn off the creation of those annoying *.sav files? A: Find the line(s) of script which include the "game_save" instruction and comment or remove it / them.
Q: How can I have a light that glows systematically (like a red alarm)? A: Use this piece of code.
action red_alarm // attach it to any entity { my.invisible = on; my.passable = on; my.lightrange = 100; // 100 sets the light range while (1) { while (my.red < 255) { my.red += 10 * time_step; my.green = 0.2 * my.red; my.blue = 0.2 * my.red; wait (1); } while (my.red > 0) { my.red -= 10 * time_step; my.green = 0.2 * my.red; my.blue = 0.2 * my.red; wait (1); } wait (1); } }
Q: I'd like to have an animation that starts slow, but goes much faster in the end, like a power hit with the sword. A: Use the following example; press "P" to start the power hit animation.
action power_hit { fps_max = 80; // limit the frame rate to 80 fps while (key_p == off) {wait (1);} // wait until "P" is pressed while (key_p == on) {wait (1);} // wait until "P" is released var initial_frames; // store the initial number of frames that have passed since the game was started initial_frames = total_frames; while (my.skill10 < 100) // play the entire animation once { ent_animate(my, "stab", my.skill10, anm_cycle); // play with 0.1, 5 and 150 my.skill10 += (0.1 + min (5, (total_frames - initial_frames) / 150)) * time_step; wait (1); } }
Q: How can I synchronize lightning effects and thunder sounds? A: Use this example.
sound thunder_wav = <thunder.wav>;
string lightning_pcx = <lightning+15.pcx>; // animated lightning sprite, 15 animation frames
function show_lightning() { my.passable = on; my.oriented = on; my.pan = random(360); my.scale_x = 0.8 + random(2); my.scale_y = my.scale_x; my.bright = on; my.flare = on; my.ambient = 100; my.red = 215; my.blue = 255; my.green = 20; my.lightrange = 300; my.passable = on; while (my.frame < 15) { my.frame += 1 * time_step; my.lightrange = 300 - random(100); wait(1); } ent_remove(my); }
action lightning_thunder // attach it to an entity placed up high in the sky { my.invisible = on; my.passable = on; while (1) { temp.x = my.x + 1000 - random (2000); temp.y = my.y + 1000 - random (2000); temp.z = my.z; ent_create (lightning_pcx, my.x, show_lightning); sleep (0.7); // pause between lightning and thunder sound, play with this value snd_play (thunder_wav, 100, 0); sleep(7 + random(10)); // play with 7 and 10 } }
Q: I need a key that can be picked up and a door that automatically opens when the player walks up to it (and has the key). A: Use the following snippet:
var got_key1 = 0;
action my_key { my.passable = on; while (player == null) {wait (1);} while (vec_dist (player.x, my.x) > 100) { my.pan += 4 * time_step; wait (1); } my.invisible = on; // hide the key got_key1 = 1; }
action my_door { var door_coords; vec_set (door_coords.x, my.x); // store the initial door position while (got_key1 == 0) {wait (1);} // wait until the player picks up the key while (vec_dist (player.x, my.x) > 150) {wait (1);} // wait until the player comes close to the door while (my.x < door_coords.x + 80) // play with 80 { my.x += 3 * time_step; // play with 3 wait (1); } }
|