hl2 coding questions

I have a few question about hl2 coding.

How to draw a line along a tracer?

Where can I find the code which kills npcs when a npc got hit by a bullet?

has nobody an answere?

Take a look at the env_gunfire entity code.

didn’t help much, but thanks though.
any idea how to draw a simple line?(not env_beam or env_laser, just a simple 1px line)

UTIL_TraceLine(…)…is what you want


[list]
[*][B]vStart, vEnd[/B] are points defined as vectors
[*][B]iMask[/B] is that mask for solids to test against; usually MASK_SHOT
[*][B]pTraceEntity[/B] is entity you wish to ignore when firing this trace. 
[*][B]iCollision[/B] is the collision group to skip; usually COLLISION_GROUP_NONE
[/list]

trace_t tr;
UTIL_TraceLine( vStart, vEnd, iMask, pTraceEntity, iCollison, &tr );

Once you fire the trace you can use [B]tr[/B] to find the following infromation:

[list]
[*][B]tr.m_pEnt[/b], if the trace hit anything then this may return the entity that was hit.
[*][B]tr.startpos & tr.endpos[/B], the start point and end point where the trace calculated
[*][B]tr.plane[/B], plane information if any ( this is where you can get the normal, search the code for struct cplane_t )
[*] and more defined in ..public/trace.h
[/list]

You can draw a debug 1pixel length line with NDebugOverlay::Line(…)

thank you very much!

another question:
when I kill an npc with TakeDamage() I get this:

CreateEvent: event 'entity_killed' not registered.

how to register an event?

…sourcemods/yourmod/resources/GameEvents.res ( If it is missing then you need to rip it from an gcf )

add if missing

	"entity_killed"				
	{
		"entindex_killed" "long"	
		"entindex_attacker" "long"
                "entindex_inflictor" "long"
		"damagebits" "long"
	}

wow, it worked I thought I would have to tell the game event manager something

got a new problem:
if I kill a npc with takedamage() short after the npc shot at the player the game crashes, because it can’t get the entity infos.
How to fix this?(something like preventing deletion of the entity in the memory)

bump!
I wrote this:

void Spawner::Think()
{
	BaseClass::Think();
	m_nRenderMode = kRenderTransAlpha;
	m_nRenderFX = kRenderFxFadeFast;
	DevMsg("Alpha Value of %s is %i\n",this->GetDebugName(), m_clrRender->a);
	if ( m_clrRender->a == 0 )
	{
		UTIL_Remove(this);
		return;
	}

	SetNextThink( gpGlobals->curtime + 1.0f );
}

the problem: m_clrRender and GetrenderColor() always say a = 255
how to solve this?

EDIT:

void Spawner::Think()
{
	BaseClass::Think();
	m_nRenderMode = kRenderTransAlpha;
	//m_nRenderFX = kRenderFxFadeFast;
        SetRenderColorA(GetRenderColor().a-5);

	if ( m_clrRender->a == 0 )
	{
		UTIL_Remove(this);
		return;
	}

	SetNextThink( gpGlobals->curtime + 0.01f );
}

sorry to revive this thread again, but I need some help again.

Could someone explain me how to spawn clientside particles?

I can’t help you with the coding, but have you tried asking for help at Interlopers? Really helpful community.

thx, the forum there is really very helpful

Founded in 2004, Leakfree.org became one of the first online communities dedicated to Valve’s Source engine development. It is more famously known for the formation of Black Mesa: Source under the 'Leakfree Modification Team' handle in September 2004.