From 8e283f3738e35018f909c2c210b3b73101d2e0d8 Mon Sep 17 00:00:00 2001 From: Blixibon Date: Sat, 23 Jan 2021 09:20:21 -0600 Subject: [PATCH] Added OnServerRagdoll hook for VScript --- sp/src/game/server/baseanimating.cpp | 9 +++++++++ sp/src/game/server/baseanimating.h | 2 ++ sp/src/game/server/physics_prop_ragdoll.cpp | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/sp/src/game/server/baseanimating.cpp b/sp/src/game/server/baseanimating.cpp index 753cfc6a..f16744f1 100644 --- a/sp/src/game/server/baseanimating.cpp +++ b/sp/src/game/server/baseanimating.cpp @@ -282,6 +282,10 @@ IMPLEMENT_SERVERCLASS_ST(CBaseAnimating, DT_BaseAnimating) END_SEND_TABLE() +#ifdef MAPBASE_VSCRIPT +ScriptHook_t CBaseAnimating::g_Hook_OnServerRagdoll; +#endif + BEGIN_ENT_SCRIPTDESC( CBaseAnimating, CBaseEntity, "Animating models" ) DEFINE_SCRIPTFUNC( LookupAttachment, "Get the named attachement id" ) @@ -333,6 +337,11 @@ BEGIN_ENT_SCRIPTDESC( CBaseAnimating, CBaseEntity, "Animating models" ) DEFINE_SCRIPTFUNC( BecomeRagdollOnClient, "" ) DEFINE_SCRIPTFUNC( IsRagdoll, "" ) DEFINE_SCRIPTFUNC( CanBecomeRagdoll, "" ) + + BEGIN_SCRIPTHOOK( CBaseAnimating::g_Hook_OnServerRagdoll, "OnServerRagdoll", FIELD_VOID, "Called when this entity creates/turns into a server-side ragdoll." ) + DEFINE_SCRIPTHOOK_PARAM( "ragdoll", FIELD_HSCRIPT ) + DEFINE_SCRIPTHOOK_PARAM( "submodel", FIELD_BOOLEAN ) + END_SCRIPTHOOK() #endif END_SCRIPTDESC(); diff --git a/sp/src/game/server/baseanimating.h b/sp/src/game/server/baseanimating.h index 8f640827..8513d886 100644 --- a/sp/src/game/server/baseanimating.h +++ b/sp/src/game/server/baseanimating.h @@ -209,6 +209,8 @@ public: // For VScript int GetSkin() { return m_nSkin; } void SetSkin( int iSkin ) { m_nSkin = iSkin; } + + static ScriptHook_t g_Hook_OnServerRagdoll; #endif // These return the attachment in the space of the entity diff --git a/sp/src/game/server/physics_prop_ragdoll.cpp b/sp/src/game/server/physics_prop_ragdoll.cpp index 0844f7b7..78dd812c 100644 --- a/sp/src/game/server/physics_prop_ragdoll.cpp +++ b/sp/src/game/server/physics_prop_ragdoll.cpp @@ -1353,6 +1353,16 @@ CBaseAnimating *CreateServerRagdollSubmodel( CBaseAnimating *pOwner, const char matrix3x4_t pBoneToWorld[MAXSTUDIOBONES], pBoneToWorldNext[MAXSTUDIOBONES]; pRagdoll->ResetSequence( 0 ); +#ifdef MAPBASE_VSCRIPT + // Hook for pre-spawn ragdolling + if (pOwner->m_ScriptScope.IsInitialized() && CBaseAnimating::g_Hook_OnServerRagdoll.CanRunInScope( pOwner->m_ScriptScope )) + { + // ragdoll, submodel + ScriptVariant_t args[] = { ScriptVariant_t( pRagdoll->GetScriptInstance() ), true }; + CBaseAnimating::g_Hook_OnServerRagdoll.Call( pOwner->m_ScriptScope, NULL, args ); + } +#endif + // let bone merging do the work of copying everything over for us pRagdoll->SetParent( pOwner ); pRagdoll->SetupBones( pBoneToWorld, BONE_USED_BY_ANYTHING ); @@ -1377,6 +1387,16 @@ CBaseEntity *CreateServerRagdoll( CBaseAnimating *pAnimating, int forceBone, con pRagdoll->CopyAnimationDataFrom( pAnimating ); pRagdoll->SetOwnerEntity( pAnimating ); +#ifdef MAPBASE_VSCRIPT + // Hook for pre-spawn ragdolling + if (pAnimating->m_ScriptScope.IsInitialized() && CBaseAnimating::g_Hook_OnServerRagdoll.CanRunInScope( pAnimating->m_ScriptScope )) + { + // ragdoll, submodel + ScriptVariant_t args[] = { ScriptVariant_t( pRagdoll->GetScriptInstance() ), false }; + CBaseAnimating::g_Hook_OnServerRagdoll.Call( pAnimating->m_ScriptScope, NULL, args ); + } +#endif + pRagdoll->InitRagdollAnimation(); matrix3x4_t pBoneToWorld[MAXSTUDIOBONES], pBoneToWorldNext[MAXSTUDIOBONES];