Skip to content

Commit 526c35c

Browse files
authored
Merge pull request #858 from ReactiveDrop/die-vscript-func
Die() vscript function for inhabitable npcs
2 parents 8ccc0ca + 6e48849 commit 526c35c

5 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/game/server/basecombatcharacter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ int CBaseCombatCharacter::OnTakeDamage_Alive( const CTakeDamageInfo &info )
22742274
float flDamage = info.GetDamage();
22752275
CBaseEntity* pInflictor = info.GetInflictor();
22762276
#ifdef RD_VSCRIPT_INTERCEPT_ENTITY_DAMAGE
2277-
if ( m_ScriptScope.IsInitialized() && m_ScriptScope.ValueExists( "OnTakeDamage_Alive" ) )
2277+
if ( m_ScriptScope.IsInitialized() && m_ScriptScope.ValueExists( "OnTakeDamage_Alive" ) && info.GetCallVScriptHook() )
22782278
{
22792279
ScriptVariant_t newDamage;
22802280
ScriptStatus_t nStatus = m_ScriptScope.Call( "OnTakeDamage_Alive", &newDamage, ToHScript( pInflictor ), ToHScript( info.GetAttacker() ), ToHScript( info.GetWeapon() ), flDamage, info.GetDamageType(), info.GetAmmoName() );
@@ -2287,7 +2287,9 @@ int CBaseCombatCharacter::OnTakeDamage_Alive( const CTakeDamageInfo &info )
22872287
newDamage.AssignTo( &flDamage );
22882288
}
22892289
}
2290-
if ( CAlienSwarm *pAlienSwarm = ASWGameRules() )
2290+
2291+
CAlienSwarm *pAlienSwarm = ASWGameRules();
2292+
if ( pAlienSwarm && info.GetCallVScriptHook() )
22912293
{
22922294
ScriptVariant_t args[7];
22932295

src/game/server/swarm/asw_inhabitable_npc.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ BEGIN_ENT_SCRIPTDESC( CASW_Inhabitable_NPC, CBaseCombatCharacter, "Alien Swarm I
151151
DEFINE_SCRIPTFUNC( SetHealthBarColor, "Sets the health bar color. Cheaper than spawning an asw_health_bar. Set alpha to 0 to disable the health bar." )
152152
DEFINE_SCRIPTFUNC( SetHealthBarScale, "Sets the health bar scale. Negative scales hide the health bar if the alien's health is full." )
153153
DEFINE_SCRIPTFUNC( SetHealthBarOffset, "Sets the health bar offset in local space." )
154+
DEFINE_SCRIPTFUNC( Die, "Simple kill function for aliens and marines." )
154155
END_SCRIPTDESC()
155156

156157
CASW_Inhabitable_NPC::CASW_Inhabitable_NPC()
@@ -344,6 +345,19 @@ void CASW_Inhabitable_NPC::Suicide()
344345
TakeDamage( info );
345346
}
346347

348+
void CASW_Inhabitable_NPC::Die()
349+
{
350+
if ( !IsAlive() )
351+
return;
352+
353+
SetHealth( 1 );
354+
355+
CTakeDamageInfo info( NULL, NULL, 100, DMG_FALL );
356+
info.SetCallVScriptHook( false );
357+
358+
TakeDamage( info );
359+
}
360+
347361
// using entities over time
348362
bool CASW_Inhabitable_NPC::StartUsing( CBaseEntity *pEntity )
349363
{

src/game/server/swarm/asw_inhabitable_npc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class CASW_Inhabitable_NPC : public CAI_PlayerAlly, public IASW_Spawnable_NPC
5050
char m_szInitialCommanderNetworkID[64]; // ASWNetworkID of the first commander for this marine in this mission
5151
const char *GetPlayerName() const;
5252
virtual void Suicide();
53+
void Die();
5354

5455
// gun
5556
CASW_Weapon *GetASWWeapon( int index ) const;

src/game/shared/takedamageinfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ BEGIN_SIMPLE_DATADESC( CTakeDamageInfo )
2929
DEFINE_FIELD( m_iDamageStats, FIELD_INTEGER),
3030
DEFINE_FIELD( m_iAmmoType, FIELD_INTEGER),
3131
DEFINE_FIELD( m_flRadius, FIELD_FLOAT),
32+
DEFINE_FIELD( m_bCallVScriptHook, FIELD_BOOLEAN),
3233
END_DATADESC()
3334

3435
void CTakeDamageInfo::Init( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, const Vector &damageForce, const Vector &damagePosition, const Vector &reportedPosition, float flDamage, int bitsDamageType, int iCustomDamage )
@@ -58,6 +59,7 @@ void CTakeDamageInfo::Init( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBa
5859
m_vecReportedPosition = reportedPosition;
5960
m_iAmmoType = -1;
6061
m_flRadius = 0.0f;
62+
m_bCallVScriptHook = true;
6163
}
6264

6365
CTakeDamageInfo::CTakeDamageInfo()

src/game/shared/takedamageinfo.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class CTakeDamageInfo
8383
float GetRadius() const;
8484
void SetRadius( float fRadius );
8585

86+
bool GetCallVScriptHook() const;
87+
void SetCallVScriptHook( bool bCall );
88+
8689
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType, int iKillType = 0 );
8790
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, float flDamage, int bitsDamageType, int iKillType = 0 );
8891
void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL );
@@ -116,6 +119,7 @@ class CTakeDamageInfo
116119
int m_iDamageStats;
117120
int m_iAmmoType; // AmmoType of the weapon used to cause this damage, if any
118121
float m_flRadius;
122+
bool m_bCallVScriptHook;
119123

120124
DECLARE_SIMPLE_DATADESC();
121125
};
@@ -344,6 +348,16 @@ inline void CTakeDamageInfo::SetRadius( float flRadius )
344348
m_flRadius = flRadius;
345349
}
346350

351+
inline bool CTakeDamageInfo::GetCallVScriptHook() const
352+
{
353+
return m_bCallVScriptHook;
354+
}
355+
356+
inline void CTakeDamageInfo::SetCallVScriptHook( bool bCall )
357+
{
358+
m_bCallVScriptHook = bCall;
359+
}
360+
347361

348362
// -------------------------------------------------------------------------------------------------- //
349363
// Inlines.

0 commit comments

Comments
 (0)