-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
mercsdietwice.sp
199 lines (156 loc) · 5.88 KB
/
mercsdietwice.sp
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/**
* Mercs Die Twice perk.
* Copyright (C) 2024 Filip Tomaszewski
*
* 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 <http://www.gnu.org/licenses/>.
*/
#define SOUND_RESURRECT "mvm/mvm_revive.wav"
#define SOUND_RESURRECT_DENY "replay/replaydialog_warn.wav"
#define InFakeDeath Int[0]
#define BaseAlpha Int[1]
#define HealthPercentage Int[2]
#define NextResurrection Int[3]
#define Velocity(%1) Float[%1]
#define ProtectionTime Float[3]
#define Ragdoll EntSlot_1
DEFINE_CALL_APPLY_REMOVE(MercsDieTwice)
public void MercsDieTwice_Init(const Perk perk)
{
PrecacheSound(SOUND_RESURRECT);
PrecacheSound(SOUND_RESURRECT_DENY);
Events.OnVoice(perk, MercsDieTwice_OnVoice);
}
void MercsDieTwice_ApplyPerk(const int client, const Perk perk)
{
Cache[client].InFakeDeath = false;
Cache[client].HealthPercentage = perk.GetPrefCell("health", 80);
Cache[client].ProtectionTime = perk.GetPrefFloat("protection", 3.0);
SDKHook(client, SDKHook_OnTakeDamageAlive, MercsDieTwice_OnTakeDamage);
}
public void MercsDieTwice_RemovePerk(const int client, const RTDRemoveReason eRemoveReason)
{
if (Cache[client].InFakeDeath)
MercsDieTwice_Resurrect(client);
SDKUnhook(client, SDKHook_OnTakeDamageAlive, MercsDieTwice_OnTakeDamage);
}
void MercsDieTwice_OnVoice(const int client)
{
if (!Cache[client].InFakeDeath)
return;
if (GetTime() < Cache[client].NextResurrection)
{
EmitSoundToClient(client, SOUND_RESURRECT_DENY);
return;
}
MercsDieTwice_Resurrect(client);
}
public Action MercsDieTwice_OnTakeDamage(int client, int& iAttacker, int& iInflictor, float& fDamage, int& iType, int& iWeapon, float fForce[3], float fPos[3])
{
if (Cache[client].InFakeDeath)
return Plugin_Handled;
if (fDamage >= GetClientHealth(client) && CanPlayerBeHurt(client, iAttacker))
{
SetEntityHealth(client, RoundToCeil(fDamage + 2.0));
MercsDieTwice_FakeDeath(client, iAttacker, iInflictor, iWeapon);
}
return Plugin_Continue;
}
void MercsDieTwice_FakeDeath(const int client, const int iAttacker, const int iInflictor, const int iWeapon)
{
Cache[client].InFakeDeath = true;
Cache[client].NextResurrection = GetTime() + 3;
g_eInGodmode.Set(client);
float fVel[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", fVel);
Cache[client].Velocity(0) = fVel[0];
Cache[client].Velocity(1) = fVel[1];
Cache[client].Velocity(2) = fVel[2];
Cache[client].BaseAlpha = GetEntityAlpha(client);
SetClientAlpha(client, 0);
int iRag = CreateRagdoll(client);
if (iRag > MaxClients)
{
Cache[client].SetEnt(Ragdoll, iRag);
SetClientViewEntity(client, iRag);
}
DisarmWeapons(client, true);
SetEntityMoveType(client, MOVETYPE_NONE);
TF2_AddCondition(client, TFCond_DisguisedAsDispenser);
ApplyPreventCapture(client);
SetOverlay(client, ClientOverlay_Stealth);
SetVariantInt(1);
AcceptEntityInput(client, "SetForcedTauntCam");
PrintCenterText(client, "%t", "RTD2_Perk_Resurrect", 0x03, 0x01);
MercsDieTwice_SendDeathEvent(client, iAttacker, iInflictor, iWeapon);
}
void MercsDieTwice_Resurrect(const int client)
{
Cache[client].InFakeDeath = false;
g_eInGodmode.Unset(client);
float fVec[3];
fVec[0] = Cache[client].Velocity(0);
fVec[1] = Cache[client].Velocity(1);
fVec[2] = Cache[client].Velocity(2);
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fVec);
SetClientAlpha(client, Cache[client].BaseAlpha);
DisarmWeapons(client, false);
SetEntityMoveType(client, MOVETYPE_WALK);
TF2_RemoveCondition(client, TFCond_DisguisedAsDispenser);
RemovePreventCapture(client);
SetOverlay(client, ClientOverlay_None);
SetVariantInt(0);
AcceptEntityInput(client, "SetForcedTauntCam");
SetClientViewEntity(client, client);
Cache[client].GetEnt(Ragdoll).Kill();
TF2_AddCondition(client, TFCond_UberchargedCanteen, Cache[client].ProtectionTime);
EmitSoundToAll(SOUND_RESURRECT, client);
float fMulti = float(Cache[client].HealthPercentage) / 100.0;
SetEntityHealth(client, RoundFloat(Shared[client].MaxHealthFloat() * fMulti));
Cache[client].HealthPercentage = MaxInt(10, RoundFloat(Cache[client].HealthPercentage * 0.75));
MercsDieTwice_SpawnEffect(client);
}
void MercsDieTwice_SpawnEffect(const int client)
{
int iProxy = CreateProxy(client);
if (iProxy <= MaxClients)
return;
KILL_ENT_IN(iProxy,0.7); // adjusted specifically for utaunt_elebound_yellow_parent
SendTEParticleLingeringAttachedProxy(TEParticlesLingering.LightningSwirl, iProxy);
}
void MercsDieTwice_SendDeathEvent(const int client, const int iAttacker, const int iInflictor, const int iWeapon)
{
Event hEvent = CreateEvent("player_death");
int iWeaponIndex = 0;
if (IsValidEntity(iWeapon))
{
iWeaponIndex = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
}
hEvent.SetInt("userid", GetClientUserId(client));
hEvent.SetInt("victim_entindex", client);
hEvent.SetInt("inflictor_entindex", iInflictor);
hEvent.SetInt("attacker", iAttacker == 0 ? 0 : GetClientUserId(iAttacker));
hEvent.SetInt("weaponid", iWeapon);
hEvent.SetInt("weapon_def_index", iWeaponIndex);
hEvent.SetInt("death_flags", TF_DEATHFLAG_DEADRINGER);
hEvent.Fire();
}
#undef SOUND_RESURRECT
#undef SOUND_RESURRECT_DENY
#undef InFakeDeath
#undef BaseAlpha
#undef HealthPercentage
#undef NextResurrection
#undef Velocity
#undef ProtectionTime
#undef Ragdoll