........................
// This is from the tank's action, and initiates the function to fire bullets
if(mouse_right){fire_turrmg();}
......................
// Function used to fire machine gun (still needs sound bug fixed)
function fire_turrmg()
{
snd_stop(hnd_MGfire);
hnd_MGfire = ent_playloop(player,snd_792MG,70);
var firing_ang;
VECTOR mg_barrel;
vec_for_vertex(mg_barrel,player,28);
ent_create("MG_bullet.mdl",mg_barrel,mg_action);
wait(-0.04);
if(!mouse_right){snd_stop(hnd_MGfire);}
}
.................
// Action to handle machine gun bullets
action mg_action()
{
wait(1);
ang_for_bone(my.pan,player,"turret_bone");
ang_rotate(my.tilt,vector(Turr_Ang,0,0));
c_move(me,vector(15,0,0),NULLVECTOR,IGNORE_YOU);
c_setminmax(my);
phent_settype(me,PH_RIGID,PH_BOX);
phent_setmass(me,0.012,PH_SPHERE);//45kg
phent_setfriction(me,100);
phent_setdamping(me,2,100);
phent_addvellocal(my, vector(2000,0,0), nullvector);
wait(1);
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT);
my.event = impact_mghit;
set(my,POLYGON);
set(my,BRIGHT);
set(my,METAL);
set(my,INVISIBLE);
var mps;
while(1)
{
phent_getvelocity(my,mps,NULLVECTOR);
wait(1);
tracerglow.x = - 20; tracerglow.y = 0; tracerglow.z = 0;
vec_rotate(tracerglow,my.pan);
VECTOR tail;
vec_for_vertex(tail,me,1);
effect(effect_smktrail, 1, tail,tracerglow);
effect(effect_tracer,1,tail,tracerglow);
vec_rotate(tracerglow,my.pan);
kill_bullet();
wait(1);
}
wait(1);
}
.................................
// Oh, and here's the event function
function impact_mghit()
{
switch (event_type)
{
///////////////////////////////////////////////////////////////////////////////////////////////////
case EVENT_IMPACT:
wait(1);
VECTOR placement;
placement.x = my.x; placement.y = my.y; placement.z = my.z;
effect(effect_sandhit,5,vector(my.x,my.y,my.z),NULLVECTOR);
wait(1);
ent_remove(me);
///////////////////////////////////////////////////////////////////////////////////////////////////
case EVENT_ENTITY:
wait(1);
VECTOR placement;
placement.x = my.x; placement.y = my.y; placement.z = my.z;
effect(effect_sandhit,5,vector(my.x,my.y,my.z),NULLVECTOR);
wait(1);
ent_remove(me);
///////////////////////////////////////////////////////////////////////////////////////////////////
case EVENT_BLOCK:
wait(1);
VECTOR placement;
placement.x = my.x; placement.y = my.y; placement.z = my.z;
effect(effect_sandhit,5,vector(my.x,my.y,my.z),NULLVECTOR);
wait(1);
ent_remove(me);
}
}