Q: Please give me an example for a particle effect that uses beam!
A: Here's the code and 2 small shots (1st without beam, 2nd with beam)
function torch_fx();
function flame_fade();
bmap flame_pcx = <flame.pcx>;
action torch
{
my.invisible = on;
my.passable = on;
while (1)
{
effect (torch_fx, 1, my.x, normal);
wait (1);
}
}
function torch_fx()
{
temp.x = random(1) - 2;
temp.y = random(1) - 2;
temp.z = random(1) + 3;
vec_rotate (temp, my.pan);
vec_normalize (temp, 20);
vec_add(my.vel_x,temp);
my.bmap = flame_pcx;
my.flare = on;
my.bright = on;
my.size = 30;
my.move = on;
if (key_b == 1) // press "B" for beam
{
my.beam = on;
}
else
{
my.beam = off;
}
my.function = flame_fade;
my.lifespan = 100;
}
function flame_fade()
{
my.alpha -= 1.3 * time;
if (my.alpha < 0) {my.lifespan = 0;}
}
Q: I would like to have different sounds for every template gun - is this possible?
A: Open weapons.wdl, add the following lines at its beginning:
sound weapon1_wav = <weapon1.wav>;
sound weapon2_wav = <weapon2.wav>;
sound weapon3_wav = <weapon3.wav>;
and then replace function _flashup with this one:
function _flashup()
{
MY.SCALE_X = 2;
MY.SCALE_Y = 2;
vec_scale(MY.SCALE_X,actor_scale);
MY.PASSABLE = ON;
// Set flare only in D3D mode
if(VIDEO_MODE > 8) { MY.FLARE = ON; }
else{ MY.TRANSPARENT = ON; }
MY.FACING = ON;
MY.AMBIENT = 100;
MY.LIGHTRED = light_muzzle.RED;
MY.LIGHTGREEN = light_muzzle.GREEN;
MY.LIGHTBLUE = light_muzzle.BLUE;
MY.LIGHTRANGE = 100;
wait(1);
if (weapon_number == 1) {snd_play (weapon1_wav, 50, 0);}
if (weapon_number == 2) {snd_play (weapon2_wav, 50, 0);}
if (weapon_number == 3) {snd_play (weapon3_wav, 50, 0);}
// PLAY_SOUND gun_wham,50; // comment this line!
remove(ME);
}
Q: How can I use the mouse wheel to scroll through the weapons?
A: Add these lines at the end of function main:
while (1)
{
if (mickey.z > 5)
{
if (weapon_number == 6) {_gun_select7();}
if (weapon_number == 5) {_gun_select6();}
if (weapon_number == 4) {_gun_select5();}
if (weapon_number == 3) {_gun_select4();}
if (weapon_number == 2) {_gun_select3();}
if (weapon_number == 1) {_gun_select2();}
}
if (mickey.z < -5)
{
if (weapon_number == 2) {_gun_select1();}
if (weapon_number == 3) {_gun_select2();}
if (weapon_number == 4) {_gun_select3();}
if (weapon_number == 5) {_gun_select4();}
if (weapon_number == 6) {_gun_select5();}
if (weapon_number == 7) {_gun_select6();}
}
wait (1);
}
Q: I'm still searching for the code where the smoke trail for the rocket launcher is defined. Can you help me?
A: Open particle.wdl and look for function particle_smoke. Change the bitmap, lower the size of the particle and increase the speed on z.
Q: I would like to have a counter that starts as soon as the level loads and counts down from 120 seconds to 0. How can I do that?
A: Place the following code at the beginning of your main wdl file (office.wdl?):
var seconds = 120;
panel time_panel
{
pos_x = 0;
pos_y = 0;
layer = 10;
digits 10, 10, 3, _a4font, 1, seconds;
flags = visible, refresh, d3d;
}
function count_down()
{
while(seconds > 0)
{
sleep (1);
seconds -= 1;
}
}
and put this line of the end of main:
count_down();
Q: Does anyone know how can I control the sounds volume of a certain sound? I know about sound_vol, but it controls the volume of all the wav sounds.
A: Use this piece of code:
var my_volume;
bmap slider_pcx = <slider.pcx>;
sound mysound_wav = <mysound.wav>;
panel mysound_pan
{
layer = 20;
pos_x = 20;
pos_y = 20;
hslider = 20, 95, 200, slider_pcx, 0, 100, my_volume;
flags = d3d, overlay, refresh, visible;
}
function sound_volume() // call it in main
{
while (1)
{
if (key_s == 1) // press "S" to play the sound
{
while (key_s == 1) {wait (1);} // wait for the key to be released
snd_play (mysound_wav, my_volume, 0);
}
wait (1);
}
}
Q: I can open a file and write the data in it, but the new data always overwrites the old data. How can I fix that?
A: Use the code below; every time you run the game a new "aum" string will be added to the data.txt file:
var data_handle;
function add_data() // call it in main
{
data_handle = file_open_append("data.txt"); // open the file
file_str_write(data_handle, "aum "); // write "aum" inside the file
file_close(data_handle); // close the file
}
Q: I would like to create a camera effect; the camera should rotate around the player when I press a key. The center of the circle is the player and the camera should move around it, always facing the player.
A: Here's the code that does what you want:
var camera_angle = 0;
view rotating_camera
{
pos_x = 0;
pos_y = 0;
size_x = 640; // change this value to your screen resolution on x
size_y = 480; // and y
layer = 25; // must be bigger than camera's layer
}
function camera_effect()
{
camera.visible = off;
rotating_camera.visible = on;
while (player == null) {wait (1);}
while (key_s == 0) // press "S" to stop the effect
{
rotating_camera.x = player.x + 500 * cos(camera_angle.pan);
rotating_camera.y = player.y + 500 * sin(camera_angle.pan);
rotating_camera.z = player.z + 300;
camera_angle += 1 * time;
vec_set (temp.x, player.x);
vec_sub (temp.x, rotating_camera.x);
vec_to_angle (rotating_camera.pan, temp); // look at the player
wait (1);
}
camera.visible = on;
rotating_camera.visible = off;
}
on_c = camera_effect; // press "C" to start the rotating camera
Q: I have created an attack animation for my character; I want to play the entire animation when I press the left mouse button.
A: Use this piece of code as a base for your code:
action attack_me
{
while(1)
{
if(mouse_left == 1)
{
my.skill20 = 0;
while (my.skill20 < 100)
{
ent_cycle("attack", my.skill20);
my.skill20 += 5 * time;
wait (1);
}
}
while (mouse_left == 1) {wait (1);} // disable looping
wait(1);
}
}
|