forked from jeremyvillanuevar/scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMCL4D1CDeathHandler.sp
More file actions
122 lines (96 loc) · 3.59 KB
/
LMCL4D1CDeathHandler.sp
File metadata and controls
122 lines (96 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* LMCL4D1CDeathHandler - Manages deaths regarding lmc, overlay ragdolls
* Copyright (C) 2019 LuxLuma acceliacat@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define REQUIRE_PLUGIN
#include <LMCCore>
#undef REQUIRE_PLUGIN
#pragma newdecls required
#define PLUGIN_NAME "LMCL4D1CDeathHandler"
#define PLUGIN_VERSION "1.1.1"
static char sModelStrings[MAXPLAYERS+1][PLATFORM_MAX_PATH];
static int iCSRagdollRef = INVALID_ENT_REFERENCE;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(GetEngineVersion() != Engine_Left4Dead)
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = "Lux",
description = "Manages deaths regarding lmc, overlay ragdolls",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?p=2607394"
};
public void OnPluginStart()
{
CreateConVar("lmcl4d1cdeathhandler_version", PLUGIN_VERSION, "LMCL4D1CDeathHandler_version", FCVAR_DONTRECORD|FCVAR_NOTIFY);
HookEvent("player_death", ePlayerDeath);
}
public Action SpawnHook(int iClient)
{
SDKUnhook(iClient, SDKHook_Spawn, SpawnHook);
SetEntityModel(iClient, sModelStrings[iClient]);
}
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;
GetEntPropString(iOwner, Prop_Data, "m_ModelName", sModelStrings[iOwner], PLATFORM_MAX_PATH);
SDKHook(iOwner, SDKHook_Spawn, SpawnHook);
SetEntProp(iOwner, Prop_Send, "m_nModelIndex", GetEntProp(iRagdoll, Prop_Send, "m_nModelIndex", 2), 2);
}
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);
if(iTeam != 2 && iTeam != 3)
return;
int iEntity = LMC_GetClientOverlayModel(iVictim);
if(iEntity < MaxClients || !IsValidEntRef(iCSRagdollRef) || iVictim != GetEntPropEnt(iCSRagdollRef, Prop_Send, "m_hPlayer"))
return;
int iRagdoll = EntRefToEntIndex(iCSRagdollRef);
iCSRagdollRef = 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");
}
public void OnEntityCreated(int iEntity, const char[] sClassname)
{
if(sClassname[0] != 'c')
return;
if(StrEqual(sClassname, "cs_ragdoll", false))
iCSRagdollRef = EntIndexToEntRef(iEntity);
}
static bool IsValidEntRef(int iEntRef)
{
return (iEntRef != 0 && EntRefToEntIndex(iEntRef) != INVALID_ENT_REFERENCE);
}