forked from jeremyvillanuevar/scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneAdjustments.sp
More file actions
505 lines (441 loc) · 17.2 KB
/
SceneAdjustments.sp
File metadata and controls
505 lines (441 loc) · 17.2 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#define PLUGIN_NAME "[L4D2] Scene Adjustments"
#define PLUGIN_AUTHOR "Shadowysn"
#define PLUGIN_DESC "Re-adds some quotes as well as fixing friendly fire lines for 5+ survivors."
#define PLUGIN_VERSION "1.1.4"
#define PLUGIN_URL "https://forums.alliedmods.net/showthread.php?p=2681697"
#define PLUGIN_NAME_SHORT "Scene Adjustments"
#define PLUGIN_NAME_TECH "l4d_sceneadjust"
#define DEBUG 0
#pragma semicolon 1
#include <sourcemod>
//#include <sceneprocessor>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required
#pragma semicolon 1
//static bool pounced[MAXPLAYERS+1] = false; // Hunter pounce zoeyfix/oof //
//static bool hasMourned[MAXPLAYERS+1] = false; // L4D1 passing survivor mourn fix //
static bool canMourn[MAXPLAYERS+1] = false; // L4D1 passing survivor mourn fix //
static float g_vecLastLivingOrigin[3][MAXPLAYERS+1]; // L4D1 passing survivor mourn fix //
static int targetClient[MAXPLAYERS+1] = INVALID_ENT_REFERENCE; // L4D1 passing survivor mourn fix //
static float friendlyFire_Time[MAXPLAYERS+1] = 0.0; // Friendly Fire fix //
static bool hasFriendlyFired = false; // Friendly Fire fix //
#define FRIENDLYFIRE_DELAY 10.0 // Friendly Fire fix //
ConVar version_cvar;
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESC,
version = PLUGIN_VERSION,
url = PLUGIN_URL
}
static bool g_isSequel = false;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if (GetEngineVersion() == Engine_Left4Dead2)
{
g_isSequel = true;
return APLRes_Success;
}
else if (GetEngineVersion() == Engine_Left4Dead)
{
g_isSequel = false;
return APLRes_Success;
}
strcopy(error, err_max, "Plugin only supports Left 4 Dead and Left 4 Dead 2.");
return APLRes_SilentFailure;
}
//ConVar Scene_ZoeyPounced;
ConVar Scene_OofSounds;
ConVar Scene_FriendlyFire;
ConVar Scene_L4D1Mourn;
public void OnPluginStart()
{
char cvar_desc_str[500];
Format(cvar_desc_str, sizeof(cvar_desc_str), "%s plugin version.", PLUGIN_NAME_SHORT);
version_cvar = CreateConVar("sm_l4d_sceneadjust_ver", PLUGIN_VERSION, cvar_desc_str, 0|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_DONTRECORD);
if (version_cvar != null)
SetConVarString(version_cvar, PLUGIN_VERSION);
char cvar_str[128];
if (g_isSequel)
{
//Format(cvar_str, sizeof(cvar_str), "sm_%s_zoey_pounce", PLUGIN_NAME_TECH);
//Format(cvar_desc_str, sizeof(cvar_desc_str), "Should %s fix Zoey's lines while pounced?", PLUGIN_NAME_SHORT);
//Scene_ZoeyPounced = CreateConVar(cvar_str, "1", cvar_desc_str, FCVAR_ARCHIVE, true, 0.0, true, 1.0);
Format(cvar_str, sizeof(cvar_str), "sm_%s_oof", PLUGIN_NAME_TECH);
Format(cvar_desc_str, sizeof(cvar_desc_str), "Should %s make Survivors play their minor hurt sounds upon getting pounced/charged?", PLUGIN_NAME_SHORT);
Scene_OofSounds = CreateConVar(cvar_str, "1", cvar_desc_str, FCVAR_ARCHIVE, true, 0.0, true, 1.0);
Format(cvar_str, sizeof(cvar_str), "sm_%s_l4d1mourn", PLUGIN_NAME_TECH);
Format(cvar_desc_str, sizeof(cvar_desc_str), "Should %s fix the L4D1 survivors on L4D2 set not mourning their own group?", PLUGIN_NAME_SHORT);
Scene_L4D1Mourn = CreateConVar(cvar_str, "1", cvar_desc_str, FCVAR_ARCHIVE, true, 0.0, true, 1.0);
}
else
{
//delete Scene_ZoeyPounced;
delete Scene_OofSounds;
delete Scene_L4D1Mourn;
}
Format(cvar_str, sizeof(cvar_str), "sm_%s_friendlyfire", PLUGIN_NAME_TECH);
Format(cvar_desc_str, sizeof(cvar_desc_str), "Should %s fix friendly fire quotes not playing for 5+ survivors?", PLUGIN_NAME_SHORT);
Scene_FriendlyFire = CreateConVar(cvar_str, "1", cvar_desc_str, FCVAR_ARCHIVE, true, 0.0, true, 1.0);
if (g_isSequel)
{
HookEvent("lunge_pounce", lunge_pounce); // Hunter pounce zoeyfix/oof //
//HookEvent("pounce_end", pounce_end); // Hunter pounce zoeyfix/oof //
HookEvent("charger_carry_start", charger_carry_start); // Charger Oof sound //
//HookEvent("player_spawn", player_spawn);
HookEvent("player_death", player_death);
//HookEvent("player_shoved", player_shoved);
CreateTimer(1.0, TimerUpdate_Mourn, _, TIMER_REPEAT); // L4D1 passing survivor mourn fix //
}
HookEvent("player_hurt", player_hurt, EventHookMode_Post); // Friendly Fire fix //
HookEvent("friendly_fire", friendly_fire, EventHookMode_Pre); // Friendly Fire fix //
AutoExecConfig(true, "l4d_sceneadjust");
}
public void OnPluginEnd()
{
if (g_isSequel)
{
//UnhookEvent("lunge_pounce", lunge_pounce);
//UnhookEvent("pounce_end", pounce_end);
UnhookEvent("charger_carry_start", charger_carry_start);
//UnhookEvent("player_spawn", player_spawn);
UnhookEvent("player_death", player_death);
//UnhookEvent("player_shoved", player_shoved);
}
UnhookEvent("player_hurt", player_hurt, EventHookMode_Post);
UnhookEvent("friendly_fire", friendly_fire, EventHookMode_Pre);
}
// L4D1 passing survivor mourn fix //
Action TimerUpdate_Mourn(Handle timer)
{
if (!IsServerProcessing()) return;
if (Scene_L4D1Mourn == null || !GetConVarBool(Scene_L4D1Mourn)) return;
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i) && IsPlayerAlive(i))
{
int is_Incap = GetEntProp(i, Prop_Send, "m_isIncapacitated");
//if (IsClientL4D1Survivor(i) && !is_Incap && !hasMourned[i])
if (IsClientL4D1Survivor(i) && !is_Incap)
{
for (int loopclient = 1; loopclient <= MaxClients; loopclient++)
{
if (!IsValidClient(loopclient)) continue;
if (!IsSurvivor(loopclient) || !IsClientL4D1Survivor(loopclient) || IsPlayerAlive(loopclient)) continue;
if (IsValidClient(targetClient[i]) && targetClient[i] == loopclient) continue;
int character = GetEntProp(i, Prop_Send, "m_survivorCharacter");
int loopchar = GetEntProp(loopclient, Prop_Send, "m_survivorCharacter");
char weapon_name[128];
GetClientWeapon(loopclient, weapon_name, sizeof(weapon_name));
if (character == loopchar || StrEqual(weapon_name, "weapon_defibrillator", false)) continue;
float client_pos[3];
float other_pos[3];
other_pos[0] = g_vecLastLivingOrigin[0][loopclient];
other_pos[1] = g_vecLastLivingOrigin[1][loopclient];
other_pos[2] = g_vecLastLivingOrigin[2][loopclient];
//if (!HasEntProp(loopclient, Prop_Data, "m_vecAbsOrigin")) continue;
if (other_pos[0] == 0.0 && other_pos[1] == 0.0 && other_pos[2] == 0.0) continue;
GetClientAbsOrigin(i, client_pos);
float distance = GetVectorDistance(client_pos, other_pos);
if (distance <= 50.0 && canMourn[i])
//if (distance <= 50.0 && canMourn[i])
{
canMourn[i] = false;
SurvivorMourn(i, loopclient);
targetClient[i] = loopclient;
break;
}
else if (distance > 200.0 && !canMourn[i])
{
canMourn[i] = true;
//targetClient[i] = INVALID_ENT_REFERENCE;
break;
}
}
}
}
}
}
void SurvivorMourn(int client, int victim)
{
//char client_namestr[PLATFORM_MAX_PATH];
char victim_namestr[PLATFORM_MAX_PATH];
//GetSurvivorSceneName(client, false, client_namestr, sizeof(client_namestr));
GetSurvivorSceneName(victim, false, victim_namestr, sizeof(victim_namestr));
char temp_str[128];
//int worldspawn = 0;
Format(temp_str, sizeof(temp_str), "DeadCharacter:%s:0.1", victim_namestr);
SetVariantString(temp_str);
AcceptEntityInput(client, "AddContext");
//hasMourned[client] = true;
//SetVariantString("SaidSomeoneDied:1:10");
//AcceptEntityInput(worldspawn, "AddContext");
SetVariantString("PlayerSeeDeadPlayer");
AcceptEntityInput(client, "SpeakResponseConcept");
}
void player_death(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client) && !IsPlayerAlive(client) && IsSurvivor(client))
{
//hasMourned[client] = false;
if (IsClientL4D1Survivor(client))
{
float other_pos[3];
GetClientAbsOrigin(client, other_pos);
g_vecLastLivingOrigin[0][client] = other_pos[0];
g_vecLastLivingOrigin[1][client] = other_pos[1];
g_vecLastLivingOrigin[2][client] = other_pos[2];
/*for (int loopclient = 1; loopclient <= MaxClients; loopclient++)
{
if (!IsValidClient(loopclient)) continue;
if (!IsSurvivor(loopclient)) continue;
//hasMourned[loopclient] = false;
}*/
}
}
}
// L4D1 passing survivor mourn fix end //
// Hunter pounce zoeyfix/oof //
void lunge_pounce(Handle event, const char[] name, bool dontBroadcast)
{
#if DEBUG
PrintToChatAll("Lunge pounce!");
#endif
int client = GetClientOfUserId(GetEventInt(event, "victim"));
//if (IsZoey(client) && IsValidEntity(GetEntPropEnt(client, Prop_Send, "m_pounceAttacker")))
if (IsSurvivor(client) && IsPlayerAlive(client) && Scene_OofSounds != null && GetConVarBool(Scene_OofSounds))
{
SetVariantString("PainLevel:Minor:0.5");
AcceptEntityInput(client, "AddContext");
SetVariantString("Pain");
AcceptEntityInput(client, "SpeakResponseConcept");
}
/*if (IsZoey(client) && IsPlayerAlive(client) && !pounced[client] &&
Scene_ZoeyPounced != null && GetConVarBool(Scene_ZoeyPounced))
{
pounced[client] = true;
CreateTimer(2.0, ScreamThink, client, TIMER_REPEAT && TIMER_FLAG_NO_MAPCHANGE);
SetVariantString("PainLevel:None");
AcceptEntityInput(client, "AddContext");
}*/
}
/*void pounce_end(Handle event, const char[] name, bool dontBroadcast)
{
#if DEBUG
PrintToChatAll("Pounce end!");
#endif
int client = GetClientOfUserId(GetEventInt(event, "victim"));
//if (IsZoey(client) && !IsValidEntity(GetEntPropEnt(client, Prop_Send, "m_pounceAttacker")))
if (IsZoey(client) && pounced[client])
{ pounced[client] = false; }
}
Action ScreamThink(Handle timer, int client)
{
if (!IsServerProcessing()) return;
if (IsSurvivor(client) && IsPlayerAlive(client) && pounced[client] &&
Scene_ZoeyPounced != null && GetConVarBool(Scene_ZoeyPounced))
{
#if DEBUG
PrintToChatAll("Being pounced!");
#endif
switch (GetRandomInt(1, 4))
{
//case 1:PerformScene(client, "", "scenes/teengirl/screamwhilepounced01.vcd");
case 1:PlayScene(client, "scenes/teengirl/screamwhilepounced01.vcd");
case 2:PlayScene(client, "scenes/teengirl/screamwhilepounced02.vcd");
case 3:PlayScene(client, "scenes/teengirl/screamwhilepounced04.vcd");
case 4:PlayScene(client, "scenes/teengirl/screamwhilepounced06.vcd");
default:return;
}
}
else
{
SetVariantString("PainLevel:None:0.01");
AcceptEntityInput(client, "AddContext");
KillTimer(timer);
}
}*/
/*void PlayScene(int client, const char[] str)
{
int scene = CreateEntityByName("instanced_scripted_scene");
DispatchKeyValue(scene, "SceneFile", str);
SetEntPropEnt(scene, Prop_Data, "m_hActor", client);
DispatchKeyValue(scene, "busyactor", "0");
DispatchSpawn(scene);
ActivateEntity(scene);
AcceptEntityInput(scene, "Start");
}*/
// Hunter pounce zoeyfix/oof end //
// Charger Oof sound //
void charger_carry_start(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "victim"));
if (IsSurvivor(client) && IsPlayerAlive(client) && Scene_OofSounds != null && GetConVarBool(Scene_OofSounds))
{
SetVariantString("PainLevel:Minor:0.5");
AcceptEntityInput(client, "AddContext");
SetVariantString("Pain");
AcceptEntityInput(client, "SpeakResponseConcept");
}
}
// Charger Oof sound end //
/*void player_shoved(Handle event, const char[] name, bool dontBroadcast)
{
#if DEBUG
PrintToChatAll("Shoved1!");
#endif
int client = GetClientOfUserId(GetEventInt(event, "userid"));
//int client = GetClientOfUserId(GetEventInt(event, "entityid"));
//int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if (IsValidClient(client) && IsPlayerAlive(client))
{
#if DEBUG
PrintToChatAll("Shoved!");
#endif
}
}*/
// Friendly Fire fix //
void friendly_fire(Handle event, const char[] name, bool dontBroadcast)
{
if (Scene_FriendlyFire == null || !GetConVarBool(Scene_FriendlyFire)) return;
int client = GetClientOfUserId(GetEventInt(event, "victim"));
if (!IsSurvivor(client)) return;
float game_Time = GetGameTime();
if (friendlyFire_Time[client] > game_Time) return;
friendlyFire_Time[client] = game_Time+FRIENDLYFIRE_DELAY;
}
void player_hurt(Event event, const char[] name, bool dontBroadcast)
{
if (Scene_FriendlyFire == null || !GetConVarBool(Scene_FriendlyFire)) return;
if (hasFriendlyFired) return;
int clientID = GetEventInt(event, "userid");
int client = GetClientOfUserId(clientID);
//if (!IsSurvivor(client) || !IsExtraSurvivor(client)) return;
if (!IsSurvivor(client)) return;
float game_Time = GetGameTime();
if (friendlyFire_Time[client] > game_Time) return;
int attackerID = GetEventInt(event, "attacker");
int attacker = GetClientOfUserId(attackerID);
if (!IsSurvivor(attacker) || attacker == client) return;
int type = GetEventInt(event, "type");
if (!(type & DMG_BULLET) && !(type & DMG_BLAST) && !(type & DMG_CLUB) && !(type & DMG_SLASH))
return;
friendlyFire_Time[client] = game_Time+FRIENDLYFIRE_DELAY;
Handle friendly_fire_ev = CreateEvent("friendly_fire");
SetEventInt(friendly_fire_ev, "attacker", attacker);
SetEventInt(friendly_fire_ev, "victim", client);
SetEventInt(friendly_fire_ev, "guilty", attacker);
SetEventInt(friendly_fire_ev, "type", type);
FireEvent(friendly_fire_ev);
Handle award_earned = CreateEvent("award_earned");
SetEventInt(award_earned, "userid", GetClientUserId(client));
SetEventInt(award_earned, "entityid", EntRefToEntIndex(client));
SetEventInt(award_earned, "subjectentid", EntRefToEntIndex(attacker));
SetEventInt(award_earned, "award", 87);
FireEvent(award_earned);
char name_str[32];
GetSurvivorSceneName(attacker, false, name_str, sizeof(name_str));
//if (RecognizesOther(client, attacker))
//{
char temp_str[128];
//Format(temp_str, sizeof(temp_str), "%sFriendlyFire:1:10", name_str);
Format(temp_str, sizeof(temp_str), "Subject:%s:0.6", name_str);
SetVariantString(temp_str);
AcceptEntityInput(client, "AddContext");
//}
hasFriendlyFired = true;
CreateTimer(0.5, Timer_FFResponse, client, TIMER_FLAG_NO_MAPCHANGE);
CreateTimer(0.0, Timer_hasFriendlyFired, -1, TIMER_FLAG_NO_MAPCHANGE);
}
Action Timer_FFResponse(Handle timer, int client)
{
if (!IsSurvivor(client)) return;
SetVariantString("PlayerFriendlyFire");
AcceptEntityInput(client, "SpeakResponseConcept");
}
Action Timer_hasFriendlyFired(Handle timer)
{
hasFriendlyFired = false;
}
// Friendly Fire fix end //
void GetSurvivorSceneName(int client, bool is_victim = false, char[] str, int maxlength)
{
if (!IsSurvivor(client)) return;
static char cl_model[PLATFORM_MAX_PATH];
GetClientModel(client, cl_model, sizeof(cl_model));
//PrintToChatAll("%s", cl_model);
if (StrEqual(cl_model, "models/survivors/survivor_gambler.mdl", false))
{ is_victim ? strcopy(str, maxlength, "nick") : strcopy(str, maxlength, "Gambler"); }
else if (StrEqual(cl_model, "models/survivors/survivor_producer.mdl", false))
{ is_victim ? strcopy(str, maxlength, "rochelle") : strcopy(str, maxlength, "Producer"); }
else if (StrEqual(cl_model, "models/survivors/survivor_coach.mdl", false))
{ is_victim ? strcopy(str, maxlength, "coach") : strcopy(str, maxlength, "Coach"); }
else if (StrEqual(cl_model, "models/survivors/survivor_mechanic.mdl", false))
{ is_victim ? strcopy(str, maxlength, "ellis") : strcopy(str, maxlength, "Mechanic"); }
else if (StrEqual(cl_model, "models/survivors/survivor_namvet.mdl", false))
{ is_victim ? strcopy(str, maxlength, "bill") : strcopy(str, maxlength, "NamVet"); }
else if (StrEqual(cl_model, "models/survivors/survivor_teenangst.mdl", false))
{ is_victim ? strcopy(str, maxlength, "zoey") : strcopy(str, maxlength, "TeenGirl"); }
else if (StrEqual(cl_model, "models/survivors/survivor_biker.mdl", false))
{ is_victim ? strcopy(str, maxlength, "francis") : strcopy(str, maxlength, "Biker"); }
else if (StrEqual(cl_model, "models/survivors/survivor_manager.mdl", false))
{ is_victim ? strcopy(str, maxlength, "louis") : strcopy(str, maxlength, "Manager"); }
else
{ strcopy(str, maxlength, "Unknown"); }
}
/*bool IsZoey(int client)
{
char cl_model[PLATFORM_MAX_PATH];
if (IsValidClient(client))
{ GetClientModel(client, cl_model, sizeof(cl_model)); }
if (IsValidClient(client) && IsSurvivor(client) && (
GetEntProp(client, Prop_Send, "m_survivorCharacter") == 5 || // For Zoey in The Passing set
GetEntProp(client, Prop_Send, "m_survivorCharacter") == 1 && StrEqual(cl_model,"models/survivors/survivor_teenangst.mdl", false) ) ) // For Zoey in the L4D1 survivor set
{
return true;
}
return false;
}*/
/*bool RecognizesOther(int client, int other)
{
if (!IsSurvivor(client) || !IsSurvivor(other)) return false;
switch (IsClientL4D1Survivor(client))
{
case 1: // true
{
if (IsClientL4D1Survivor(other)) return true;
}
case 0: // not true
{
if (!IsClientL4D1Survivor(other)) return true;
}
}
return false;
}*/
bool IsSurvivor(int client)
{
if (!IsValidClient(client)) return false;
if (GetClientTeam(client) == 2 || GetClientTeam(client) == 4) return true;
return false;
}
bool IsClientL4D1Survivor(int client)
{
if (!IsSurvivor(client)) return false;
int character = GetEntProp(client, Prop_Send, "m_survivorCharacter");
if (character >= 4 && character <= 7) return true;
return false;
}
bool IsValidClient(int client, bool replaycheck = true)
{
if (client <= 0 || client > MaxClients) return false;
if (!IsClientInGame(client)) return false;
//if (GetEntProp(client, Prop_Send, "m_bIsCoaching")) return false;
if (replaycheck)
{
if (IsClientSourceTV(client) || IsClientReplay(client)) return false;
}
return true;
}