HL1: my own flashlight Created 13 years ago2010-10-02 07:18:19 UTC by Un_Nem Un_Nem

Created 13 years ago2010-10-02 07:18:19 UTC by Un_Nem Un_Nem

Posted 13 years ago2010-10-02 07:18:19 UTC Post #285985
Do anyone know how to make my own flashlight sprite ?
Posted 13 years ago2010-10-02 09:58:01 UTC Post #285987
coding
Suparsonik SuparsonikI'm going off the edge to meet my maker.
Posted 13 years ago2010-10-02 10:48:08 UTC Post #285988
I'm not even sure the flash-light uses a sprite, I always taught it was an actual coded light entity, but if it does have a sprite however, you should check the hl/valve/sprites directory for anything the flash-light might be using, then make your own sprite and replace the flash-light one with your own sprite and it should change.
Skals SkalsLevel Designer
Posted 13 years ago2010-10-02 11:29:35 UTC Post #285991
I think the flashlight is actually a spotlight. But here's something I've been wondering about for a while... if I ever get off my ass and start working on a proper mod, I'd like to see rotating emergency lights (like at the beginning of Agroprom in Stalker: http://www.youtube.com/watch?v=cj9njhgPng4&feature=related) with actual lights, not just func_illusionary brushes. Given that the flashlight is a light that follows the players movement, wouldn't it be possible to code a light entity to follow a func_rotating for instance?

Don't mean to hijack the thread, just some thoughts...
Posted 13 years ago2010-10-02 11:39:01 UTC Post #285992
It can probably be easily done with the help of coding, but I'm not quite sure how hlrad will react to it. I mean you can turn lights on and off already but if they move how will hlrad properly texture the light faces?
Skals SkalsLevel Designer
Posted 13 years ago2010-10-02 16:19:12 UTC Post #286002
The same way as with the flashlight? More work for the realtime engine, I guess.
Posted 13 years ago2010-10-02 16:34:14 UTC Post #286005
I believe the flashlight is a simple coding trick that makes the one targeted area illuminated when it is active. You can tell it's not a proper spotlight because when you view the playerfrom someone elses perspective, you can see a light_spot glow around his feet, facing downwards rather than where he is pointing the flashlight. So I believe that when Valve made the game, they ran into some problems with the moving light_spot entity and instead of allowing others to view it as you would view it, they just illuminated the player whenever he activates his flashlight.
I'm not saying it's impossible to properly code a constantly moving light_spot, but the engine is quite old so you will most likely hit a brick wall.

However there is a way to create the same effect using simply hammer and no codes which I just taught of... But I believe simply using a moving func_illusionary is the best way.
Skals SkalsLevel Designer
Posted 13 years ago2010-10-02 18:43:32 UTC Post #286019
Here's the flashlight code from the engine:
[quote]void CL_PlayerFlashlight( void )
{
cl_entity_t *ent;
dlight_t *dl;
ent = cl_entities + cl.playernum + 1;
if ( ent->curstate.effects & (EF_BRIGHTLIGHT|EF_DIMLIGHT) && cl.worldmodel )
{
	if ( cl.pLight && cl.pLight->key == 1 )
		dl = cl.pLight;
	else
		dl = efx.CL_AllocDlight (1);
	if ( ent->curstate.effects & EF_BRIGHTLIGHT )
	{
		dl->color.r = dl->color.g = dl->color.b = 250;
		dl->radius = 400;
		VectorCopy (ent->origin, dl->origin);
		dl->origin[2] += 16;
	}
	else
	{
		pmtrace_t trace;
		vec3_t end;
		float falloff;
		VectorCopy (ent->origin, dl->origin);
		VectorAdd( dl->origin, cl.viewheight, dl->origin );
		VectorMA( dl->origin, FLASHLIGHT_DISTANCE, vpn, end );
		// Trace a line outward, use studio box to avoid expensive studio hull calcs
		pmove->usehull = 2;
		trace = PM_PlayerTrace( dl->origin, end, PM_STUDIO_BOX, -1 );
		if ( trace.ent > 0 )
		{
			// If we hit a studio model, light it at it's origin so it lights properly (no falloff)
			if ( pmove->physents[ trace.ent].studiomodel )
			{
				VectorCopy( pmove->physents[trace.ent ].origin, trace.endpos );
			}
		}
		VectorCopy( trace.endpos, dl->origin );
		falloff = trace.fraction*FLASHLIGHT_DISTANCE;
		if ( falloff < 500 )
			falloff = 1.0;
		else
			falloff = 500.0 / (falloff);
		falloff *= falloff;
		dl->radius = 80;
		dl->color.r = dl->color.g = dl->color.b = 255 * falloff;
#if 0
		dlight_t *halo;
		halo = efx.CL_AllocDlight( 2 );
		halo->color.r = halo->color.g = halo->color.b = 60;
		halo->radius = 200;
		VectorCopy (ent->origin, halo->origin);
		halo->origin[2] += 16;
		halo->die = cl.time + 0.2;
#endif
	}
	cl.pLight = dl;
	dl->die = cl.time + 0.2;
	CL_TouchLight( dl );
}
else
{
	if ( cl.pLight && cl.pLight->key == 1 )
		cl.pLight->die = cl.time;
	cl.pLight = NULL;
}
} [/quote]

I think the way it works is the server .dll sets EF_DIMLIGHT in the player's pev->effects, and if it's set, the engine creates a dynamic light.
If you want to draw a sprite while the flashlight is on, you'll probably do that on the client in CHudFlashlight::Draw
Posted 13 years ago2010-10-02 20:49:08 UTC Post #286023
Well, Night in the Office used a flashlight sprite like you said in lieu of the real-time lighting. It looks like crap in my opinion. I could never understand why they switched to the inferior "fixed" method in HL2. HL1's flashlight was so realistic in its behavior, but then they went and downgraded it. Probably they thought it distracted players, but it was so cool...
Posted 13 years ago2010-10-03 02:00:30 UTC Post #286029
A flashlight NEVER casts a perfect circle of light, there is ALWAYS some sort of imperfection in the lens, there's the rim of the lens\casing, there's some dirt (Brand new flashlight doesn't obviously), often times there's something in the bulb [again imperfections in the glass], so i don't believe hl1's flashlight was all that realistic at all.

Oh wait you meant the BEHAVIOR. Whoops...
Crollo CrolloTrollo
You must be logged in to post a response.