This is a multi-part message in MIME format.
--
[ Picked text/plain from multipart/alternative ]
How the heck do you create and delete entities without crashing half-life? (
I thought this was simple too)
I used valve's code as examples but no matter what combination of deleting a
freaking entities, hl always manages to crap out.
Here is some code of mine for dropping an HEV entity.
Keep in minde, this function is static
void CItemBattery::Drop(CBasePlayer* pPlayer)
{
CBaseEntity *pEnt;
CItem *pTemp=NULL;
pPlayer->pev->armorvalue -= 15;
UTIL_MakeVectors( pPlayer->pev->v_angle );
pEnt = CBaseEntity::Create( "item_battery", pPlayer->pev->origin
,pPlayer->pev->angles, pPlayer->edict() );
UTIL_SetOrigin( pEnt->pev, pPlayer->pev->origin +
pPlayer->pev->view_ofs + gpGlobals->v_forward * 64);
pEnt->pev->velocity = gpGlobals->v_forward * 400;
pEnt->pev->angles = UTIL_VecToAngles (pEnt->pev->velocity);
pEnt->pev->angles.x = 0;
CItemBattery *pBattery = (CItemBattery *)pEnt;
pEnt->pev->spawnflags |= SF_NORESPAWN;
}
now let me know if this is wrong, because otherwise I think its right
because it works.
Now in CItem::Spawn() (battery is derived form this of course) it looks
like this:
void CItem::Spawn( void )
{
// m_bCanRespawn = TRUE;
pev->movetype = MOVETYPE_TOSS;
pev->solid = SOLID_TRIGGER;
UTIL_SetOrigin( pev, pev->origin );
UTIL_SetSize(pev, Vector(-16, -16, 0), Vector(16, 16, 16));
SetTouch(ItemTouch);
SetThink(ItemThink);
if (DROP_TO_FLOOR(ENT(pev)) == 0)
{
ALERT(at_error, "Item %s fell out of level at
%f,%f,%f", STRING( pev->classname ), pev->origin.x, pev->origin.y,
pev->origin.z);
UTIL_Remove( this );
return;
}
pev->nextthink = gpGlobals->time + 0.1;
m_fTime = gpGlobals->time +0.5;
}
That looks right to me, and it seems to work
Now here is some new code I added.
I don't want items people drop to stay for more then 30 seconds nor do I
want them to respawn so I do this
void CItem::ItemThink( void )
{
if(pev->spawnflags & SF_NORESPAWN)
{
if(m_fTime < gpGlobals->time )
{
SetThink( NULL );
SetTouch( NULL );
UTIL_Remove( this );
}
}
pev->nextthink = gpGlobals->time + 1.0;
}
SOMETHING is wrong with that, I don't know what, I don't know how but
something because after about the 400th battery I drop, hl crashes (Note
that the batteries disappear, there are not 400 on the screen, only 3 or 4,
I thought they were getting deleted by hl thinks otherwise)
Now to test my code, I set the life spawn of the battery to about 0.5
seconds, and I allow my self to drop infinite. it works for a while.. like I
said probably about 400 then hl crashes.. some kind of pointer crash .tried
to access blah blah at 0x000000, somewhere buried in ancient artifact they
call the hl engine.
Someone give me some advice here because I'm clueless how to make this
entities stuff delete correctly,
Thank you
--
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders