forked from jeremyvillanuevar/scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefibModel.sp
More file actions
1310 lines (1083 loc) · 38.4 KB
/
Copy pathDefibModel.sp
File metadata and controls
1310 lines (1083 loc) · 38.4 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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <adminmenu>
#define PLUGIN_NAME "[L4D2] Defib Death Model"
#define PLUGIN_AUTHOR "Shadowysn"
#define PLUGIN_DESC "Defib death models like in Rayman's admin system."
#define PLUGIN_VERSION "1.1.2"
#define PLUGIN_URL "https://forums.alliedmods.net/showthread.php?p=2691204"
#define PLUGIN_NAME_SHORT "Defib Death Model"
#define PLUGIN_NAME_TECH "defib_death_model"
#define DEATH_MODEL_CLASS "survivor_death_model"
#define GAMEDATA "l4d2_defibmodel"
#define AUTOEXEC_CFG "l4d2_defibmodel_cvars"
#define INCAP_CVAR "survivor_max_incapacitated_count"
ConVar incap_cvar;
static int g_iSelectedTarget[MAXPLAYERS+1] = -1;
// Credits to Silvers V
//static Handle g_hTimerRespawn[MAXPLAYERS+1] = null;
//static Handle g_hTempGod[MAXPLAYERS+1] = null;
// end
static float g_fTimerRespawn[MAXPLAYERS+1] = -1.0;
static bool g_bTimerRespawn[MAXPLAYERS+1] = false;
static int g_iChosenBody[MAXPLAYERS+1] = -1;
static bool g_bIsVScript[MAXPLAYERS+1] = false;
static float g_fTempGod[MAXPLAYERS+1] = -1.0;
static bool g_bTempGod[MAXPLAYERS+1] = false;
// v To prevent survivors from getting defibbed over and over again if they fell into a death zone
static float g_fTimeTilSafe[MAXPLAYERS+1] = -1.0;
static int g_iNumOfDeathOnAD[MAXPLAYERS+1] = 0;
#define POST_THINK_HOOK SDKHook_PostThink
static float g_fClientWait[MAXPLAYERS+1] = 0.0;
#define THINK_WAITTIME 0.5
TopMenu hTopMenu;
//static const String:MODEL_NICK[] = "models/survivors/survivor_gambler.mdl";
//static const String:MODEL_ROCHELLE[] = "models/survivors/survivor_producer.mdl";
//static const String:MODEL_COACH[] = "models/survivors/survivor_coach.mdl";
//static const String:MODEL_ELLIS[] = "models/survivors/survivor_mechanic.mdl";
//static const String:MODEL_BILL[] = "models/survivors/survivor_namvet.mdl";
//static const String:MODEL_ZOEY[] = "models/survivors/survivor_teenangst.mdl";
//static const String:MODEL_LOUIS[] = "models/survivors/survivor_manager.mdl";
//static const String:MODEL_FRANCIS[] = "models/survivors/survivor_biker.mdl";
ConVar Defib_AutoTimer;
ConVar Defib_AutoTimerMode;
ConVar Defib_TempGodTimer;
ConVar Defib_AutoTimerTeleport;
ConVar Defib_AutoTimerBAW;
ConVar Defib_AutoTimerSpawnKill;
ConVar Defib_AutoTimerSafety;
#define BITFLAG_BAW_AUTO (1 << 0)
#define BITFLAG_BAW_NONAUTO (1 << 1)
Handle hConf = null;
static Handle hOnRevivedByDefibrillator = null;
#define NAME_OnRevivedByDefibrillator "CTerrorPlayer::OnRevivedByDefibrillator"
#define SIG_OnRevivedByDefibrillator_LINUX "@_ZN13CTerrorPlayer24OnRevivedByDefibrillatorEPS_P19CSurvivorDeathModel"
#define SIG_OnRevivedByDefibrillator_WINDOWS "\\x55\\x8B\\x2A\\x83\\x2A\\x34\\x53\\x56\\x8B\\x2A\\x8A"
// PUBLIC Start // -------------------------------------------------------- //
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(GetEngineVersion() == Engine_Left4Dead2)
{
return APLRes_Success;
}
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2");
return APLRes_SilentFailure;
}
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESC,
version = PLUGIN_VERSION,
url = PLUGIN_URL
}
ConVar version_cvar;
public void OnPluginStart()
{
char temp_str[128];
char desc_str[1024];
Format(desc_str, sizeof(desc_str), "%s version.", PLUGIN_NAME_SHORT);
version_cvar = CreateConVar("sm_defib_death_model_new_version", PLUGIN_VERSION, desc_str, FCVAR_NONE|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_DONTRECORD);
if(version_cvar != null)
SetConVarString(version_cvar, PLUGIN_VERSION);
incap_cvar = FindConVar(INCAP_CVAR);
Format(temp_str, sizeof(temp_str), "sm_%s_autotimer", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "0.0 = Off. | Automatic timer for defibbing each player that died within the defined time limit.");
Defib_AutoTimer = CreateConVar(temp_str, "0.0", desc_str, FCVAR_NONE, true, 0.0);
Format(temp_str, sizeof(temp_str), "sm_%s_autotimer_mode", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "0 = VScript. 1 = Signature. | Choose an automatic timer mode.");
Defib_AutoTimerMode = CreateConVar(temp_str, "1", desc_str, FCVAR_NONE, true, 0.0, true, 1.0);
Format(temp_str, sizeof(temp_str), "sm_%s_autodefib_god", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "0.0 = Off. | How long the temporary godmode lasts from autodefib, in seconds.");
Defib_TempGodTimer = CreateConVar(temp_str, "5.0", desc_str, FCVAR_NONE, true, 0.0);
Format(temp_str, sizeof(temp_str), "sm_%s_autodefib_teleport", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "0 = Off. 1 = On. | Should autodefibbed survivors be teleported to the closest survivor not on air?");
Defib_AutoTimerTeleport = CreateConVar(temp_str, "0", desc_str, FCVAR_NONE, true, 0.0, true, 1.0);
Format(temp_str, sizeof(temp_str), "sm_%s_blackandwhite", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "Whether to make players defibbed by this plugin black-and-white. 0 = Disable. 1 | BaW on AutoDefib + 2 | BaW on Manual Defib");
Defib_AutoTimerBAW = CreateConVar(temp_str, "0", desc_str, FCVAR_NONE, true, 0.0, true, 3.0);
Format(temp_str, sizeof(temp_str), "sm_%s_autodefib_spawnkill", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "0 = Off. | How much spawnkill deaths are allowed until auto-defib stops defibbing a victim dying after defib/godmode ends?");
Defib_AutoTimerSpawnKill = CreateConVar(temp_str, "2", desc_str, FCVAR_NONE, true, 0.0);
Format(temp_str, sizeof(temp_str), "sm_%s_autodefib_safetytimer", PLUGIN_NAME_TECH);
strcopy(desc_str, sizeof(desc_str), "How long the 'check for safety' timer lasts.");
Defib_AutoTimerSafety = CreateConVar(temp_str, "1.5", desc_str, FCVAR_NONE, true, 0.5);
// Credits to Silvers V
HookEvent("round_end", round_end);
// end
HookEvent("player_death", player_death);
HookEvent("player_bot_replace", player_bot_replace);
HookEvent("bot_player_replace", bot_player_replace);
RegAdminCmd("sm_defib", InitiateMenuAdminDefib_ChooseModel, ADMFLAG_SLAY, "Open a menu with a list of dead bodies to defibrillate. Defibs via Signature.");
RegAdminCmd("sm_vdefib", InitiateMenuAdminDefib_VScript, ADMFLAG_SLAY, "Open a menu with a list of dead bodies to defibrillate. Defibs via VScript.");
RegAdminCmd("sm_autodefib", InitiateAdminDefib_Auto, ADMFLAG_SLAY, "sm_autodefib <mode> - 0 | nearest index. 1 <default> | check for same character. 2 | check for same model. - Choose a dead person and body to defib. Defibs via Signature.");
RegAdminCmd("sm_telebody", TeleBody, ADMFLAG_SLAY, "Teleport all dead bodies to your position.");
GetGamedata();
AutoExecConfig(true, AUTOEXEC_CFG);
}
public void OnMapStart()
{
for (int client = 1; client <= MaxClients; client++)
{
if (g_fClientWait[client] >= THINK_WAITTIME)
{
g_fClientWait[client] = 0.0;
}
}
}
// Credits to Silvers V
public void OnMapEnd()
{
/*for (int i = 1; i <= MaxClients; i++ )
{
CloseHandle(g_hTimerRespawn[i]);
CloseHandle(g_hTempGod[i]);
}*/
for (int i = 1; i <= MaxClients; i++ )
{
g_bTimerRespawn[i] = false;
g_bTempGod[i] = false;
}
for (int i = 1; i <= MaxClients; i++)
{
if (g_fClientWait[i] >= THINK_WAITTIME)
{
g_fClientWait[i] = 0.0;
}
}
}
// end
// PUBLIC End // -------------------------------------------------------- //
#define PLUGIN_SCRIPTLOGIC "plugin_scripting_logic_entity"
void Logic_RunScript(const char[] sCode, any ...)
{
int iScriptLogic = FindEntityByTargetname(-1, PLUGIN_SCRIPTLOGIC);
if (!iScriptLogic || !IsValidEntity(iScriptLogic))
{
iScriptLogic = CreateEntityByName("logic_script");
DispatchKeyValue(iScriptLogic, "targetname", PLUGIN_SCRIPTLOGIC);
DispatchSpawn(iScriptLogic);
}
char sBuffer[512];
VFormat(sBuffer, sizeof(sBuffer), sCode, 2);
SetVariantString(sBuffer);
AcceptEntityInput(iScriptLogic, "RunScriptCode");
}
int FindEntityByTargetname(int index, const char[] findname)
{
for (int i = index; i < GetMaxEntities(); i++) {
if (!IsValidEntity(i)) continue;
char name[128];
GetEntPropString(i, Prop_Data, "m_iName", name, sizeof(name));
if (!StrEqual(name, findname, false)) continue;
return i;
}
return -1;
}
// SIGNATURE Start // -------------------------------------------------------- //
void DefibSurvivorAndModel(int client, int reviver, int model)
{
if (!IsValidClient(client) || !IsValidClient(reviver) || !IsValidEntity(model)) return;
char class[64];
GetEntityClassname(model, class, sizeof(class));
if (!StrEqual(class, DEATH_MODEL_CLASS, false)) return;
SDKCall(hOnRevivedByDefibrillator, client, reviver, model);
if (IsPlayerAlive(client) && (GetConVarInt(Defib_AutoTimerBAW) & BITFLAG_BAW_NONAUTO))
{
int incap_cv_int = GetConVarInt(incap_cvar);
if (incap_cv_int > 0)
{ Logic_RunScript("GetPlayerFromUserID(%d).SetReviveCount(%i)", GetClientUserId(client), incap_cv_int); }
ConvertHPToTemp(client);
}
}
Action InitiateMenuAdminDefib_ChooseModel(int client, int args)
{
if (!IsValidClient(client))
{
ShowWarning(client, -1);
return Plugin_Handled;
}
char name[32]; char number[10];
Handle menu = CreateMenu(ShowMenu_ChooseModel);
//SetMenuTitle(menu, "Defib survivor:");
SetMenuTitle(menu, "Choose dead body:");
bool hasEnt = false;
for (int i = 1; i <= GetMaxEntities(); i++) // Get Survivor Models
{
if (!IsValidEntity(i)) continue;
char class[64];
GetEntityClassname(i, class, sizeof(class));
if (!StrEqual(class, DEATH_MODEL_CLASS, false)) continue;
int character = GetEntProp(i, Prop_Send, "m_nCharacterType");
GetCharacterName(character, name, sizeof(name));
Format(number, sizeof(number), "%i", EntRefToEntIndex(i));
AddMenuItem(menu, number, name);
if (!hasEnt) hasEnt = true;
//PrintToChat(client, "Entity: %i, Converted: %s", i, number);
}
if (!hasEnt)
ShowWarning(client, 4);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
int ShowMenu_ChooseModel(Handle menu, MenuAction action, int client, int param2)
{
switch (action)
{
case MenuAction_Select:
{
if (!IsValidClient(client)) return;
char param2_str[12];
GetMenuItem(menu, param2, param2_str, sizeof(param2_str));
int chosen_mdl = StringToInt(param2_str);
if (!IsValidEntity(chosen_mdl))
{ CreateTimer(0.15, TimerOpenMenu_Sig, client); ShowWarning(client, 1); return; }
char class[128];
GetEntityClassname(chosen_mdl, class, sizeof(class));
if (!StrEqual(class, DEATH_MODEL_CLASS, false)) { ShowWarning(client, 1); return; }
g_iSelectedTarget[client] = EntIndexToEntRef(chosen_mdl);
//PrintToChat(client, "[SM] Selected a dead body with index: %i", StringToInt(param2_str));
InitiateMenuAdminDefib_ChooseClient(client);
}
case MenuAction_Cancel:
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, client, TopMenuPosition_LastCategory);
}
}
case MenuAction_End:
{
CloseHandle(menu);
}
}
}
void InitiateMenuAdminDefib_ChooseClient(int client)
{
if (!IsValidClient(client))
{
ShowWarning(client, -1);
return;
}
char name[MAX_NAME_LENGTH]; char number[10];
Handle menu = CreateMenu(ShowMenu_ChooseClient);
SetMenuTitle(menu, "Defib survivor:");
bool hasEnt = false;
for (int i = 1; i <= MaxClients; i++) // Get Clients
{
if (!IsSurvivor(i) || IsPlayerAlive(i)) continue;
GetClientName(i, name, sizeof(name));
char temphp[32];
if (IsPlayerAlive(i) && HasEntProp(i, Prop_Send, "m_healthBuffer"))
{
float temphp_fl = GetEntPropFloat(i, Prop_Send, "m_healthBuffer");
if (temphp_fl > 0.0)
Format(temphp, sizeof(temphp), "+T%i", RoundToCeil(temphp_fl));
}
int hp = GetClientHealth(i);
char status[128]; strcopy(status, sizeof(status), "");
if (IsPlayerAlive(i) && IsIncapacitated(i))
{ Format(status, sizeof(status), "[DOWN] %i", hp); }
else if (IsPlayerAlive(i))
{ Format(status, sizeof(status), "%i", hp); }
else
{ strcopy(status, sizeof(status), "DEAD"); }
char team_str[16]; strcopy(team_str, sizeof(team_str), "");
if (IsPassingSurvivor(i))
{ strcopy(team_str, sizeof(team_str), "T4 "); }
int character = GetEntProp(i, Prop_Send, "m_survivorCharacter");
char charletter[6];
GetCharacterLetter(character, charletter, sizeof(charletter));
Format(charletter, sizeof(charletter), " %s", charletter);
char name_and_hp[MAX_NAME_LENGTH+64];
Format(name_and_hp, sizeof(name_and_hp), "%s (%s%s%s%s)", name, team_str, status, temphp, charletter);
Format(number, sizeof(number), "%i", GetClientUserId(i));
AddMenuItem(menu, number, name_and_hp);
if (!hasEnt) hasEnt = true;
}
if (!hasEnt)
ShowWarning(client, 5);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return;
}
int ShowMenu_ChooseClient(Handle menu, MenuAction action, int client, int param2)
{
switch (action)
{
case MenuAction_Select:
{
if (!IsValidClient(client)) return;
char number[4];
GetMenuItem(menu, param2, number, sizeof(number));
int body = EntRefToEntIndex(g_iSelectedTarget[client]);
if (!IsValidEntity(body))
{ ShowWarning(client, 2); return; }
int target = GetClientOfUserId(StringToInt(number));
if (!IsValidClient(target))
{ ShowWarning(client, 0); return; }
PrintToChat(client, "[SM] Revived %N using a dead body with index: %i", target, EntRefToEntIndex(body));
DefibSurvivorAndModel(target, client, body);
CreateTimer(0.15, TimerOpenMenu_Sig, client);
}
case MenuAction_Cancel:
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, client, TopMenuPosition_LastCategory);
}
}
case MenuAction_End:
{
CloseHandle(menu);
}
}
}
Action TimerOpenMenu_Sig(Handle timer, int client)
{
if (!DoesEntityWithClassExist(DEATH_MODEL_CLASS)) return;
InitiateMenuAdminDefib_ChooseModel(client, 0);
}
// SIGNATURE End // -------------------------------------------------------- //
// VSCRIPT Start // -------------------------------------------------------- //
Action InitiateMenuAdminDefib_VScript(int client, int args)
{
if (!IsValidClient(client))
{
ShowWarning(client, -1);
return Plugin_Handled;
}
char name[32]; char number[10];
Handle menu = CreateMenu(ShowMenu);
//SetMenuTitle(menu, "Defib survivor:");
SetMenuTitle(menu, "Defib dead body:");
bool hasEnt = false;
for (int i = 1; i <= GetMaxEntities(); i++) // Get Survivor Models
{
if (!IsValidEntity(i)) continue;
char class[64];
GetEntityClassname(i, class, sizeof(class));
if (StrEqual(class, DEATH_MODEL_CLASS, false))
{
int character = GetEntProp(i, Prop_Send, "m_nCharacterType");
GetCharacterName(character, name, sizeof(name));
Format(number, sizeof(number), "%i", EntRefToEntIndex(i));
AddMenuItem(menu, number, name);
if (!hasEnt) hasEnt = true;
}
}
if (!hasEnt)
ShowWarning(client, 4);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
int ShowMenu(Handle menu, MenuAction action, int client, int param2)
{
switch (action)
{
case MenuAction_Select:
{
char number[4];
GetMenuItem(menu, param2, number, sizeof(number));
int ref = EntIndexToEntRef(StringToInt(number));
if (!IsValidEntity(ref))
{ CreateTimer(0.15, TimerOpenMenu_VScript, client); return; }
int character = GetEntProp(ref, Prop_Send, "m_nCharacterType");
for (int i = 1; i <= MaxClients; i++) // Survivor Model
{
if (!IsSurvivor(i) || IsPlayerAlive(i)) continue;
int cl_char = GetEntProp(i, Prop_Send, "m_survivorCharacter");
if (cl_char != character)
continue;
Logic_RunScript("GetPlayerFromUserID(%d).ReviveByDefib()", GetClientUserId(i));
CreateTimer(0.15, TimerOpenMenu_VScript, client);
return;
}
/*int target = GetClientOfUserId(StringToInt(number));
if (!IsClientInGame(target) || IsPlayerAlive(target) || (GetClientTeam(target) != 2 && GetClientTeam(target) != 4))
return;
Logic_RunScript("GetPlayerFromUserID(%d).ReviveByDefib()", GetClientUserId(target));*/
}
case MenuAction_Cancel:
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, client, TopMenuPosition_LastCategory);
}
}
case MenuAction_End:
{
CloseHandle(menu);
}
}
}
Action TimerOpenMenu_VScript(Handle timer, int client)
{
if (!DoesEntityWithClassExist(DEATH_MODEL_CLASS)) return;
InitiateMenuAdminDefib_VScript(client, 0);
}
// VSCRIPT End // -------------------------------------------------------- //
// AUTO SIG Start // -------------------------------------------------------- //
Action InitiateAdminDefib_Auto(int client, int args)
{
char arg[2];
GetCmdArg(1, arg, sizeof(arg));
int arg_int = -1;
if (!arg[0])
{ arg_int = 1; }
else
{ arg_int = StringToInt(arg); }
int bodyEnt = -1;
int clientEnt = -1;
for (int i = 1; i <= MaxClients; i++) // Get Clients
{
if (!IsSurvivor(i) || IsPlayerAlive(i)) continue;
clientEnt = i;
break;
}
//int temp = FindEntityByClassname(-1, DEATH_MODEL_CLASS);
//if (temp && IsValidEntity(temp)) bodyEnt = temp;
for (int i = 1; i <= GetMaxEntities(); i++) // Get Survivor Models
{
if (!IsValidEntity(i)) continue;
char class[64];
GetEntityClassname(i, class, sizeof(class));
if (!StrEqual(class, DEATH_MODEL_CLASS, false)) continue;
if ((arg_int & 1) && !ClientAndBodySameChar(clientEnt, i)) continue;
if ((arg_int & 2) && !ClientAndBodySameModel(clientEnt, i)) continue;
bodyEnt = i;
break;
}
bool hasFailed = false;
if (!IsValidEntity(bodyEnt) && !IsValidClient(clientEnt))
{ ShowWarning(client, 6); hasFailed = true; }
else if (!IsValidClient(clientEnt))
{ ShowWarning(client, 5); hasFailed = true; }
else if (!IsValidEntity(bodyEnt))
{ ShowWarning(client, 4); hasFailed = true; }
if (hasFailed) return Plugin_Handled;
DefibSurvivorAndModel(clientEnt, clientEnt, bodyEnt);
return Plugin_Handled;
}
// AUTO SIG End // -------------------------------------------------------- //
// TELEBODY Start // -------------------------------------------------------- //
Action TeleBody(int client, int args)
{
if (!IsValidClient(client))
{
ShowWarning(client, -1);
return Plugin_Handled;
}
for (int i = 1; i <= GetMaxEntities(); i++) // Get Survivor Models
{
if (!IsValidEntity(i)) continue;
char class[64];
GetEntityClassname(i, class, sizeof(class));
if (!StrEqual(class, DEATH_MODEL_CLASS, false)) continue;
float origin[3];
GetClientAbsOrigin(client, origin);
TeleportEntity(i, origin, NULL_VECTOR, NULL_VECTOR);
}
return Plugin_Handled;
}
// TELEBODY End // -------------------------------------------------------- //
// AUTOTIMER Start // -------------------------------------------------------- //
// Credits to Silvers V
void round_end(Event event, const char[] name, bool dontBroadcast)
{
/*for (int i = 1; i <= MaxClients; i++)
{
CloseHandle(g_hTimerRespawn[i]);
CloseHandle(g_hTempGod[i]);
}*/
for (int i = 1; i <= MaxClients; i++ )
{
g_bTimerRespawn[i] = false;
g_bTempGod[i] = false;
}
}
// end
void player_bot_replace(Event event, const char[] name, bool dontBroadcast) // Bot replaced a player
{
//PrintToChatAll("player_bot_replace:");
int client = GetClientOfUserId(event.GetInt("player"));
int bot = GetClientOfUserId(event.GetInt("bot"));
//PrintToChatAll("BEFORE: client g_fTimerRespawn: %f, bot g_fTimerRespawn: %f", g_fTimerRespawn[client], g_fTimerRespawn[bot]);
SwapTimers(client, bot);
HookThink(client);
HookThink(bot);
//PrintToChatAll("AFTER: client g_fTimerRespawn: %f, bot g_fTimerRespawn: %f", g_fTimerRespawn[client], g_fTimerRespawn[bot]);
}
void bot_player_replace(Event event, const char[] name, bool dontBroadcast) // Player replaced a bot
{
//PrintToChatAll("bot_player_replace:");
int client = GetClientOfUserId(event.GetInt("player"));
int bot = GetClientOfUserId(event.GetInt("bot"));
//PrintToChatAll("BEFORE: client g_fTimerRespawn: %f, bot g_fTimerRespawn: %f", g_fTimerRespawn[client], g_fTimerRespawn[bot]);
SwapTimers(bot, client);
HookThink(bot);
HookThink(client);
//PrintToChatAll("AFTER: client g_fTimerRespawn: %f, bot g_fTimerRespawn: %f", g_fTimerRespawn[client], g_fTimerRespawn[bot]);
}
/*void Move1stTimersTo2ndTimers(int client, int other)
{
g_fTimerRespawn[other] = g_fTimerRespawn[client];
g_bTimerRespawn[other] = g_bTimerRespawn[client];
g_iChosenBody[other] = g_iChosenBody[client];
g_bIsVScript[other] = g_bIsVScript[client];
g_fTempGod[other] = g_fTempGod[client];
g_bTempGod[other] = g_bTempGod[client];
g_fTimeTilSafe[other] = g_fTimeTilSafe[client];
g_iNumOfDeathOnAD[other] = g_iNumOfDeathOnAD[client];
}*/
void SwapTimers(int client, int other)
{
// yes, this is messy, but idk what else to do :(
float g_fTimerRespawn_backup = g_fTimerRespawn[other];
bool g_bTimerRespawn_backup = g_bTimerRespawn[other];
int g_iChosenBody_backup = g_iChosenBody[other];
bool g_bIsVScript_backup = g_bIsVScript[other];
float g_fTempGod_backup = g_fTempGod[other];
bool g_bTempGod_backup = g_bTempGod[other];
float g_fTimeTilSafe_backup = g_fTimeTilSafe[other];
int g_iNumOfDeathOnAD_backup = g_iNumOfDeathOnAD[other];
// Backup the timers for other
// Set the timers of 'other' to 'client'
g_fTimerRespawn[other] = g_fTimerRespawn[client];
g_bTimerRespawn[other] = g_bTimerRespawn[client];
g_iChosenBody[other] = g_iChosenBody[client];
g_bIsVScript[other] = g_bIsVScript[client];
g_fTempGod[other] = g_fTempGod[client];
g_bTempGod[other] = g_bTempGod[client];
g_fTimeTilSafe[other] = g_fTimeTilSafe[client];
g_iNumOfDeathOnAD[other] = g_iNumOfDeathOnAD[client];
// Then use the backed-up 'other' variables for 'client'
g_fTimerRespawn[client] = g_fTimerRespawn_backup;
g_bTimerRespawn[client] = g_bTimerRespawn_backup;
g_iChosenBody[client] = g_iChosenBody_backup;
g_bIsVScript[client] = g_bIsVScript_backup;
g_fTempGod[client] = g_fTempGod_backup;
g_bTempGod[client] = g_bTempGod_backup;
g_fTimeTilSafe[client] = g_fTimeTilSafe_backup;
g_iNumOfDeathOnAD[client] = g_iNumOfDeathOnAD_backup;
}
/*void ClearTimers(int client)
{
g_fTimerRespawn[client] = -1.0;
g_bTimerRespawn[client] = false;
g_iChosenBody[client] = -1;
g_bIsVScript[client] = false;
g_fTempGod[client] = -1.0;
g_bTempGod[client] = false;
g_fTimeTilSafe[client] = -1.0;
g_iNumOfDeathOnAD[client] = 0;
}*/
void player_death(Event event, const char[] name, bool dontBroadcast)
{
float cvar_time = GetConVarFloat(Defib_AutoTimer);
if (cvar_time <= 0.0) return;
int client = GetClientOfUserId(event.GetInt("userid"));
if (!IsValidClient(client)) return;
//CloseHandle(g_hTimerRespawn[client]);
//CloseHandle(g_hTempGod[client]);
g_bTimerRespawn[client] = false;
g_bTempGod[client] = false;
if (!IsSurvivor(client) || IsPlayerAlive(client)) return;
float game_time = GetGameTime();
int max_deaths = GetConVarInt(Defib_AutoTimerSpawnKill);
if (max_deaths > 0)
{
// Check if the 'time til safe' timer is still active when the player died...
if (g_fTimeTilSafe[client] > game_time)
{
g_iNumOfDeathOnAD[client]++;
if (g_iNumOfDeathOnAD[client] >= max_deaths)
{
PrintToChat(client, "You will no longer be auto-defibbed again.");
g_fTimeTilSafe[client] = -1.0;
g_iNumOfDeathOnAD[client] = 0;
return;
}
else
{
int deaths_remaining = max_deaths-g_iNumOfDeathOnAD[client];
char temp_str[2];
if (deaths_remaining != 1)
{ strcopy(temp_str, sizeof(temp_str), "s"); }
PrintToChat(client, "You died whilst you were getting auto-defibbed. %i more death%s until your auto-defib stops.",
deaths_remaining, temp_str);
}
}
else
{
g_iNumOfDeathOnAD[client] = 0;
}
}
if (GetConVarBool(Defib_AutoTimerMode))
{
g_bIsVScript[client] = false;
g_iChosenBody[client] = GetSpawnedBodyForSurvivor(client);
}
else
{
g_bIsVScript[client] = true;
}
g_fTimerRespawn[client] = game_time+cvar_time;
g_bTimerRespawn[client] = true;
HookThink(client);
/*if (GetConVarBool(Defib_AutoTimerMode))
{
// If true, use Signature.
int body = GetSpawnedBodyForSurvivor(client);
DataPack data = CreateDataPack();
data.WriteCell(client);
data.WriteCell(body);
g_hTimerRespawn[client] = CreateTimer(cvar_time, AutoTimer_Defib, data, TIMER_FLAG_NO_MAPCHANGE);
}
else
{ g_hTimerRespawn[client] = CreateTimer(cvar_time, AutoTimer_DefibVScript, client, TIMER_FLAG_NO_MAPCHANGE); } // Choose VScript*/
}
/*Action AutoTimer_DefibVScript(Handle timer, int client)
{
if (!IsValidClient(client)) return;
g_hTimerRespawn[client] = null;
if (!IsSurvivor(client)) return;
if (!IsPlayerAlive(client))
{
Logic_RunScript("GetPlayerFromUserID(%d).ReviveByDefib()", GetClientUserId(client));
if (IsPlayerAlive(client))
{ GiveTempGod(client); }
}
}
Action AutoTimer_Defib(Handle timer, DataPack data)
{
data.Reset();
int client = data.ReadCell();
int body = data.ReadCell();
if (data != null)
{ CloseHandle(data); }
//PrintToChatAll("%i", body);
if (!IsValidClient(client) || !IsValidEntity(body)) return;
g_hTimerRespawn[client] = null;
DefibSurvivorAndModel(client, client, body);
GiveTempGod(client);
}*/
// end
// AUTOTIMER End // -------------------------------------------------------- //
// Non-Handle Timers Start // -------------------------------------------------------- //
void HookThink(int entity, bool boolean = true)
{
if (!IsValidClient(entity)) return;
if (boolean)
{ SDKHook(entity, POST_THINK_HOOK, Hook_OnThinkPost); g_fClientWait[entity] = 0.0; }
else
{ SDKUnhook(entity, POST_THINK_HOOK, Hook_OnThinkPost); }
}
void Hook_OnThinkPost(int client)
{
if (!IsServerProcessing()) return;
if (IsValidClient(client))
{
if (GetGameTime() - g_fClientWait[client] >= 0.0)
{
UpdateTimers(client);
g_fClientWait[client] = g_fClientWait[client] + THINK_WAITTIME;
}
}
}
void UpdateTimers(int client)
{
float game_time = GetGameTime();
if (g_fTimerRespawn[client] <= game_time && g_bTimerRespawn[client])
{
Timer_TimerRespawn(client);
g_bTimerRespawn[client] = false;
g_fTimerRespawn[client] = -1.0;
}
if (g_fTempGod[client] <= game_time && g_bTempGod[client])
{
Timer_TempGod(client);
g_bTempGod[client] = false;
g_fTempGod[client] = -1.0;
}
if (!g_bTimerRespawn[client] && !g_bTempGod[client])
{ HookThink(client, false); }
}
void Timer_TimerRespawn(int client)
{
// We update the 'time til safe' timer when either this timer or the godmode timer ends
float game_time = GetGameTime();
g_fTimeTilSafe[client] = game_time+GetConVarFloat(Defib_AutoTimerSafety);
if (g_bIsVScript[client])
{ Timer_TimerRespawn_VScript(client); }
else
{ Timer_TimerRespawn_Sig(client); }
}
void Timer_TimerRespawn_Sig(int client)
{
int body = g_iChosenBody[client];
if (!IsSurvivor(client) || (body <= 0 || !IsValidEntity(body))) return;
g_iChosenBody[client] = -1;
DefibSurvivorAndModel(client, client, body);
GiveTempGod(client);
TimerRespawn_TeleClientToOther(client);
}
void Timer_TimerRespawn_VScript(int client)
{
if (!IsSurvivor(client)) return;
if (!IsPlayerAlive(client))
{
Logic_RunScript("GetPlayerFromUserID(%d).ReviveByDefib()", GetClientUserId(client));
if (IsPlayerAlive(client))
{
GiveTempGod(client);
TimerRespawn_TeleClientToOther(client);
}
}
}
void TimerRespawn_TeleClientToOther(int client)
{
if (!GetConVarBool(Defib_AutoTimerTeleport)) return;
float cl_origin[3];
GetClientAbsOrigin(client, cl_origin);
int nearest_surv = GetNearestGroundSurvivor(cl_origin);
if (IsGameSurvivor(nearest_surv))
{
float other_origin[3];
GetClientAbsOrigin(nearest_surv, other_origin);
TeleportEntity(client, other_origin, NULL_VECTOR, NULL_VECTOR);
}
}
void Timer_TempGod(int client)
{
if (!IsSurvivor(client)) return;
float game_time = GetGameTime();
g_fTimeTilSafe[client] = game_time+GetConVarFloat(Defib_AutoTimerSafety);
g_bTempGod[client] = false;
SetEntProp(client, Prop_Data, "m_takedamage", 2);
PrintToChat(client, "Your temporary godmode has ran out.");
if (GetConVarInt(incap_cvar) > 0 && !(GetConVarInt(Defib_AutoTimerBAW) & BITFLAG_BAW_AUTO))
{
Logic_RunScript("GetPlayerFromUserID(%d).SetReviveCount(0)", GetClientUserId(client));
}
else if (GetConVarInt(Defib_AutoTimerBAW) & BITFLAG_BAW_AUTO)
{
ConvertHPToTemp(client);
}
}
// Non-Handle Timers End // -------------------------------------------------------- //
// Others Start // -------------------------------------------------------- //
void ConvertHPToTemp(int client)
{
int health = GetClientHealth(client);
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", health+1.0);
SetEntityHealth(client, 1);
}
int GetNearestGroundSurvivor(const float posToCheck[3])
{
int result = -1;
float distance = -1.0;
for (int client = 1; client <= MaxClients; client++)
{
if (!IsGameSurvivor(client) || !IsPlayerAlive(client) || IsIncapacitated(client, 1)) continue;
if (!HasEntProp(client, Prop_Send, "m_hGroundEntity") || GetEntProp(client, Prop_Send, "m_hGroundEntity") < 0) continue;
float cl_origin[3];
GetClientAbsOrigin(client, cl_origin);
float temp_dis = GetVectorDistance(posToCheck, cl_origin, true);
if (distance > 0.0 && temp_dis > distance) continue;
result = client;
distance = temp_dis;
}
return result;
}
bool DoesEntityWithClassExist(const char[] class)
{
int entity = FindEntityByClassname(-1, class);
if (!entity || !IsValidEntity(entity)) return false;
return true;
}
void GiveTempGod(int client)
{
float cvar_time = GetConVarFloat(Defib_TempGodTimer);
if (cvar_time <= 0.0) return;
if (!IsValidClient(client)) return;
int incap_cv_int = GetConVarInt(incap_cvar);
SetEntProp(client, Prop_Data, "m_takedamage", 0);