/****************
snippet from _helpy.wdl
(c)opyright dummy collective
may only be used without permission
****************/
DEFINE _range, skill1;
DEFINE _sightangle, skill2;
DEFINE _hitEntity, skill99;
ENTITY* eHit;
function destroy_turret();
function move_bullet();
function remove_bullet();
var bullet_speed[3];
sound explode_snd = "boom.wav";
sound dart_snd = <poisondart.wav>;
string bullet_mdl = <dart.mdl>;
entity* plBiped01_entity;
action dartwall {
wait(1);
c_setminmax(me);
}
action dartstatue {
wait(1);
c_setminmax(me);
if (my._range == 0) { my._range = 1000; } // set the range with skill1, default = 1000 quants
if (my._sightangle == 0) {my._sightangle = 180;} // default viewing angle in front of the turret = 180
my.enable_impact = on;
my.event = destroy_turret;
while (plBiped01_entity == null) {wait (1);}
while (my != null && plBiped01_entity != null) {
if (vec_dist (my.x, plBiped01_entity.x) < my._range) {
vec_diff(temp, plBiped01_entity.x, my.x);
vec_to_angle(temp, temp);
if (abs(ang(temp.pan - my.pan)) <= abs(my._sightangle) / 2) {
// turn the turret toward the player
vec_set(my.pan, temp);
// try to create the dart outside of the turret bounding box
temp.x = my.max_x * 1.25; // <- IMPORTANTE
temp.y = 0;
temp.z = 0;
vec_rotate(temp, my.pan);
vec_add(temp, my.x);
ent_create (bullet_mdl, temp, move_bullet);
snd_play (dart_snd, 30, 0);
}
}
wait(-0.5); // 1 bullet every 0.5 seconds
}
}
function destroy_turret() {
wait (1);
if (you == plBiped01_entity) {return;} // can't be destroyed by running into it
snd_play (explode_snd, 70, 0);
ent_remove (me);
}
function move_bullet() {
wait (1);
c_setminmax(me);
my.enable_entity = on;
my.enable_block = on;
my.event = remove_bullet;
my.pan = you.pan;
my.lightred = 250;
my.lightgreen = 150;
my.lightrange = 200;
bullet_speed.x = 100;
bullet_speed.y = 0;
bullet_speed.z = 0;
while (me != null) {
//if (you == null) { break; } // you is the turret
if (my._hitEntity != 0) { break; }
c_move (me, vector(bullet_speed.x * time_step, 0, 0), nullvector, IGNORE_PASSABLE);
wait (1);
}
if (my._hitEntity != -1) {
eHit = ptr_for_handle(my._hitEntity);
if (eHit == plBiped01_entity) {
eHit._armor__003 -= 2; // decrease player's health
if(eHit._armor__003 < 0) {
// flesh damage after armor damage
eHit._health__003 += eHit._armor__003;
eHit._armor__003 = 0;
PlBiped_Damage_Reaction(); // display damage panel
}
}
}
if (me != NULL) {
ent_remove(me);
}
}
function remove_bullet() {
my._hitEntity = -1; // hit block
if (you != NULL) {
my._hitEntity = handle(you);
}
my.event = NULL;
}