Skip to content

Commit

Permalink
Updated CDeathHandler and some include stuff
Browse files Browse the repository at this point in the history
Added Clientsided ragdoll tracking, this is handled by the client so it don't always track, also keeps ragdoll velocity this is also clientsided so not always.
  • Loading branch information
LuxLuma committed Sep 18, 2018
1 parent b95c364 commit e67837a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 34 deletions.
73 changes: 42 additions & 31 deletions addons/sourcemod/scripting/LMCL4D2CDeathHandler.sp
Expand Up @@ -4,19 +4,19 @@
#include <sdkhooks>

#define REQUIRE_PLUGIN
#include <LMCCore>
#include <LMCL4D2SetTransmit>
#include <LMCCore>
#undef REQUIRE_PLUGIN

#pragma newdecls required


#define PLUGIN_NAME "LMCL4D2CDeathHandler"
#define PLUGIN_VERSION "1.1.1"

#define PLUGIN_VERSION "1.1.4"


static int iDeathModelRef = INVALID_ENT_REFERENCE;
static int iCSRagdollRef = INVALID_ENT_REFERENCE;
static bool bIgnore = false;

Handle g_hOnClientDeathModelCreated = INVALID_HANDLE;
Expand Down Expand Up @@ -50,27 +50,47 @@ public void OnPluginStart()
HookEvent("player_death", ePlayerDeath);
}

public void Cs_Ragdollhandler(int iRagdoll, int iClient)
{
SDKUnhook(iRagdoll, SDKHook_SetTransmit, Cs_Ragdollhandler);
int iOwner = GetEntPropEnt(iRagdoll, Prop_Send, "m_hPlayer");
if(iOwner < 1 || iOwner > MaxClients)
return;

SetEntProp(iOwner, Prop_Send, "m_nModelIndex", GetEntProp(iRagdoll, Prop_Send, "m_nModelIndex", 2), 2);// should i make a forward for this?
}

