This is an in-progress code for a light emitting lamp entity that turns off when shot (from a weapon that uses c_trace).

It works as intended except that the flare isn't removed when the lamp is shot.

This might be a simple mistake I'm making (noob coding). Can anyone see the problem?



var lamplife = 1; // Lamp is lit when at 1

function lampshot_event()// If shot, things happen
{

if (event_type == EVENT_SHOOT)
{
lamplife = 0; // lamp is dead, trigger to remove flare
my.ambient = 50;
my.lightrange = 0;
//add sound, sparks, glass particles
}
}


function lamp_light1_flr()//Lamp flare model

{
set (my, TRANSLUCENT);
set (my, PASSABLE);
set (my, BRIGHT);
my.alpha = 15;
my.ambient = 100;
vec_set(my.pan, your.pan);
vec_set(my.x, vector(0, 0, 0)); //Position at lamp
vec_for_ent(my.x, you); // World coordinates

if (lamplife == 0)//Remove the flare when lamp is shot
{
wait(1);
ent_remove (my);
}
}

action lamp_light1() // Round, shootable lamp
{
my.emask = ENABLE_SHOOT;
my.event = lampshot_event;

set (my, TRANSLUCENT);
my.ambient = 100;
my.alpha = 95;

set(my,LIGHT);
my.lightrange = 155;
my.red = 100;
my.blue = 100;
my.green = 100;

//Create flare mdl
ent_create ("lmp_round01_flr.mdl", my.x, lamp_light1_flr);

}

Last edited by June; 03/05/18 04:31.

June
smooth-3d.com