Here is the code:

Code:

define barrel_handle, skill1;

action ent_turret
{
my.barrel_handle = handle(ent_create("turret_barrel.mdl", my.x, NULL));

while(my) {

you = ptr_for_handle(my.barrel_handle);

var vec_to_ent[3];
var ang_to_ent[3];

// get the direction vector turret->camera and its angles
vec_diff(vec_to_ent, camera.x, my.x);
vec_to_angle(ang_to_ent, vec_to_ent);

// first rotate the turret's body
ang_rotate(my.pan, vector(ang(ang_to_ent.pan - my.pan),0,0));

// now rotate the barrel
vec_set(you.pan, my.pan);
ang_rotate(you.pan, vector(0,ang(ang_to_ent.tilt - you.tilt),0));



wait(1);
}
}



As you can see, the calculations of the code above will not work with arbitrary orientations.
However, I have no idea what has to be changed to get it working.