// The test runs this command. void CC_Test_EHandle() { if ( g_HandleTest.Get() ) { g_HandleTest->m_bSendHandle = !g_HandleTest->m_bSendHandle; } else { CHandleTest *pHolder = CREATE_ENTITY( CHandleTest, "handle_test" ); pHolder->m_Handle = CREATE_ENTITY( CHandleDummy, "handle_dummy" ); pHolder->Spawn(); g_HandleTest = pHolder; Msg( "Created EHANDLE test entity. Run this command again to transmit the second ent.\n" ); } }
void CSquidSpit::Shoot( CBaseEntity *pOwner, Vector vecStart, Vector vecVelocity ) { CSquidSpit *pSpit = CREATE_ENTITY( CSquidSpit, "squidspit" ); pSpit->Spawn(); UTIL_SetOrigin( pSpit, vecStart ); pSpit->SetAbsVelocity( vecVelocity ); pSpit->SetOwnerEntity( pOwner ); CSprite *pSprite = (CSprite*)pSpit->GetSprite(); if ( pSprite ) { pSprite->SetAttachment( pSpit, 0 ); pSprite->SetOwnerEntity( pSpit ); pSprite->SetScale( 0.5 ); pSprite->SetTransparency( pSpit->m_nRenderMode, pSpit->m_clrRender->r, pSpit->m_clrRender->g, pSpit->m_clrRender->b, pSpit->m_clrRender->a, pSpit->m_nRenderFX ); } CPVSFilter filter( vecStart ); VectorNormalize( vecVelocity ); te->SpriteSpray( filter, 0.0, &vecStart , &vecVelocity, pSpit->m_nSquidSpitSprite, 210, 25, 15 ); }
//------------------------------------------------------------------------------ // Purpose : Given an .mdl file with gibs and the number of gibs in the file // spawns them in pVictim's bounding box // Input : // Output : //------------------------------------------------------------------------------ void CGib::SpawnSpecificGibs( CBaseEntity* pVictim, int nNumGibs, float vMinVelocity, float vMaxVelocity, const char* cModelName, float flLifetime) { for ( int i = 0; i < nNumGibs; i++ ) { CGib *pGib = CREATE_ENTITY( CGib, "gib" ); pGib->Spawn( cModelName, flLifetime ); pGib->m_nBody = i; pGib->InitGib( pVictim, vMinVelocity, vMaxVelocity ); pGib->m_lifeTime = flLifetime; if ( pVictim != NULL ) { pGib->SetOwnerEntity( pVictim ); } //If pVictim is on fire, ignite pVictim's gibs as well. if ( pVictim->GetFlags() & FL_ONFIRE ) { pGib->Ignite( ( flLifetime - 1 ), false ); } } }
//------------------------------------------------------------------------------ // Purpose : Spawn random gibs of the given gib type // Input : // Output : //------------------------------------------------------------------------------ void CGib::SpawnRandomGibs( CBaseEntity *pVictim, int cGibs, GibType_e eGibType ) { int cSplat; for ( cSplat = 0 ; cSplat < cGibs ; cSplat++ ) { CGib *pGib = CREATE_ENTITY( CGib, "gib" ); if ( g_Language.GetInt() == LANGUAGE_GERMAN ) { pGib->Spawn( "models/germangibs.mdl" ); pGib->m_nBody = random->RandomInt(0,GERMAN_GIB_COUNT-1); } else { switch (eGibType) { case GIB_HUMAN: // human pieces pGib->Spawn( "models/gibs/hgibs.mdl" ); pGib->m_nBody = random->RandomInt(1,HUMAN_GIB_COUNT-1);// start at one to avoid throwing random amounts of skulls (0th gib) break; case GIB_ALIEN: // alien pieces pGib->Spawn( "models/gibs/agibs.mdl" ); pGib->m_nBody = random->RandomInt(0,ALIEN_GIB_COUNT-1); break; } } pGib->InitGib( pVictim, 300, 400); } }
//----------------------------------------------------------------------------- // Purpose: Creates and insterts a new keyframe into the sequence // Input : newPos - // newAngles - // Output : CPathKeyFrame //----------------------------------------------------------------------------- CPathKeyFrame *CPathKeyFrame::InsertNewKey( Vector newPos, QAngle newAngles ) { CPathKeyFrame *newKey = CREATE_ENTITY( CPathKeyFrame, "keyframe_track" ); // copy data across newKey->SetKeyAngles( newAngles ); newKey->m_Origin = newPos; newKey->m_flSpeed = m_flSpeed; newKey->SetEFlags( GetEFlags() ); if ( m_iParent != NULL_STRING ) { newKey->SetParent( m_iParent, NULL ); } // link forward newKey->m_pNextKey = m_pNextKey; m_pNextKey->m_pPrevKey = newKey; // link back m_pNextKey = newKey; newKey->m_pPrevKey = this; // calculate new times CalculateFrameDuration(); newKey->CalculateFrameDuration(); return newKey; }
void HIDDEN GetAddressVtableByClassname(const char *szClassName, const int iOffset, bool bCreate) { void *vtable; if (bCreate) { edict_t *pObject = CREATE_ENTITY(); void *addr = GetFunctionEntity(szClassName); if (addr == NULL) { //can't create object. printf2(__FUNCTION__ ":: Not found export function of binaries. Presumably looks '__declspec(dllexport) void %s(entvars_t *pev)'", szClassName); REMOVE_ENTITY(pObject); return; } // call link to class GetClassPtr<BaseClass>(pev); reinterpret_cast<void (*)(entvars_t *)>(addr)(&pObject->v); vtable = *(void **)pObject->pvPrivateData; } else { VirtualTableRef *refsVtbl = GetVirtualTableRefAddr(szClassName); vtable = (void *)refsVtbl->originalAddress; } printf2(__FUNCTION__ "* ADDRESS VTABLE: %p | ADDRESS VIRTUAL FUNC: %p", OffsetToRebase((size_t)vtable), OffsetToRebase(*(((size_t **)&vtable)[ iOffset ]))); }
CBeam *CBeam::BeamCreate( const char *pSpriteName, float width ) { // Create a new entity with CBeam private data CBeam *pBeam = CREATE_ENTITY( CBeam, "beam" ); pBeam->BeamInit( pSpriteName, width ); return pBeam; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_AntlionGrub::SpawnSquashedGrub( void ) { CGib *pStandin = CREATE_ENTITY( CGib, "gib" ); Assert( pStandin ); pStandin->SetModel( ANTLIONGRUB_SQUASHED_MODEL ); pStandin->AddSolidFlags( FSOLID_NOT_SOLID ); pStandin->SetLocalAngles( GetLocalAngles() ); pStandin->SetLocalOrigin( GetLocalOrigin() ); }
void CGib::SpawnHeadGib( CBaseEntity *pVictim ) { CGib *pGib = CREATE_ENTITY( CGib, "gib" ); //City17: Germany Violence Fix. /*if ( g_Language.GetInt() == LANGUAGE_GERMAN ) { pGib->Spawn( "models/germangibs.mdl" );// throw one head pGib->m_nBody = 0; } else {*/ pGib->Spawn( "models/gibs/hgibs.mdl" );// throw one head pGib->m_nBody = 0; //} if ( pVictim ) { Vector vecNewVelocity = pGib->GetAbsVelocity(); pGib->SetLocalOrigin( pVictim->EyePosition() ); edict_t *pentPlayer = UTIL_FindClientInPVS( pGib->edict() ); if ( random->RandomInt ( 0, 100 ) <= 5 && pentPlayer ) { // 5% chance head will be thrown at player's face. CBasePlayer *player = (CBasePlayer *)CBaseEntity::Instance( pentPlayer ); if ( player ) { vecNewVelocity = ( player->EyePosition() ) - pGib->GetAbsOrigin(); VectorNormalize(vecNewVelocity); vecNewVelocity *= 300; vecNewVelocity.z += 100; } } else { vecNewVelocity = Vector (random->RandomFloat(-100,100), random->RandomFloat(-100,100), random->RandomFloat(200,300)); } QAngle vecNewAngularVelocity = pGib->GetLocalAngularVelocity(); vecNewAngularVelocity.x = random->RandomFloat ( 100, 200 ); vecNewAngularVelocity.y = random->RandomFloat ( 100, 300 ); pGib->SetLocalAngularVelocity( vecNewAngularVelocity ); // copy owner's blood color pGib->SetBloodColor( pVictim->BloodColor() ); pGib->AdjustVelocityBasedOnHealth( pVictim->m_iHealth, vecNewVelocity ); pGib->SetAbsVelocity( vecNewVelocity ); } pGib->LimitVelocity(); }
//------------------------------------------------------------------------------ // Pow! //------------------------------------------------------------------------------ void CPropAPC2::ExplodeAndThrowChunk( const Vector &vecExplosionPos ) { ExplosionCreate( vecExplosionPos, vec3_angle, this, 1000, 500.0f, SF_ENVEXPLOSION_NODAMAGE | SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE | SF_ENVEXPLOSION_NOFIREBALLSMOKE, 0 ); UTIL_ScreenShake( vecExplosionPos, 25.0, 150.0, 1.0, 750.0f, SHAKE_START ); // Drop a flaming, smoking chunk. CGib *pChunk = CREATE_ENTITY( CGib, "gib" ); pChunk->Spawn( "models/gibs/hgibs.mdl" ); pChunk->SetBloodColor( DONT_BLEED ); QAngle vecSpawnAngles; vecSpawnAngles.Random( -90, 90 ); pChunk->SetAbsOrigin( vecExplosionPos ); pChunk->SetAbsAngles( vecSpawnAngles ); int nGib = random->RandomInt( 0, APC_MAX_CHUNKS - 1 ); pChunk->Spawn( s_pChunkModelName[nGib] ); pChunk->SetOwnerEntity( this ); pChunk->m_lifeTime = random->RandomFloat( 6.0f, 8.0f ); pChunk->SetCollisionGroup( COLLISION_GROUP_DEBRIS ); IPhysicsObject *pPhysicsObject = pChunk->VPhysicsInitNormal( SOLID_VPHYSICS, pChunk->GetSolidFlags(), false ); // Set the velocity if ( pPhysicsObject ) { pPhysicsObject->EnableMotion( true ); Vector vecVelocity; QAngle angles; angles.x = random->RandomFloat( -40, 0 ); angles.y = random->RandomFloat( 0, 360 ); angles.z = 0.0f; AngleVectors( angles, &vecVelocity ); vecVelocity *= random->RandomFloat( 300, 900 ); vecVelocity += GetAbsVelocity(); AngularImpulse angImpulse; angImpulse = RandomAngularImpulse( -180, 180 ); pChunk->SetAbsVelocity( vecVelocity ); pPhysicsObject->SetVelocity(&vecVelocity, &angImpulse ); } CEntityFlame *pFlame = CEntityFlame::Create( pChunk, false ); if ( pFlame != NULL ) { pFlame->SetLifetime( pChunk->m_lifeTime ); } pChunk->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL ); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pSpriteName - // &origin - // animate - // Output : CSprite //----------------------------------------------------------------------------- CSprite *CSprite::SpriteCreate( const char *pSpriteName, const Vector &origin, bool animate ) { CSprite *pSprite = CREATE_ENTITY( CSprite, "env_sprite" ); pSprite->SpriteInit( pSpriteName, origin ); pSprite->SetSolid( SOLID_NONE ); UTIL_SetSize( pSprite, vec3_origin, vec3_origin ); pSprite->SetMoveType( MOVETYPE_NONE ); if ( animate ) pSprite->TurnOn(); return pSprite; }
CBMortar *CBMortar::Shoot( CBaseEntity *pOwner, Vector vecStart, Vector vecVelocity ) { CBMortar *pSpit = CREATE_ENTITY( CBMortar, "bmortar" ); pSpit->Spawn(); UTIL_SetOrigin( pSpit, vecStart ); pSpit->SetAbsVelocity( vecVelocity ); pSpit->SetOwnerEntity( pOwner ); pSpit->SetThink ( &CBMortar::Animate ); pSpit->SetNextThink( gpGlobals->curtime + 0.1 ); return pSpit; }
//----------------------------------------------------------------------------- // Purpose: Get the test hull (create if none) // Input : // Output : //----------------------------------------------------------------------------- CAI_TestHull* CAI_TestHull::GetTestHull(void) { if (!CAI_TestHull::pTestHull) { CAI_TestHull::pTestHull = CREATE_ENTITY( CAI_TestHull, "aitesthull" ); CAI_TestHull::pTestHull->Spawn(); CAI_TestHull::pTestHull->AddFlag( FL_NPC ); } if (CAI_TestHull::pTestHull->bInUse == true) { DevMsg("WARNING: TestHull used and never returned!\n"); Assert( 0 ); } CAI_TestHull::pTestHull->RemoveSolidFlags( FSOLID_NOT_SOLID ); CAI_TestHull::pTestHull->bInUse = true; return CAI_TestHull::pTestHull; }
//------------------------------------------------------------------------------ // Purpose : Given an .mdl file with gibs and the number of gibs in the file // spawns them in pVictim's bounding box // Input : // Output : //------------------------------------------------------------------------------ void CGib::SpawnSpecificGibs( CBaseEntity* pVictim, int nNumGibs, float vMinVelocity, float vMaxVelocity, const char* cModelName, float flLifetime) { for (int i=0;i<nNumGibs;i++) { CGib *pGib = CREATE_ENTITY( CGib, "gib" ); pGib->Spawn( cModelName ); pGib->m_nBody = i; pGib->InitGib( pVictim, vMinVelocity, vMaxVelocity ); pGib->m_lifeTime = flLifetime; if ( pVictim != NULL ) { pGib->SetOwnerEntity( pVictim ); } } }
// create a view animation object to be used for creating an animation. parameter is flags void ViewAnim_Create( void ) { if ( g_pTestAnimation ) { delete g_pTestAnimation; g_pTestAnimation = NULL; } int flags = 0; if (engine->Cmd_Argc() > 1 ) { flags = atoi(engine->Cmd_Argv(1) ); } g_pTestAnimation = CREATE_ENTITY( CViewAngleAnimation, "viewangleanim" ); if ( g_pTestAnimation ) { g_pTestAnimation->Spawn(); } }
cell AMX_NATIVE_CALL Rage::GetFunctionFromClass(AMX* amx,cell* params) { int len; char *func_name = g_fn_GetAmxString(amx,params[1],0,&len); VirtualFunction** virtual_function_ptr = Global::virtualFunctionsManager.get_by_label(func_name); if(!virtual_function_ptr) { MF_LogError(amx, AMX_ERR_NATIVE, "Virtual function %s not registered",func_name); return -1; } VirtualFunction* virtual_function = *virtual_function_ptr; char* class_name = g_fn_GetAmxString(amx,params[2],0,&len); static char class_name_cp[50]; strncpy(class_name_cp,class_name,49); edict_t *entity = CREATE_ENTITY(); CALL_GAME_ENTITY(PLID,class_name,&entity->v); if(!entity->pvPrivateData) { REMOVE_ENTITY(entity); MF_LogError(amx, AMX_ERR_NATIVE,"Unable to create an entity of class '%s'",class_name); return -1; } int ret = virtual_function->create_get_id(entity->pvPrivateData,class_name_cp); REMOVE_ENTITY(entity); return ret; }
void AddNodeEntity(const Vector &origin, int effects) { edict_t *pNode = CREATE_ENTITY(); if (g_fIsMetamod) { CALL_GAME_ENTITY(PLID, "info_node", VARS(pNode)); } else { info_node(VARS(pNode)); } pNode->v.classname = MAKE_STRING("info_node"); SET_ORIGIN(pNode, origin); pNode->v.rendercolor.x = 255; pNode->v.rendercolor.y = 255; pNode->v.rendercolor.z = 0; pNode->v.rendermode = kRenderTransAdd; pNode->v.movetype = MOVETYPE_NONE; pNode->v.solid = SOLID_TRIGGER; SET_SIZE(ENT(&pNode->v), Vector(-8, -8, -8), Vector(8, 8, 8)); pNode->v.renderfx = kRenderFxNoDissipation; pNode->v.renderamt = 255; pNode->v.scale = 0.2; SET_MODEL(ENT(pNode), "sprites/glow02.spr"); pNode->v.effects = effects; }
void ItemPostFrame() { CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>(GetOwner()); if( !pPlayer ) return; if ( pPlayer->m_afButtonReleased & IN_ATTACK ) { CancelPrimaryAttack(); } trace_t tr; Vector eyePos, eyeForward; pPlayer->EyePositionAndVectors( &eyePos, &eyeForward, NULL, NULL ); CTraceFilterSkipTwoEntities traceFilter( pPlayer, this, COLLISION_GROUP_NONE ); UTIL_TraceLine( eyePos, eyePos + eyeForward * MAX_TRACE_LENGTH, MASK_SHOT, &traceFilter, &tr ); if( !m_hBeam ) { if ( gpGlobals->curtime >= m_flBeamTime ) { #ifndef CLIENT_DLL m_hBeam = CREATE_ENTITY( CBeam, "env_beam" ); if ( m_hBeam ) { m_hBeam->BeamInit( "sprites/lgtning.vmt", 6.5f ); m_hBeam->PointEntInit( tr.endpos, pPlayer->GetViewModel(0) ); m_hBeam->SetScrollRate( -10.f ); m_hBeam->SetNoise( 1 ); m_hBeam->SetEndAttachment( LookupAttachment("muzzle") ); m_hBeam->Spawn(); } #endif SendWeaponAnim( ACT_VM_PRIMARYATTACK ); } if ( m_flBeamTime == FLT_MAX ) BaseClass::ItemPostFrame(); } else { if ( gpGlobals->curtime >= m_flDamageTime ) { GetOwner()->RemoveAmmo( 1, GetPrimaryAmmoType() ); #ifndef CLIENT_DLL if( tr.fraction != 1.0 && tr.m_pEnt ) { ClearMultiDamage(); Vector dir = tr.endpos - m_hBeam->GetAbsEndPos(); VectorNormalize( dir ); const float flDamage = BEAM_DAMAGE; CTakeDamageInfo info( m_hBeam, GetOwner(), flDamage, DMG_SHOCK ); CalculateMeleeDamageForce( &info, dir, tr.endpos ); tr.m_pEnt->DispatchTraceAttack( info, dir, &tr ); ApplyMultiDamage(); RadiusDamage( CTakeDamageInfo( m_hBeam, GetOwner(), flDamage * 0.25f, DMG_SHOCK ), tr.endpos, 16.0f, CLASS_NONE, NULL ); } #endif if ( !HasPrimaryAmmo() ) CancelPrimaryAttack(); m_flDamageTime = gpGlobals->curtime + DAMAGE_TICK; } m_hBeam->SetStartPos( tr.endpos ); } }
static cell AMX_NATIVE_CALL RegisterHam(AMX *amx, cell *params) { // Make sure the function we're requesting is within bounds int func=params[1]; int post=params[4]; CHECK_FUNCTION(func); char *function=MF_GetAmxString(amx, params[3], 0, NULL); char *classname=MF_GetAmxString(amx, params[2], 1, NULL); // Check the entity // create an entity, assign it the gamedll's class, hook it and destroy it edict_t *Entity=CREATE_ENTITY(); CALL_GAME_ENTITY(PLID,classname,&Entity->v); if (Entity->pvPrivateData == NULL) { REMOVE_ENTITY(Entity); MF_LogError(amx, AMX_ERR_NATIVE,"Failed to retrieve classtype for \"%s\", hook for \"%s\" not active.",classname,function); return 0; } void **vtable=GetVTable(Entity->pvPrivateData, Offsets.GetBase()); REMOVE_ENTITY(Entity); if (vtable == NULL) { MF_LogError(amx, AMX_ERR_NATIVE,"Failed to retrieve vtable for \"%s\", hook for \"%s\" not active.",classname,function); return 0; } // Verify that the function is valid // Don't fail the plugin if this fails, just emit a normal error int fwd=hooklist[func].makefunc(amx, function); if (fwd == -1) { MF_LogError(amx, AMX_ERR_NATIVE, "Function %s not found.", function); return 0; } // We've passed all tests... int **ivtable=(int **)vtable; void *vfunction=(void *)ivtable[hooklist[func].vtid]; // Check the list of this function's hooks, see if the function we have is a hook CVector<Hook *>::iterator end=hooks[func].end(); for (CVector<Hook *>::iterator i=hooks[func].begin(); i!=end; ++i) { if ((*i)->tramp == vfunction) { // Yes, this function is hooked Forward *pfwd=new Forward(fwd); if (post) { (*i)->post.push_back(pfwd); } else { (*i)->pre.push_back(pfwd); } return reinterpret_cast<cell>(pfwd); } } // If we got here, the function is not hooked Hook *hook=new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].paramcount, classname); hooks[func].push_back(hook); Forward *pfwd=new Forward(fwd); if (post) { hook->post.push_back(pfwd); } else { hook->pre.push_back(pfwd); } return reinterpret_cast<cell>(pfwd); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAPC::Event_Killed( const CTakeDamageInfo &info ) { m_OnDeath.FireOutput( info.GetAttacker(), this ); Vector vecAbsMins, vecAbsMaxs; CollisionProp()->WorldSpaceAABB( &vecAbsMins, &vecAbsMaxs ); Vector vecNormalizedMins, vecNormalizedMaxs; CollisionProp()->WorldToNormalizedSpace( vecAbsMins, &vecNormalizedMins ); CollisionProp()->WorldToNormalizedSpace( vecAbsMaxs, &vecNormalizedMaxs ); Vector vecAbsPoint; CPASFilter filter( GetAbsOrigin() ); for (int i = 0; i < 5; i++) { CollisionProp()->RandomPointInBounds( vecNormalizedMins, vecNormalizedMaxs, &vecAbsPoint ); te->Explosion( filter, random->RandomFloat( 0.0, 1.0 ), &vecAbsPoint, g_sModelIndexFireball, random->RandomInt( 4, 10 ), random->RandomInt( 8, 15 ), ( i < 2 ) ? TE_EXPLFLAG_NODLIGHTS : TE_EXPLFLAG_NOPARTICLES | TE_EXPLFLAG_NOFIREBALLSMOKE | TE_EXPLFLAG_NODLIGHTS, 100, 0 ); } // TODO: make the gibs spawn in sync with the delayed explosions int nGibs = random->RandomInt( 1, 4 ); for ( int i = 0; i < nGibs; i++) { // Throw a flaming, smoking chunk. CGib *pChunk = CREATE_ENTITY( CGib, "gib" ); pChunk->Spawn( "models/gibs/hgibs.mdl" ); pChunk->SetBloodColor( DONT_BLEED ); QAngle vecSpawnAngles; vecSpawnAngles.Random( -90, 90 ); pChunk->SetAbsOrigin( vecAbsPoint ); pChunk->SetAbsAngles( vecSpawnAngles ); int nGib = random->RandomInt( 0, APC_MAX_CHUNKS - 1 ); pChunk->Spawn( s_pChunkModelName[nGib] ); pChunk->SetOwnerEntity( this ); pChunk->m_lifeTime = random->RandomFloat( 6.0f, 8.0f ); pChunk->SetCollisionGroup( COLLISION_GROUP_DEBRIS ); IPhysicsObject *pPhysicsObject = pChunk->VPhysicsInitNormal( SOLID_VPHYSICS, pChunk->GetSolidFlags(), false ); // Set the velocity if ( pPhysicsObject ) { pPhysicsObject->EnableMotion( true ); Vector vecVelocity; QAngle angles; angles.x = random->RandomFloat( -20, 20 ); angles.y = random->RandomFloat( 0, 360 ); angles.z = 0.0f; AngleVectors( angles, &vecVelocity ); vecVelocity *= random->RandomFloat( 300, 900 ); vecVelocity += GetAbsVelocity(); AngularImpulse angImpulse; angImpulse = RandomAngularImpulse( -180, 180 ); pChunk->SetAbsVelocity( vecVelocity ); pPhysicsObject->SetVelocity(&vecVelocity, &angImpulse ); } CEntityFlame *pFlame = CEntityFlame::Create( pChunk, false ); if ( pFlame != NULL ) { pFlame->SetLifetime( pChunk->m_lifeTime ); } } UTIL_ScreenShake( vecAbsPoint, 25.0, 150.0, 1.0, 750.0f, SHAKE_START ); if( hl2_episodic.GetBool() ) { // EP1 perf hit Ignite( 6, false ); } else { Ignite( 60, false ); } m_lifeState = LIFE_DYING; // Spawn a lesser amount if the player is close m_iRocketSalvoLeft = DEATH_VOLLEY_ROCKET_COUNT; m_flRocketTime = gpGlobals->curtime; }
//========================================================= // RunTask //========================================================= void CNPC_Gargantua::RunTask( const Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_DIE: if ( gpGlobals->curtime > m_flWaitFinished ) { //TEMP TEMP m_nRenderFX = kRenderFxExplode; SetRenderColor( 255, 0, 0 , 255 ); StopAnimation(); SetNextThink( gpGlobals->curtime + 0.15 ); SetThink( &CBaseEntity::SUB_Remove ); int i; int parts = modelinfo->GetModelFrameCount( modelinfo->GetModel( gGargGibModel ) ); for ( i = 0; i < 10; i++ ) { CGib *pGib = CREATE_ENTITY( CGib, "gib" ); pGib->Spawn( GARG_GIB_MODEL); int bodyPart = 0; if ( parts > 1 ) bodyPart = random->RandomInt( 0, parts-1 ); pGib->SetBodygroup( 0, bodyPart ); pGib->SetBloodColor( BLOOD_COLOR_YELLOW ); pGib->m_material = matNone; pGib->SetAbsOrigin( GetAbsOrigin() ); pGib->SetAbsVelocity( UTIL_RandomBloodVector() * random->RandomFloat( 300, 500 ) ); pGib->SetNextThink( gpGlobals->curtime + 1.25 ); pGib->SetThink( &CBaseEntity::SUB_FadeOut ); } Vector vecSize = Vector( 200, 200, 128 ); CPVSFilter filter( GetAbsOrigin() ); te->BreakModel( filter, 0.0, GetAbsOrigin(), vec3_angle, vecSize, vec3_origin, gGargGibModel, 200, 50, 3.0, BREAK_FLESH ); return; } else BaseClass::RunTask( pTask ); break; case TASK_FLAME_SWEEP: if ( gpGlobals->curtime > m_flWaitFinished ) { //TEMP TEMP FlameDestroy(); TaskComplete(); FlameControls( 0, 0 ); SetBoneController( 0, 0 ); SetBoneController( 1, 0 ); } else { bool cancel = false; QAngle angles = QAngle( 0, 0, 0 ); //TEMP TEMP FlameUpdate(); CBaseEntity *pEnemy = GetEnemy(); if ( pEnemy ) { Vector org = GetAbsOrigin(); org.z += 64; Vector dir = pEnemy->BodyTarget(org) - org; VectorAngles( dir, angles ); angles.x = -angles.x; angles.y -= GetAbsAngles().y; if ( dir.Length() > 400 ) cancel = true; } if ( fabs(angles.y) > 60 ) cancel = true; if ( cancel ) { m_flWaitFinished -= 0.5; m_flameTime -= 0.5; } //TEMP TEMP //FlameControls( angles.x + 2 * sin(gpGlobals->curtime*8), angles.y + 28 * sin(gpGlobals->curtime*8.5) ); FlameControls( angles.x, angles.y ); } break; default: BaseClass::RunTask( pTask ); break; } }
static cell AMX_NATIVE_CALL RegisterHam(AMX *amx, cell *params) { // Make sure the function we're requesting is within bounds int func=params[1]; int post=params[4]; CHECK_FUNCTION(func); char *function=MF_GetAmxString(amx, params[3], 0, NULL); char *classname=MF_GetAmxString(amx, params[2], 1, NULL); // Check the entity // create an entity, assign it the gamedll's class, hook it and destroy it edict_t *Entity=CREATE_ENTITY(); CALL_GAME_ENTITY(PLID,classname,&Entity->v); if (Entity->pvPrivateData == NULL) { REMOVE_ENTITY(Entity); MF_LogError(amx, AMX_ERR_NATIVE,"Failed to retrieve classtype for \"%s\", hook for \"%s\" not active.",classname,function); return 0; } void **vtable=GetVTable(Entity->pvPrivateData, Offsets.GetBase()); REMOVE_ENTITY(Entity); if (vtable == NULL) { MF_LogError(amx, AMX_ERR_NATIVE,"Failed to retrieve vtable for \"%s\", hook for \"%s\" not active.",classname,function); return 0; } // Verify that the function is valid // Don't fail the plugin if this fails, just emit a normal error int fwd=hooklist[func].makefunc(amx, function); if (fwd == -1) { MF_LogError(amx, AMX_ERR_NATIVE, "Function %s not found.", function); return 0; } bool enableSpecialBot = false; // Old plugin doesn't have this param. if (*params / sizeof(cell) == 5) { enableSpecialBot = params[5] > 0; } Forward *pfwd = new Forward(fwd); // We've passed all tests... if (strcmp(classname, "player") == 0 && enableSpecialBot) { SpecialbotHandler.RegisterHamSpecialBot(amx, func, function, post, pfwd); } int **ivtable=(int **)vtable; void *vfunction=(void *)ivtable[hooklist[func].vtid]; // Check the list of this function's hooks, see if the function we have is a hook for (size_t i = 0; i < hooks[func].length(); ++i) { if (hooks[func].at(i)->tramp == vfunction) { // Yes, this function is hooked if (post) { hooks[func].at(i)->post.append(pfwd); } else { hooks[func].at(i)->pre.append(pfwd); } return reinterpret_cast<cell>(pfwd); } } // If we got here, the function is not hooked Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname); hooks[func].append(hook); if (post) { hook->post.append(pfwd); } else { hook->pre.append(pfwd); } return reinterpret_cast<cell>(pfwd); }
//----------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------- void CPlayerCar::Spawn( bool bPlayerOneCar, bool bPlayerTwoCar ) { m_vResetPosition = GetOrigin(); m_aResetAngles = GetAngle(); char pchScriptFile[] = "scripts/car.rps"; CScriptParser parser; if( !parser.ParseFile( pchScriptFile ) ) { error( "Error loading Car-Script \"%s\"", pchScriptFile ); return; } std::string filename; parser.GetString("model", filename); SetFilename(filename.c_str()); char pchWheel[128]; parser.GetString( "wheelmodel", pchWheel, ArrayLength(pchWheel) ); //Create wheels for( int i = 0; i < 4; i++ ) { m_pWheels[i] = CREATE_ENTITY(CStaticModel); m_pWheels[i]->SetFilename( pchWheel ); m_pWheels[i]->Spawn(); } //Calculate BB //Vector3f vMins( -22.0801f, 4.3f, -10.3831f ); //Vector3f vMaxs( 20.001f, 19.922f, 10.3737f ); //TODO: generalize this Vector3f vMins( -10.3737f, 4.3f, -22.0801f ); Vector3f vMaxs( 10.3831f, 19.922f, 20.001f ); Vector3f pvVerts[8]; pvVerts[0].Init( vMins.x, vMins.y, vMins.z ); pvVerts[1].Init( vMins.x, vMins.y, vMaxs.z ); pvVerts[2].Init( vMins.x, vMaxs.y, vMins.z ); pvVerts[3].Init( vMins.x, vMaxs.y, vMaxs.z ); pvVerts[4].Init( vMaxs.x, vMins.y, vMins.z ); pvVerts[5].Init( vMaxs.x, vMins.y, vMaxs.z ); pvVerts[6].Init( vMaxs.x, vMaxs.y, vMins.z ); pvVerts[7].Init( vMaxs.x, vMaxs.y, vMaxs.z ); //char testval[256]; parser.FindSubString( "Max" ); m_info.mass = parser.GetFloat( "mass" ); m_info.maxEngineForce = parser.GetFloat( "MaxEngineForce" ); //this should be engine/velocity dependent m_info.maxBreakingForce = parser.GetFloat( "MaxBreakingForce" ); m_info.steeringClamp = parser.GetFloat( "SteeringClamp" ); m_info.wheelRadius = parser.GetFloat( "WheelRadius" ); m_info.wheelWidth = parser.GetFloat( "WheelWidth" ); m_info.wheelFriction = parser.GetFloat( "WheelFriction" ); m_info.suspensionStiffness = parser.GetFloat( "SuspensionStiffness" ); m_info.suspensionDamping = parser.GetFloat( "SuspensionDamping" ); m_info.suspensionCompression = parser.GetFloat( "SuspensionCompression" ); m_info.rollInfluence = parser.GetFloat( "RollInfluence" ); m_info.suspensionRestLength = parser.GetFloat( "SuspensionRestLength" ); m_info.suspensionMaxTravel = parser.GetFloat( "SuspensionMaxTravel" ); //25 cm m_info.suspensionForce = parser.GetFloat( "SuspensionForce" ); m_info.suspensionMaxForce = parser.GetFloat( "SuspensionMaxForce" ); m_info.motorHorsePower = parser.GetFloat( "HorsePower" ); m_info.motorMaxRpm = parser.GetFloat( "MaxRpm" ); m_info.motorMinRpm = parser.GetFloat( "MinRpm" ); m_info.motorShiftDownRpm = parser.GetFloat( "ShiftDownRpm" ); m_info.motorShiftUpRpm = parser.GetFloat( "ShiftUpRpm" ); m_info.numberOfGears = parser.GetInt( "NumberOfGears" ); m_info.gearRatios[0] = parser.GetFloat( "Gear1Ratio" ); m_info.gearRatios[1] = parser.GetFloat( "Gear2Ratio" ); m_info.gearRatios[2] = parser.GetFloat( "Gear3Ratio" ); m_info.gearRatios[3] = parser.GetFloat( "Gear4Ratio" ); m_info.gearRatios[4] = parser.GetFloat( "Gear5Ratio" ); m_info.gearRatios[5] = parser.GetFloat( "Gear6Ratio" ); m_info.gearRatios[6] = parser.GetFloat( "Gear7Ratio" ); m_info.axleRatio = parser.GetFloat( "AxleRatio" ); m_info.cwValue = parser.GetFloat( "cwValue" ); m_info.faceSurface = parser.GetFloat( "faceSurface" ); float pfCenterOfMass[3]; parser.GetFloats( "CenterOfMassOffset", 3, pfCenterOfMass ); m_info.vMassCenterOfs = Vector3f( pfCenterOfMass ); //Calculate Wheel positions float fAxisDistFront = parser.GetFloat( "AxisDistFront" ); float fAxisDistRear = parser.GetFloat( "AxisDistRear" ); float fAxisWidthFront = parser.GetFloat( "AxisWidthFront" ); float fAxisWidthRear = parser.GetFloat( "AxisWidthRear" ); float fAxisHeightOffsetFront = parser.GetFloat( "AxisHeightOffsetFront" ); float fAxisHeightOffsetRear = parser.GetFloat( "AxisHeightOffsetRear" ); m_info.vWheelPos[0] = Vector3f( fAxisWidthFront*0.5f, fAxisHeightOffsetFront, fAxisDistFront ); //FL m_info.vWheelPos[1] = Vector3f( -fAxisWidthFront*0.5f, fAxisHeightOffsetFront, fAxisDistFront ); //FR m_info.vWheelPos[2] = Vector3f( fAxisWidthRear*0.5f, fAxisHeightOffsetRear, -fAxisDistRear ); //RL m_info.vWheelPos[3] = Vector3f( -fAxisWidthRear*0.5f, fAxisHeightOffsetRear, -fAxisDistRear ); //RR m_pPhysVehicle = ((CBulletPhysics*)g_pPhysics)->CreateVehicle( this, (CBaseEntity**)m_pWheels, pvVerts, 8, m_info ); BaseClass::Spawn(); }