Shootable lamp entity with flare

Posted By: June

Shootable lamp entity with flare - 03/05/18 03:34

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);

}
Posted By: Ayumi

Re: Shootable lamp entity with flare - 03/05/18 08:20

I think, you don t Need an Event in this case.
Just ask, if the you Pointer is "lamp" and remove.


Btw.

Code:
set (my, TRANSLUCENT);
set (my, PASSABLE); 
set (my, BRIGHT); 

set (my, TRANSLUCENT|PASSABLE|BRIGHT);

Posted By: June

Re: Shootable lamp entity with flare - 03/06/18 06:25

I tried the code without the event as a separate function and included in the action instead but it does not work.

I don't want to remove the lamp itself, just the flare. I know there is a way to do it but my understanding of pointers is limited.

Thanks for the tip, I didn't know you could combine settings into one line. That should clean up future code quite nicely.
Posted By: Ayumi

Re: Shootable lamp entity with flare - 03/06/18 18:09

I am not 100% about the Skill Casting, but i am sure , it s possible.
Code not tested, just try...

Code:
#define EntGroup skill1

#define TypeLampFlare 1
#define TypeLamp 2


action Lamp()
{
	// ... set Lamp settings
	my.EntGroup= TypeLamp;
	my.skill3 = ent_create("LampFlare.mdl", vector, DoSomthing);
	
}

void Shoot()
{
	VECTOR vecShot;
	
   			   			   
   vec_set(vecShot, vector(1, 1, 1));	
   vec_rotate(vecShot, camera.pan);
	vec_add(vecShot, camera.x);
//   c_ignore(2,3,0);	      	      
   c_trace(camera.x, vecShot, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);			   	   
	
   if(TARGTE_HIT)
   {
      if(you.EntGroup == TypeLamp)
      { 
         if(you.skill3 != NULL)
       	 {
            ENTITY* ent = (ENTITY*)you.skill3;
            ptr_remove(ent);
         }
      }
   }		
}

Posted By: June

Re: Shootable lamp entity with flare - 03/07/18 02:55

Thank you for taking the time to write this out, Ayumi. I will do some testing and see what happens.
© 2024 lite-C Forums