hello,
i have tried to add some things to the weaponscript from AUM 59.
iīve wanted to add a stand, shot, reload animation, and choose weapon / holster weapon animation . the shot animation seems to work but if you push the mouse button faster the animation gets faster too. i donīt know how to fix it.
There are some problems with the reload animation and the ammo panel (i have add an ammo panel too).
the script plays the reload animation if the current ammo is full. iīve got some problems with the panel in general. i think iīve been confused by all variables.(current_ammo, maxcurrent_ammo, current_ammoreserve, maxcurrent_ammoreserve, ammocounter...) . iīve lost the track of things.
the idle / stand animation is missing, i have no idea how to manage it with the other animations and i want to be able to switch between weapons. i donīt know how to add more guns and the ammo types, choosing them by key 1, 2 and so on, and playing the switch animation when change the weapon.
in general i am not sure if the way i add the animation is the right or lets say efficent way.
it would be very nice if you can help me, please. i am desperate.:
here is the code:
var trace_coords;
var weapon_height;
var ammocounter = 0;
var current_ammo = 18;
var maxcurrent_ammo = 18;
var current_ammoreserve = 0;
var maxcurrent_ammoreserve = 180;
font verdana_font = "Verdana",0,20;
string hithole_tga = <hithole.tga>;
bmap cross_map = <crosshair.tga>;
BMAP ammo_map <bullet.pcx>;
sound bullet_wav = <pistol.wav>;
sound gotweapon2_wav = <gotweapon2.wav>;
sound nobullets_wav = <nobullets.wav>;
sound gotammo_wav = <gotammo.wav>;
sound reload1_wav = <pistolreload.wav>;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function fire_bullets(); // creates the bullets
function display_hithole(); // shows the hit hole bitmap
function show_crosshair();
panel crosshair
{
layer = 4;
bmap = cross_map;
alpha = 100;
flags = transparent, refresh, overlay, d3d;
}
PANEL ammo_panel
{
pos_x = 1100;
pos_y = 950;
digits = 52, 6, 3, verdana_font, 1, current_ammo;
digits = 52, 35, 3, verdana_font, 1, current_ammoreserve;
BMAP ammo_map;
LAYER 2;
FLAGS OVERLAY, REFRESH, d3d;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
entity weapon2_ent
{
type = <pistole.mdl>; // weapon model
pan = 0; // weapon angle
x = 35; // 55 quants ahead of the view, play with this value
y = -15; // 22 quants towards the right side of the screen, play with this value
z = -22; // 22 quants below, play with this value
pan = 2; // weapon's pan angle (you can also use tilt and roll)
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
action players_weapon2
{
my.passable = on; // the weapon is made passable
while (player == null) {wait (1);} // we wait until the player is created
while (vec_dist (player.x, my.x) > 50) // we wait until the player comes closer than 50 quants
{
// my.pan += 3 * time_step;
wait (1);
}
snd_play (gotweapon2_wav, 80, 0);
my.invisible = on;
weapon2_ent.visible = on;
ammo_panel.visible = on;
sleep (1);
ent_remove (my);
}
starter use_weapon2()
{
proc_late(); // run this function at the end of the function scheduler list (elliminates jerkiness)
var player1_pos; // stores the initial position of the player
var player2_pos; // stores the position of the player after a frame
while (player == null) {wait (1);}
while (1)
{
vec_set (player1_pos.x, player.x); // store the initial player position
if (weapon2_ent.visible == on) // the weapon is visible?
{
weapon2_ent.scale_x =4;
weapon2_ent.scale_y =4;
weapon2_ent.scale_z =4;
// weapon2_ent.frame = 1;
// while (weapon2_ent.frame <= 101)
// {
// weapon2_ent.frame += 2 * time;
// wait(1);
// }
vec_set(trace_coords.x, vector(10000, 0, 0)); // the weapon has a firing range of up to 10,000 quants
vec_rotate(trace_coords.x, camera.pan);
vec_add(trace_coords.x, camera.x);
if (c_trace(camera.x, trace_coords.x, ignore_me | ignore_passable) > 0) // hit something?
{
show_crosshair();
}
}
wait (1);
vec_set (player2_pos.x, player.x); // store player's position after 1 frame
if (vec_dist (player1_pos.x, player2_pos.x) != 0) // the player has moved during the last frame?
{
weapon_height += 30 * time_step; // then offset weapon_height (30 = weapon waving speed)
weapon2_ent.z += 0.04 * sin(weapon_height); // (0.03 = weapon waving amplitude)
}
}
}
on_mouse_left = fire_bullets; // call this function when the left mouse button is pressed
on_r = reload_weapon2;
function fire_bullets()
{
weapon2_ent.frame = 102;
if (weapon2_ent.visible == off) {return;} // don't do anything if the player hasn't picked up the weapon yet
if (current_ammo > 0) // got ammo?
{
while (weapon2_ent.frame <= 115)
{
weapon2_ent.frame += 3.5 * time;
wait(1);
}
c_trace(camera.x, trace_coords.x, ignore_me | ignore_passable | activate_shoot);
if (you == null) // hit a wall?
{
ent_create (hithole_tga, target.x, display_hithole); // then create a bullet hit hole
}
snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
current_ammo -= 1; // decrease the number of bullets
ammocounter +=1;
}
else // no ammo left?
{
snd_play (nobullets_wav, 100, 0); // then play the noammo.wav sound
reload_weapon2();
}
}
function display_hithole()
{
vec_to_angle (my.pan, normal); // orient the hit hole sprite correctly
vec_add(my.x, normal.x); // move the sprite a bit away from the wall
my.passable = on; // the hit hole bitmap is passable
my.transparent = on; // and transparent
my.ambient = 50;
my.flare = on;
my.oriented = on; // the sprite is oriented
my.roll = random(360); // and has a random roll angle (looks nicer this way)
my.scale_x = 0.5; // we scale it down
my.scale_y = my.scale_x; // on the x and y axis
sleep (20); // show the hit hole for 20 seconds
ent_remove (my); // and then remove it
}
action ammo_pack
{
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 50)
{
my.pan += 3 * time_step;
wait (1);
}
if (maxcurrent_ammoreserve <= 180 | current_ammo <= 18)
{
current_ammoreserve += 18; // use your own value here
snd_play (gotammo_wav, 80, 0);
my.invisible = on;
sleep (1);
ent_remove (my);
}
else
{
current_ammoreserve = maxcurrent_ammoreserve;
sleep(1);
}
}
function reload_weapon2()
{
weapon2_ent.frame = 116;
if (current_ammoreserve > 0 | current_ammo < 18)
{
current_ammo += ammocounter;
current_ammoreserve -= ammocounter;
while (weapon2_ent.frame <=160)
{
weapon2_ent.frame += 3 * time;
wait(1);
}
snd_play (reload1_wav, 80, 0);
}
else
{
wait(16);
}
weapon2_ent.frame = 102;
ammocounter = 0;
current_ammo = 18;
}
function show_crosshair()
{
crosshair.pos_x = (screen_size.x - bmap_width(cross_map))/2; //Center on x Axis
crosshair.pos_y = (screen_size.y - bmap_height(cross_map))/2; //Center on y Axis
crosshair.visible = on; //Set crosshair visible
}