public void ePlayerDeath(Handle hEvent, const char[] sEventName, bool bDontBroadcast)
{
int iVictim = GetClientOfUserId(GetEventInt(hEvent, "userid"));
if(iVictim < 1 || iVictim > MaxClients || !IsClientInGame(iVictim))
return;

int iTeam = GetClientTeam(iVictim);
int iEntity = LMC_GetClientOverlayModel(iVictim);
if(iTeam != 2 && iTeam != 3)
return;

if(iTeam == 3 && IsValidEntity(iEntity))
int iEntity = LMC_GetClientOverlayModel(iVictim);
if(IsValidEntity(iEntity) && IsValidEntRef(iCSRagdollRef) && iVictim == GetEntPropEnt(iCSRagdollRef, Prop_Send, "m_hPlayer"))
{
LMC_L4D2_SetTransmit(iVictim, iEntity, false);
AcceptEntityInput(iEntity, "ClearParent");
SetEntProp(iEntity, Prop_Send, "m_bClientSideRagdoll", 1, 1);
SetVariantString("OnUser1 !self:Kill::0.1:1");
AcceptEntityInput(iEntity, "AddOutput");
AcceptEntityInput(iEntity, "FireUser1");
int iRagdoll = EntRefToEntIndex(iCSRagdollRef);
iCSRagdollRef = INVALID_ENT_REFERENCE;
iDeathModelRef = INVALID_ENT_REFERENCE;

SetEntProp(iRagdoll, Prop_Send, "m_nModelIndex", GetEntProp(iEntity, Prop_Send, "m_nModelIndex", 2), 2);
SetEntProp(iRagdoll, Prop_Send, "m_ragdollType", 1);
SDKHook(iRagdoll, SDKHook_SetTransmit, Cs_Ragdollhandler);

LMC_ResetRenderMode(iVictim);
AcceptEntityInput(iEntity, "Kill");

iCSRagdollRef = INVALID_ENT_REFERENCE;
iDeathModelRef = INVALID_ENT_REFERENCE;
return;
}

if(iTeam == 2 && IsValidEntRef(iDeathModelRef))
//sm_ted_spawnhook cs_ragdoll
if(IsValidEntRef(iDeathModelRef))
{
float fPos[3];
GetClientAbsOrigin(iVictim, fPos);
Expand Down Expand Up @@ -101,34 +121,25 @@ public void ePlayerDeath(Handle hEvent, const char[] sEventName, bool bDontBroad
return;
}

if(!IsValidEntity(iEntity) || iTeam != 2)
return;

SetEntProp(iEntity, Prop_Send, "m_nGlowRange", 0);
SetEntProp(iEntity, Prop_Send, "m_iGlowType", 0);
SetEntProp(iEntity, Prop_Send, "m_glowColorOverride", 0);
SetEntProp(iEntity, Prop_Send, "m_nGlowRangeMin", 0);

LMC_L4D2_SetTransmit(iVictim, iEntity, false);

AcceptEntityInput(iEntity, "ClearParent");
SetEntProp(iEntity, Prop_Send, "m_bClientSideRagdoll", 1, 1);
SetVariantString("OnUser1 !self:Kill::0.1:1");
AcceptEntityInput(iEntity, "AddOutput");
AcceptEntityInput(iEntity, "FireUser1");
if(IsValidEntity(iEntity))
AcceptEntityInput(iEntity, "Kill");
}

public void OnEntityCreated(int iEntity, const char[] sClassname)
{
if(sClassname[0] != 's' || !StrEqual(sClassname, "survivor_death_model", false))
if(sClassname[0] != 's' && sClassname[0] != 'c')
return;

SDKHook(iEntity, SDKHook_SpawnPost, SpawnPost);
if(StrEqual(sClassname, "cs_ragdoll", false))
iCSRagdollRef = EntIndexToEntRef(iEntity);

if(StrEqual(sClassname, "survivor_death_model", false))
SDKHook(iEntity, SDKHook_SpawnPost, SpawnPostDeathModel);
}

public void SpawnPost(int iEntity)
public void SpawnPostDeathModel(int iEntity)
{
SDKUnhook(iEntity, SDKHook_SpawnPost, SpawnPost);
SDKUnhook(iEntity, SDKHook_SpawnPost, SpawnPostDeathModel);
if(!IsValidEntity(iEntity))
return;

Expand Down
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/LMC_L4D2_RandomSpawns.sp
Expand Up @@ -3,9 +3,9 @@
#include <sdktools>

#define REQUIRE_PLUGIN
#include <LMCCore>
#include <LMCL4D2CDeathHandler>
#include <LMCL4D2SetTransmit>
#include <LMCCore>
#undef REQUIRE_PLUGIN

#pragma newdecls required
Expand Down
21 changes: 20 additions & 1 deletion addons/sourcemod/scripting/include/LMCCore.inc
Expand Up @@ -22,8 +22,17 @@
#define _LMCCore_included


#define LMCCore_version "2.5.1"
#define LMCCore_version "2.5.2"

#if defined REQUIRE_PLUGIN
#undef REQUIRE_PLUGIN
#include <LMCL4D2SetTransmit>
#include <LMCL4D2CDeathHandler>
#define REQUIRE_PLUGIN
#else
#include <LMCL4D2SetTransmit>
#include <LMCL4D2CDeathHandler>
#endif


/**
Expand Down Expand Up @@ -204,3 +213,13 @@ public void __pl_LMCCore_SetNTVOptional()
MarkNativeAsOptional("LMC_HideClientOverlayModel");
}
#endif

#if defined REQUIRE_PLUGIN
#undef REQUIRE_PLUGIN
#include <LMCL4D2SetTransmit>
#include <LMCL4D2CDeathHandler>
#define REQUIRE_PLUGIN
#else
#include <LMCL4D2SetTransmit>
#include <LMCCore>
#endif
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/include/LMCL4D2SetTransmit.inc
Expand Up @@ -10,7 +10,7 @@
#endif
#define _LMCL4D2SetTransmit_included

#define LMCL4D2SetTransmit_version "1.0"
#define LMCL4D2SetTransmit_version "1.0.1"

/**
* Unhook/hook LMC's SetTransmit in LMCL4D2SetTransmit module
Expand Down

0 comments on commit e67837a

Please sign in to comment.