Code:
ENTITY* weapon1; // pointer to our weapon model
STRING* weapdisp = "Hello?";
TEXT* weapdisp_text = {
pos_x=300;
pos_y=500;
font=_a4font;
string=weapdisp;
flags=visible;
}
... snipped code here ...
function fire_bullets()
{
proc_kill(4); // don't allow more than 1 copy of this function to run
while (mouse_left == ON) // this loop runs for as long as the left mouse button is pressed
{
vec_for_vertex (temp.x, weapon1, 29); // get the coordinates for the bullets' origin
// create the bullet at camera's position and attach it the "move_bullets" function
ent_create (muzzle_pcx, temp.x, display_muzzle); // create the gun muzzle
//temp.x += 100;
ent_create (bullet_mdl, camera.x, move_bullets); /// use camera.x and not the weapon vertex
snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
wait(7); // adjust this to get the rpm you want
}
}
function move_bullets()
{
VECTOR bullet_speed; // this var will store the speed of the bullet
set(my,ENABLE_ENTITY|ENABLE_IMPACT);
my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
my.pan = camera.pan; // the bullet has the same pan
my.tilt = camera.tilt; // and tilt with the camera
my.push=5;
bullet_speed.x = 300 * time_step; // adjust the speed of the bullet here
bullet_speed.y = 0; //random(2); // allow windage... will make this an external calculation
bullet_speed.z = 0; // allow gravity
while (my != NULL) // this loop will run for as long as the bullet exists (it isn't "null")
{
// move the bullet ignoring the passable entities and store the result in distance_covered
c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);
wait (.1);
}
}
void remove_bullets() // this function runs when the bullet collides with something
{
wait (1); // wait a frame to be sure (don't trigger engine warnings)
str_cpy((weapdisp_text.pstring)[0],"Test!"); /// <-- this never happens!
effect (particle_blood, 100, my.x, normal);
if( you != NULL ){
str_for_entfile(weapdisp,you);
if(str_cmpi(weapdisp,"TOON_CRITTER2.MDL")==0)
{
str_for_entfile (weapdisp,you);
if(str_cmpi(weapdisp,"MOUND2B.MDL")==1)
{
effect(particle_dust, 15, my.x, normal);
}
else
{
effect(particle_dust, 5, my.x, normal);
}
}
else
{
spawn_physics(you);
}
}
set(my,PASSABLE|INVISIBLE); // the bullets becomes passable and invisible now
wait(2); // wait until the explosion_sprite() function is over
ent_remove (my); // and then remove the bullet
}
... more snipped code ...