mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2025-02-24 20:51:08 +03:00
Reworked the OnDeath VScript hook so it could cheat death properly
This commit is contained in:
parent
6f515a2d34
commit
8ad19cbf0a
@ -1725,25 +1725,6 @@ Killed
|
|||||||
*/
|
*/
|
||||||
void CBaseCombatCharacter::Event_Killed( const CTakeDamageInfo &info )
|
void CBaseCombatCharacter::Event_Killed( const CTakeDamageInfo &info )
|
||||||
{
|
{
|
||||||
#ifdef MAPBASE_VSCRIPT
|
|
||||||
if (m_ScriptScope.IsInitialized() && g_Hook_OnDeath.CanRunInScope( m_ScriptScope ))
|
|
||||||
{
|
|
||||||
HSCRIPT hInfo = g_pScriptVM->RegisterInstance( const_cast<CTakeDamageInfo*>(&info) );
|
|
||||||
|
|
||||||
// info
|
|
||||||
ScriptVariant_t functionReturn;
|
|
||||||
ScriptVariant_t args[] = { ScriptVariant_t( hInfo ) };
|
|
||||||
if ( g_Hook_OnDeath.Call( m_ScriptScope, &functionReturn, args ) && (functionReturn.m_type == FIELD_BOOLEAN && functionReturn.m_bool == false) )
|
|
||||||
{
|
|
||||||
// Make this entity cheat death
|
|
||||||
g_pScriptVM->RemoveInstance( hInfo );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_pScriptVM->RemoveInstance( hInfo );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern ConVar npc_vphysics;
|
extern ConVar npc_vphysics;
|
||||||
|
|
||||||
// Advance life state to dying
|
// Advance life state to dying
|
||||||
@ -2893,6 +2874,12 @@ int CBaseCombatCharacter::OnTakeDamage( const CTakeDamageInfo &info )
|
|||||||
#endif
|
#endif
|
||||||
if ( m_iHealth <= 0 )
|
if ( m_iHealth <= 0 )
|
||||||
{
|
{
|
||||||
|
#ifdef MAPBASE_VSCRIPT
|
||||||
|
// False = Cheat death
|
||||||
|
if (ScriptDeathHook( const_cast<CTakeDamageInfo*>(&info) ) == false)
|
||||||
|
return retVal;
|
||||||
|
#endif
|
||||||
|
|
||||||
IPhysicsObject *pPhysics = VPhysicsGetObject();
|
IPhysicsObject *pPhysics = VPhysicsGetObject();
|
||||||
if ( pPhysics )
|
if ( pPhysics )
|
||||||
{
|
{
|
||||||
|
@ -1719,22 +1719,9 @@ int CBaseEntity::VPhysicsTakeDamage( const CTakeDamageInfo &info )
|
|||||||
void CBaseEntity::Event_Killed( const CTakeDamageInfo &info )
|
void CBaseEntity::Event_Killed( const CTakeDamageInfo &info )
|
||||||
{
|
{
|
||||||
#ifdef MAPBASE_VSCRIPT
|
#ifdef MAPBASE_VSCRIPT
|
||||||
if (m_ScriptScope.IsInitialized() && g_Hook_OnDeath.CanRunInScope( m_ScriptScope ))
|
// False = Cheat death
|
||||||
{
|
if (ScriptDeathHook( const_cast<CTakeDamageInfo*>(&info) ) == false)
|
||||||
HSCRIPT hInfo = g_pScriptVM->RegisterInstance( const_cast<CTakeDamageInfo*>(&info) );
|
return;
|
||||||
|
|
||||||
// info
|
|
||||||
ScriptVariant_t functionReturn;
|
|
||||||
ScriptVariant_t args[] = { ScriptVariant_t( hInfo ) };
|
|
||||||
if ( g_Hook_OnDeath.Call( m_ScriptScope, &functionReturn, args ) && (functionReturn.m_type == FIELD_BOOLEAN && functionReturn.m_bool == false) )
|
|
||||||
{
|
|
||||||
// Make this entity cheat death
|
|
||||||
g_pScriptVM->RemoveInstance( hInfo );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_pScriptVM->RemoveInstance( hInfo );
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( info.GetAttacker() )
|
if( info.GetAttacker() )
|
||||||
@ -4668,6 +4655,16 @@ bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAPBASE_VSCRIPT
|
||||||
|
bool CBaseEntity::ScriptAcceptInput( const char *szInputName, const char *szValue, HSCRIPT hActivator, HSCRIPT hCaller )
|
||||||
|
{
|
||||||
|
variant_t value;
|
||||||
|
value.SetString( MAKE_STRING( szValue ) );
|
||||||
|
|
||||||
|
return AcceptInput( szInputName, ToEnt( hActivator ), ToEnt( hCaller ), value, 0 );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -4700,12 +4697,26 @@ bool CBaseEntity::ScriptInputHook( const char *szInputName, CBaseEntity *pActiva
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAPBASE_VSCRIPT
|
#ifdef MAPBASE_VSCRIPT
|
||||||
bool CBaseEntity::ScriptAcceptInput( const char *szInputName, const char *szValue, HSCRIPT hActivator, HSCRIPT hCaller )
|
bool CBaseEntity::ScriptDeathHook( CTakeDamageInfo *info )
|
||||||
{
|
{
|
||||||
variant_t value;
|
if (m_ScriptScope.IsInitialized() && g_Hook_OnDeath.CanRunInScope( m_ScriptScope ))
|
||||||
value.SetString( MAKE_STRING(szValue) );
|
{
|
||||||
|
HSCRIPT hInfo = g_pScriptVM->RegisterInstance( info );
|
||||||
|
|
||||||
return AcceptInput( szInputName, ToEnt(hActivator), ToEnt(hCaller), value, 0 );
|
// info
|
||||||
|
ScriptVariant_t functionReturn;
|
||||||
|
ScriptVariant_t args[] = { ScriptVariant_t( hInfo ) };
|
||||||
|
if ( g_Hook_OnDeath.Call( m_ScriptScope, &functionReturn, args ) && (functionReturn.m_type == FIELD_BOOLEAN && functionReturn.m_bool == false) )
|
||||||
|
{
|
||||||
|
// Make this entity cheat death
|
||||||
|
g_pScriptVM->RemoveInstance( hInfo );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pScriptVM->RemoveInstance( hInfo );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -693,6 +693,9 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool ScriptInputHook( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, ScriptVariant_t &functionReturn );
|
bool ScriptInputHook( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, ScriptVariant_t &functionReturn );
|
||||||
|
#ifdef MAPBASE_VSCRIPT
|
||||||
|
bool ScriptDeathHook( CTakeDamageInfo *info );
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Input handlers.
|
// Input handlers.
|
||||||
|
@ -689,9 +689,15 @@ int CCombineDropshipContainer::OnTakeDamage( const CTakeDamageInfo &info )
|
|||||||
|
|
||||||
if ( m_iHealth <= 0 )
|
if ( m_iHealth <= 0 )
|
||||||
{
|
{
|
||||||
m_iHealth = 0;
|
#ifdef MAPBASE_VSCRIPT
|
||||||
Event_Killed( dmgInfo );
|
// False = Cheat death
|
||||||
return 0;
|
if (ScriptDeathHook( const_cast<CTakeDamageInfo*>(&info) ) != false)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
m_iHealth = 0;
|
||||||
|
Event_Killed( dmgInfo );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn damage effects
|
// Spawn damage effects
|
||||||
|
@ -561,9 +561,15 @@ int CPropAPC::OnTakeDamage( const CTakeDamageInfo &info )
|
|||||||
m_iHealth -= dmgInfo.GetDamage();
|
m_iHealth -= dmgInfo.GetDamage();
|
||||||
if ( m_iHealth <= 0 )
|
if ( m_iHealth <= 0 )
|
||||||
{
|
{
|
||||||
m_iHealth = 0;
|
#ifdef MAPBASE_VSCRIPT
|
||||||
Event_Killed( dmgInfo );
|
// False = Cheat death
|
||||||
return 0;
|
if (ScriptDeathHook( const_cast<CTakeDamageInfo*>(&info) ) != false)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
m_iHealth = 0;
|
||||||
|
Event_Killed( dmgInfo );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chain
|
// Chain
|
||||||
|
Loading…
x
Reference in New Issue
Block a user