-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
timebomb.sp
223 lines (172 loc) · 6.09 KB
/
timebomb.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Timebomb 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 MODEL_BOMB "models/props_lakeside_event/bomb_temp_hat.mdl"
#define SOUND_TIMEBOMB_TICK "buttons/button17.wav"
#define SOUND_TIMEBOMB_GOFF "weapons/cguard/charging.wav"
#define SOUND_EXPLODE "weapons/explode3.wav"
#define TICKS_SLOW 0.75
#define TICKS_FAST 0.35
#define Resistance Int[0]
#define Headshot Int[1]
#define Damage Float[0]
#define RadiusSquared Float[1]
#define PrimeThreshold Float[2]
#define DetonateThreshold Float[3]
#define Bomb EntSlot_1
static char g_sResistanceMedium[][] = {
"player/resistance_medium1.wav",
"player/resistance_medium2.wav",
"player/resistance_medium3.wav",
"player/resistance_medium4.wav",
};
DEFINE_CALL_APPLY_REMOVE(Timebomb)
public void Timebomb_Init(const Perk perk)
{
PrecacheModel(MODEL_BOMB);
PrecacheSound(SOUND_EXPLODE);
PrecacheSound(SOUND_TIMEBOMB_TICK);
PrecacheSound(SOUND_TIMEBOMB_GOFF);
PrecacheSound(g_sResistanceMedium[0]);
PrecacheSound(g_sResistanceMedium[1]);
PrecacheSound(g_sResistanceMedium[2]);
PrecacheSound(g_sResistanceMedium[3]);
}
void Timebomb_ApplyPerk(const int client, const Perk perk)
{
float fExplodeTime = GetEngineTime() + GetPerkTime(perk);
float fRadius = perk.GetPrefFloat("radius", 512.0);
Cache[client].Resistance = RoundFloat(perk.GetPrefFloat("resistance", 0.75) * 100);
Cache[client].Headshot = RoundFloat(perk.GetPrefFloat("headshot", 0.1) * 100);
Cache[client].Damage = perk.GetPrefFloat("damage", 270.0);
Cache[client].RadiusSquared = fRadius * fRadius;
Cache[client].PrimeThreshold = fExplodeTime - 3.0;
Cache[client].DetonateThreshold = fExplodeTime - 1.0;
Cache[client].SetEnt(Bomb, Timebomb_SpawnBombHead(client));
SetVariantInt(1);
AcceptEntityInput(client, "SetForcedTauntCam");
SDKHook(client, SDKHook_OnTakeDamage, Timebomb_OnTakeDamage);
Cache[client].Repeat(TICKS_SLOW, Timebomb_TickSlow);
}
public void Timebomb_RemovePerk(const int client, const RTDRemoveReason eRemoveReason)
{
SetVariantInt(0);
AcceptEntityInput(client, "SetForcedTauntCam");
SDKUnhook(client, SDKHook_OnTakeDamage, Timebomb_OnTakeDamage);
if (GetEngineTime() < Cache[client].DetonateThreshold)
return;
float fDamage = Cache[client].Damage;
float fRadiusSquared = Cache[client].RadiusSquared;
float fPos[3];
GetClientAbsOrigin(client, fPos);
int iPlayerDamage = 0;
for (int i = 1; i <= MaxClients; ++i)
{
if (i == client || !IsClientInGame(i) || !IsPlayerAlive(i))
continue;
if (!CanPlayerBeHurt(i))
continue;
if (!CanEntitySeeTarget(client, i))
continue;
float fTargetPos[3];
GetClientAbsOrigin(i, fTargetPos);
if (GetVectorDistance(fPos, fTargetPos, true) <= fRadiusSquared)
{
iPlayerDamage += RoundToFloor(fDamage);
TakeDamage(i, 0, client, fDamage, DMG_PREVENT_PHYSICS_FORCE | DMG_CRUSH | DMG_ALWAYSGIB | DMG_BLAST);
}
}
int iShockwave = CreateParticle(client, "rd_robot_explosion_shockwave");
KILL_ENT_IN(iShockwave,1.0);
int iExplosion = CreateParticle(client, "rd_robot_explosion");
KILL_ENT_IN(iExplosion,1.0);
Notify.PlayerDamage(client, iPlayerDamage);
EmitSoundToAll(SOUND_EXPLODE, client);
FakeClientCommandEx(client, "explode");
}
public Action Timebomb_OnTakeDamage(int client, int& iAttacker, int& iInflictor, float& fDamage, int& iType, int& iWeapon, float fForce[3], float fPos[3], int iCustomType)
{
int iValue = iCustomType == TF_CUSTOM_HEADSHOT ? Cache[client].Headshot : Cache[client].Resistance;
fDamage *= float(iValue) / 100.0;
EmitSoundToAll(g_sResistanceMedium[GetRandomInt(0, sizeof(g_sResistanceMedium) - 1)], client);
return Plugin_Changed;
}
public Action Timebomb_TickSlow(const int client)
{
Timebomb_Beep(client);
if (GetEngineTime() > Cache[client].PrimeThreshold)
{
Cache[client].Repeat(TICKS_FAST, Timebomb_TickFast);
return Plugin_Stop;
}
return Plugin_Continue;
}
public Action Timebomb_TickFast(const int client)
{
Timebomb_Beep(client);
if (GetEngineTime() > Cache[client].DetonateThreshold)
{
EmitSoundToAll(SOUND_TIMEBOMB_GOFF, client);
return Plugin_Stop;
}
return Plugin_Continue;
}
void Timebomb_Beep(const int client)
{
EmitSoundToAll(SOUND_TIMEBOMB_TICK, client);
SendTEParticleAttached(TEParticles.ShockwaveAirLight, Cache[client].GetEnt(Bomb).Index);
}
int Timebomb_SpawnBombHead(const int client)
{
int iBomb = CreateEntityByName("prop_dynamic");
if (iBomb <= MaxClients)
return 0;
DispatchKeyValue(iBomb, "model", MODEL_BOMB);
switch (TF2_GetClientTeam(client))
{
case TFTeam_Blue:
DispatchKeyValue(iBomb, "rendercolor", "100 100 255 255");
case TFTeam_Red:
DispatchKeyValue(iBomb, "rendercolor", "255 100 100 255");
}
DispatchSpawn(iBomb);
SetVariantString("!activator");
AcceptEntityInput(iBomb, "SetParent", client, -1, 0);
switch (Shared[client].ClassForPerk)
{
case TFClass_Pyro, TFClass_Engineer:
SetVariantString("OnUser1 !self,SetParentAttachment,head,0.0,-1");
default:
SetVariantString("OnUser1 !self,SetParentAttachment,eyes,0.0,-1");
}
AcceptEntityInput(iBomb, "AddOutput");
AcceptEntityInput(iBomb, "FireUser1");
return iBomb;
}
#undef MODEL_BOMB
#undef SOUND_TIMEBOMB_TICK
#undef SOUND_TIMEBOMB_GOFF
#undef SOUND_EXPLODE
#undef TICKS_SLOW
#undef TICKS_FAST
#undef Resistance
#undef Headshot
#undef Damage
#undef RadiusSquared
#undef PrimeThreshold
#undef DetonateThreshold
#undef Bomb