void createBullethole(VECTOR* pos, VECTOR* n, int chunk){
vec_set(hit.x, pos);
vec_set(hit.nx, n);
hit.chunk = chunk;
hit.model = NULL;
PARTICLE* p = ent_decal(NULL, "bullet_hole.tga", 8, random(360));
//here you can set up everything for the bullet hole, like a event and a material
p.lifespan = 160; //remove after 10 secs
}
void pistol_shoot(){
VECTOR from, to;
//mouse_spot to get the middle of the crosshair
vec_set(from, vector(mouse_pos.x + mouse_spot.x, mouse_pos.y + mouse_spot.y ,0);
vec_set(to, from);
to.z = camera.clip_far;
vec_for_screen(from, camera);
vec_for_screen(to, camera);
c_trace(from, to, IGNORE_PASSABLE | IGNORE_ME | IGNORE_YOU | USE_POLYGON | SCAN_TEXTURE);
int holeChunk = hit.chunk;
VECTOR holePos;
vec_set(holePos, target);
VECTOR holeN;
vec_set(holeN, normal);
vec_set(to, target);
vec_for_vertex(from, pistol, 797);
c_trace(from, to, IGNORE_PASSABLE | IGNORE_ME | USE_POLYGON | ACTIVATE_SHOOT | GET_HITVERTEX);
if(you==NULL){//hit nothing
createBullethole(holePos, holeN, holeChunk);
}
else{
your.health -= PISTOL_DAMAGE;
}
}