here is the weapon code

please if you use it, put my name in the credits.

you will ned adapt it to your needs, I have a tower gun entitie name torres, you need choose an entitie to be a gun and put the vertex of start and end the gun tuble. sorry my english is terrible.

Code:


//bullet code by Marcio Esper
//using NGD 1.51
// you need a gun entitie to set the bullet origen
//you need a bullet model
//examine the code, some things you can delet if i forget in the code


entity* projetil;

var destino[6];
var origem[6];
var final [6];
var newtonImpulseRecord[8];

function baladata(material){

var collisionType;
var body;
dll_handle = newtonHandle;

body = NewtonGetBody (my);
collisionType = my.collision_sph_box;
body = NewtonAddMapEntity (my, collisionType);
NewtonSetBodyMass (body, my.mass);
NewtonSetBodyLinearDamp (body, my.linear_drag);
NewtonSetBodyAngularDamp (body, my.angular_drag_x, my.angular_drag_y, my.angular_drag_z);
NewtonSetBodyForceAndTorque (body, ApplyGravityForceEvent);
NewtonSetBodyMaterial (body, material);
NewtonSetBodyActiveState (body, my.start_active);
vec_for_vertex(destino, torres, 130);
vec_for_vertex(origem, torres, 78);
//vec_diff (final,destino,origem); not need this


//ENT_playSOUND (torres, bum, 100); - uncoment and make a sound if you need it


// gun end of tuble point
newtonImpulseRecord[0] = destino.x;
newtonImpulseRecord[1] = destino.y;
newtonImpulseRecord[2] = destino.z;

// origin of bullet (use to determone the direction of the impulse)
newtonImpulseRecord[3] = origem.x;
newtonImpulseRecord[4] = origem.y;
newtonImpulseRecord[5] = origem.z;

// copy the bullet mass - change it to more or less distance and damage
newtonImpulseRecord[6] = 10000;

// copy the bullet speed - change like above
newtonImpulseRecord[7] = 900;
NewtonBodyAddImpulse (body, newtonImpulseRecord);

}



action bala{

projetil =me;
my.material = cores;
my.red=255;
my.green=200;
my.blue=100;
my.lightrange = 400;
my.light=on;
my.mass =10;
my.health = 20;
my.shape_factor = 0.9;
my.start_active=1;
baladata(wood_material);

}

Function tiro(){

vec_for_vertex(temp, torres, 130); //get temp the position of vertex
ent_create("balabh.mdl", temp, bala); //you need a bullet model, in this case I use balabh.mdl, you can use a little box


}



on_mouse_left = tiro();




I hope it help you.

best regards,

Marcio