-
Notifications
You must be signed in to change notification settings - Fork 22
/
zp_addon_grenade_modes.sp
1363 lines (1121 loc) · 34.9 KB
/
zp_addon_grenade_modes.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
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
/**
* ============================================================================
*
* Zombie Plague
*
*
* Copyright (C) 2015-2023 qubka (Nikita Ushakov)
*
* 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/>.
*
* ============================================================================
**/
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <zombieplague>
#pragma newdecls required
#pragma semicolon 1
/**
* @brief Record plugin info.
**/
public Plugin myinfo =
{
name = "[ZP] Addon: Grenade Modes",
author = "qubka (Nikita Ushakov), Nyuu",
description = "Adds 6 new modes for all the grenades",
version = "2.0",
url = "https://forums.alliedmods.net/showthread.php?t=290657"
}
/**
* @section Information about the addon.
**/
#define GRENADE_SELF_COLOR {125, 0, 125, 255} // The color of the self effects
#define GRENADE_TEAMMATE_COLOR {0, 125, 0, 255} // The color of the teammate effects
#define GRENADE_ENEMY_COLOR {125, 0, 0, 255} // The color of the enemy effects
/**
* @endsection
**/
/**
* @section Grenade modes.
**/
enum
{
GRENADE_MODE_NORMAL,
GRENADE_MODE_IMPACT,
GRENADE_MODE_PROXIMITY,
GRENADE_MODE_TRIPWIRE,
GRENADE_MODE_SATCHEL,
GRENADE_MODE_HOMING,
GRENADE_MODE_SENSOR,
GRENADE_MODE_MAXIMUM
};
/**
* @endsection
**/
/**
* @section Proximity states. (Sensor)
**/
enum
{
PROXIMITY_STATE_WAIT_IDLE,
PROXIMITY_STATE_POWERUP,
PROXIMITY_STATE_DETECT
};
/**
* @endsection
**/
/**
* @section Tripwire states.
**/
enum
{
TRIPWIRE_STATE_POWERUP,
TRIPWIRE_STATE_DETECT
};
/**
* @endsection
**/
/**
* @section Satchel states.
**/
enum
{
SATCHEL_STATE_POWERUP,
SATCHEL_STATE_ENABLED
};
/**
* @endsection
**/
// Grenade mode names
static const char sModes[GRENADE_MODE_MAXIMUM][SMALL_LINE_LENGTH] =
{
"normal", // NORMAL
"impact", // IMPACT
"proximity", // PROXIMITY
"trip wire", // TRIPWIRE
"satchel charge", // SATCHEL
"homing", // HOMING
"motion sensor" // SENSOR
};
// Decal index
int gBeacon; int gBeam; int gHalo;
// Player index
int iGrenadeMode[MAXPLAYERS+1]; ArrayList hGrenadeList[MAXPLAYERS+1] = { null, ... };
// Cvars
ConVar hCvarGrenadeDamageMode;
ConVar hCvarGrenadeProximityPowerupTime;
ConVar hCvarGrenadeProximityRadius;
ConVar hCvarGrenadeSensorActivate;
ConVar hCvarGrenadeTripwirePowerupTime;
ConVar hCvarGrenadeTripwireDistance;
ConVar hCvarGrenadeSatchelPowerupTime;
ConVar hCvarGrenadeSatchelRadius;
ConVar hCvarGrenadeHomingRadius;
ConVar hCvarGrenadeHomingSpeed;
ConVar hCvarGrenadeHomingRotation;
ConVar hCvarGrenadeHomingAvoid;
/**
* @brief Called when the plugin is fully initialized and all known external references are resolved.
* This is only called once in the lifetime of the plugin, and is paired with OnPluginEnd().
**/
public void OnPluginStart()
{
hCvarGrenadeDamageMode = CreateConVar("zp_grenade_modes_damage_mode", "1", "Allow activation from the other damage", 0, true, 0.0, true, 1.0);
hCvarGrenadeProximityPowerupTime = CreateConVar("zp_grenade_modes_proximity_powerup_time", "2.0", "Proximity powerup time", 0, true, 0.0);
hCvarGrenadeProximityRadius = CreateConVar("zp_grenade_modes_proximity_radius", "100.0", "Radius of detection", 0, true, 0.0);
hCvarGrenadeSensorActivate = CreateConVar("zp_grenade_modes_sensor_activate", "100.0", "Speed of the enemy to activate", 0, true, 0.0);
hCvarGrenadeTripwirePowerupTime = CreateConVar("zp_grenade_modes_tripwire_powerup_time", "2.0", "Tripwire powerup time", 0, true, 0.0);
hCvarGrenadeTripwireDistance = CreateConVar("zp_grenade_modes_tripwire_distance", "8192.0", "Tripwire distance", 0, true, 0.0);
hCvarGrenadeSatchelPowerupTime = CreateConVar("zp_grenade_modes_satchel_powerup_time", "1.5", "Satchel powerup time", 0, true, 0.0);
hCvarGrenadeSatchelRadius = CreateConVar("zp_grenade_modes_satchel_radius", "25.0", "Satchel effect radius", 0, true, 0.0);
hCvarGrenadeHomingRadius = CreateConVar("zp_grenade_modes_homing_radius", "500.0", "Radius of homing", 0, true, 0.0);
hCvarGrenadeHomingSpeed = CreateConVar("zp_grenade_modes_homing_speed", "500.0", "Speed of homing", 0, true, 0.0);
hCvarGrenadeHomingRotation = CreateConVar("zp_grenade_modes_homing_rotation", "0.5", "Speed of rotation", 0, true, 0.0);
hCvarGrenadeHomingAvoid = CreateConVar("zp_grenade_modes_homing_avoid", "100.0", "Range of avoid homing", 0, true, 0.0);
AutoExecConfig(true, "zp_addon_grenade_modes", "sourcemod/zombieplague");
}
/**
* @brief Called after a library is added that the current plugin references optionally.
* A library is either a plugin name or extension name, as exposed via its include file.
**/
public void OnLibraryAdded(const char[] sLibrary)
{
if (!strcmp(sLibrary, "zombieplague", false))
{
LoadTranslations("grenade_modes.phrases");
}
}
/**
* @brief The map is starting.
**/
public void OnMapStart()
{
gBeacon = PrecacheModel("materials/sprites/physbeam.vmt", true);
gBeam = PrecacheModel("materials/sprites/purplelaser1.vmt", true);
gHalo = PrecacheModel("materials/sprites/purpleglow1.vmt", true);
PrecacheSound("buttons/blip1.wav", true);
PrecacheSound("buttons/blip2.wav", true);
}
/**
* @brief Called when a client is disconnecting from the server.
*
* @param client The client index.
**/
public void OnClientDisconnect(int client)
{
GrenadeActivate(client);
}
/**
* @brief Called when a client has been killed.
*
* @param client The client index.
* @param attacker The attacker index.
**/
public void ZP_OnClientDeath(int client, int attacker)
{
GrenadeActivate(client);
}
/**
* @brief Called when a client became a zombie/human.
*
* @param client The client index.
* @param attacker The attacker index.
**/
public void ZP_OnClientUpdated(int client, int attacker)
{
GrenadeActivate(client);
}
//**********************************************
//* Grenade (common) function. *
//**********************************************
/**
* @brief Called on each frame of a weapon holding.
*
* @param client The client index.
* @param iButtons The buttons buffer.
* @param iLastButtons The last buttons buffer.
* @param weapon The weapon index.
* @param weaponID The weapon id.
*
* @return Plugin_Continue to allow buttons. Anything else
* (like Plugin_Changed) to change buttons.
**/
public Action ZP_OnWeaponRunCmd(int client, int &iButtons, int iLastButtons, int weapon, int weaponID)
{
if (iButtons & IN_RELOAD && !(iLastButtons & IN_RELOAD))
{
ItemDef iItem = ZP_GetWeaponDefIndex(weaponID);
if (IsProjectile(iItem))
{
int iMode = iGrenadeMode[client];
iMode = (iMode + 1) % GRENADE_MODE_MAXIMUM;
iGrenadeMode[client] = iMode;
SetGlobalTransTarget(client);
PrintHintText(client, "%t", "grenade mode", sModes[iMode]);
EmitSoundToClient(client, SOUND_INFO_TIPS, SOUND_FROM_PLAYER, SNDCHAN_ITEM);
}
}
else if (iButtons & IN_ATTACK2 && !(iLastButtons & IN_ATTACK2))
{
if (IsPlayerAlive(client))
{
GrenadeActivate(client);
}
}
return Plugin_Continue;
}
/**
* @brief Called after a custom grenade is created.
*
* @param client The client index.
* @param grenade The grenade index.
* @param weaponID The weapon id.
**/
public void ZP_OnGrenadeCreated(int client, int grenade, int weaponID)
{
DataPack hPack = new DataPack();
hPack.WriteCell(GetClientUserId(client));
hPack.WriteCell(EntIndexToEntRef(grenade));
hPack.WriteCell(weaponID);
RequestFrame(ZP_OnGrenadeCreatedPost, hPack);
}
/**
* @brief Called after a custom grenade is created.
*
* @param hPack The pack handle.
**/
public void ZP_OnGrenadeCreatedPost(DataPack hPack)
{
hPack.Reset();
int client = GetClientOfUserId(hPack.ReadCell());
int grenade = EntRefToEntIndex(hPack.ReadCell());
int weaponID = hPack.ReadCell();
delete hPack;
if (!client || grenade == -1)
{
return;
}
if (GetEntProp(grenade, Prop_Data, "m_nNextThinkTick") == -1)
{
return;
}
ItemDef iItem = ZP_GetWeaponDefIndex(weaponID);
if (IsProjectile(iItem))
{
int owner = GetEntPropEnt(grenade, Prop_Data, "m_hOwnerEntity");
if (owner != -1)
{
switch (iGrenadeMode[owner])
{
case GRENADE_MODE_NORMAL :
{
}
case GRENADE_MODE_IMPACT :
{
SetEntProp(grenade, Prop_Data, "m_nNextThinkTick", -1);
SDKHook(grenade, SDKHook_TouchPost, GrenadeImpactTouchPost);
}
case GRENADE_MODE_TRIPWIRE :
{
SetEntProp(grenade, Prop_Data, "m_nNextThinkTick", -1);
SetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget", false);
SetEntProp(grenade, Prop_Data, "m_iHammerID", TRIPWIRE_STATE_POWERUP);
SetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime", hCvarGrenadeTripwirePowerupTime.FloatValue);
SDKHook(grenade, SDKHook_Touch, GrenadeTripwireTouch);
}
case GRENADE_MODE_PROXIMITY, GRENADE_MODE_SENSOR :
{
SetEntProp(grenade, Prop_Data, "m_nNextThinkTick", -1);
SetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget", (iGrenadeMode[owner] == GRENADE_MODE_SENSOR));
SetEntProp(grenade, Prop_Data, "m_iHammerID", PROXIMITY_STATE_WAIT_IDLE);
SetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime", 0.0);
CreateTimer(0.1, GrenadeProximityThinkHook, EntIndexToEntRef(grenade), TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
SDKHook(grenade, SDKHook_Touch, GrenadeProximityTouch);
}
case GRENADE_MODE_SATCHEL :
{
SetEntProp(grenade, Prop_Data, "m_nNextThinkTick", -1);
SetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget", false);
SetEntProp(grenade, Prop_Data, "m_iHammerID", SATCHEL_STATE_POWERUP);
SetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime", hCvarGrenadeSatchelPowerupTime.FloatValue);
SDKHook(grenade, SDKHook_Touch, GrenadeSatchelTouch);
GrenadePush(client, grenade);
SetGlobalTransTarget(client);
PrintHintText(client, "%t", "satchel info");
EmitSoundToClient(client, SOUND_INFO_TIPS, SOUND_FROM_PLAYER, SNDCHAN_ITEM);
}
case GRENADE_MODE_HOMING :
{
SetEntProp(grenade, Prop_Data, "m_iHammerID", GetEntProp(grenade, Prop_Data, "m_iTeamNum"));
SetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime", 0.0);
CreateTimer(0.1, GrenadeHomingThinkHook, EntIndexToEntRef(grenade), TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
}
}
}
}
/**
* @brief Grenade damage hook.
*
* @param grenade The entity index.
* @param attacker The attacker index.
* @param inflictor The inflictor index.
* @param damage The amount of damage inflicted.
* @param damageBits The type of damage inflicted.
**/
public Action GrenadeDamageHook(int grenade, int &attacker, int &inflictor, float &flDamage, int &damageBits)
{
if (hCvarGrenadeDamageMode.BoolValue)
{
if (IsClientValid(attacker))
{
int iTeam = GetEntProp(grenade, Prop_Data, "m_iTeamNum");
if (ZP_GetPlayerTeam(attacker) == iTeam)
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}
return Plugin_Handled;
}
//**********************************************
//* Grenade (impact) function. *
//**********************************************
/**
* @brief Called right after the grenade touch other entity.
*
* @param grenade The grenade index.
* @param target The entity index of the entity being touched.
**/
public void GrenadeImpactTouchPost(int grenade, int target)
{
int owner = GetEntPropEnt(grenade, Prop_Data, "m_hOwnerEntity");
if (owner == target)
{
return;
}
GrenadeDetonate(grenade);
}
/**
* @brief Timer for detonate grenade.
*
* @param hTimer The timer handle.
* @param refID The reference index.
**/
public Action GrenadeDetonateHook(Handle hTimer, int refID)
{
int grenade = EntRefToEntIndex(refID);
if (grenade != -1)
{
GrenadeDetonate(grenade);
}
return Plugin_Stop;
}
//**********************************************
//* Grenade (proximity/sensor) function. *
//**********************************************
/**
* @brief Called right before the grenade touch other entity.
*
* @param grenade The grenade index.
* @param target The entity index of the entity being touched.
**/
public Action GrenadeProximityTouch(int grenade, int target)
{
return Plugin_Handled;
}
/**
* @brief Move to another state.
*
* @param grenade The grenade index.
* @param iState The state index.
* @param flCounter The counter timer.
**/
Action GrenadeProximityThinkWaitIdle(int grenade, int &iState, float &flCounter)
{
static float vVelocity[3];
GetEntPropVector(grenade, Prop_Data, "m_vecVelocity", vVelocity);
if (GetVectorLength(vVelocity, true) <= 0.0)
{
GrenadeSetBreakable(grenade);
iState = PROXIMITY_STATE_POWERUP;
flCounter = hCvarGrenadeProximityPowerupTime.FloatValue;
}
return Plugin_Continue;
}
/**
* @brief Emit proximity sounds.
*
* @param grenade The grenade index.
* @param iState The state index.
* @param flCounter The counter timer.
**/
Action GrenadeProximityThinkPowerUp(int grenade, int &iState, float &flCounter)
{
int iCounter = RoundToNearest(flCounter * 10.0);
if (flCounter <= 0.0)
{
EmitSoundToAll("buttons/blip2.wav", grenade, _);
iState = PROXIMITY_STATE_DETECT;
flCounter = 0.0;
}
else if (!(iCounter % 2))
{
int iPitch = 200 - iCounter * 4;
if (iPitch <= 100)
{
iPitch = 100;
}
EmitSoundToAll("buttons/blip1.wav", grenade, _, _, _, _, iPitch);
}
return Plugin_Continue;
}
/**
* @brief Detect any victims.
*
* @param grenade The grenade index.
* @param iState The state index.
* @param flCounter The counter timer.
**/
Action GrenadeProximityThinkDetect(int grenade, int &iState, float &flCounter)
{
int owner = GetEntPropEnt(grenade, Prop_Data, "m_hOwnerEntity");
if (owner != -1)
{
static float vPosition[3]; static float vPosition2[3]; static float vVelocity[3];
GetEntPropVector(grenade, Prop_Data, "m_vecAbsOrigin", vPosition);
bool bDetonate; int iTeam = GetEntProp(grenade, Prop_Data, "m_iTeamNum");
bool bSensor = view_as<bool>(GetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget"));
float flRadius = hCvarGrenadeProximityRadius.FloatValue;
float flRadius2 = flRadius * flRadius;
float flSensorActivate = hCvarGrenadeSensorActivate.FloatValue;
float flSensorActivate2 = flSensorActivate * flSensorActivate;
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientValid(i) || ZP_GetPlayerTeam(i) == iTeam)
{
continue;
}
GetEntPropVector(i, Prop_Data, "m_vecAbsOrigin", vPosition2);
if (GetVectorDistance(vPosition, vPosition2, true) > flRadius2)
{
continue;
}
if (bSensor)
{
GetEntPropVector(i, Prop_Data, "m_vecVelocity", vVelocity);
if (GetVectorLength(vVelocity, true) < flSensorActivate2)
{
continue;
}
}
bDetonate = true;
}
if (bDetonate)
{
CreateTimer(0.1, GrenadeDetonateHook, EntIndexToEntRef(grenade), TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
if (flCounter <= 0.0)
{
static int iPlayers[MAXPLAYERS+1]; static int vColor[4];
int iMaxPlayers = GetClientsInRange(vPosition, RangeType_Audibility, iPlayers, MaxClients);
for (int i = 0 ; i < iMaxPlayers ; i++)
{
int client = iPlayers[i];
if (ZP_GetPlayerTeam(client) == iTeam)
{
vColor = (client == owner) ? GRENADE_SELF_COLOR : GRENADE_TEAMMATE_COLOR;
}
else
{
vColor = GRENADE_ENEMY_COLOR;
}
TE_SetupBeamRingPoint(vPosition, bSensor ? flRadius : 0.0, flRadius * 2.0, gBeacon, gHalo, 0, 0, 0.5, 4.0, 0.0, vColor, 30, 0);
TE_SendToClient(client);
}
flCounter = 1.0;
}
}
else
{
CreateTimer(GetRandomFloat(0.5, 2.0), GrenadeDetonateHook, EntIndexToEntRef(grenade), TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
return Plugin_Continue;
}
/**
* @brief Timer for proximity think.
*
* @param hTimer The timer handle.
* @param refID The reference index.
**/
public Action GrenadeProximityThinkHook(Handle hTimer, int refID)
{
int grenade = EntRefToEntIndex(refID);
Action hResult = Plugin_Stop;
if (grenade != -1)
{
int iState = GetEntProp(grenade, Prop_Data, "m_iHammerID");
float flCounter = GetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime");
if (flCounter > 0.0)
{
flCounter -= 0.1;
}
switch (iState)
{
case PROXIMITY_STATE_WAIT_IDLE :
{
hResult = GrenadeProximityThinkWaitIdle(grenade, iState, flCounter);
}
case PROXIMITY_STATE_POWERUP :
{
hResult = GrenadeProximityThinkPowerUp(grenade, iState, flCounter);
}
case PROXIMITY_STATE_DETECT :
{
hResult = GrenadeProximityThinkDetect(grenade, iState, flCounter);
}
}
SetEntProp(grenade, Prop_Data, "m_iHammerID", iState);
SetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime", flCounter);
}
return hResult;
}
//**********************************************
//* Grenade (tripwire) function. *
//**********************************************
/**
* @brief Called right before the grenade touch other entity.
*
* @param grenade The grenade index.
* @param target The entity index of the entity being touched.
**/
public Action GrenadeTripwireTouch(int grenade, int target)
{
if (!GetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget"))
{
if (!target || ZP_IsBSPModel(target))
{
GrenadeTripwireTrackWall(grenade);
}
}
SetEntProp(grenade, Prop_Data, "m_nSolidType", SOLID_NONE);
SetEntProp(grenade, Prop_Send, "m_CollisionGroup", COLLISION_GROUP_NONE);
return Plugin_Handled;
}
/**
* @brief Move to another state.
*
* @param grenade The grenade index.
**/
void GrenadeTripwireTrackWall(int grenade)
{
static float vPosition[3]; static float vEndPosition[3]; static float vNormal[3];
static const int vLoop[6][2] = { {2, 1}, {2, -1}, {0, 1}, {0, -1}, {1, 1}, {1, -1} };
GetEntPropVector(grenade, Prop_Data, "m_vecAbsOrigin", vPosition);
int victim; float flFraction; float flBestFraction = 1.0;
for (int i = 0; i < 6; i++)
{
vEndPosition[vLoop[i][0]] = vPosition[vLoop[i][0]] + (2.0 * float(vLoop[i][1]));
Handle hTrace = TR_TraceRayFilterEx(vPosition, vEndPosition, MASK_SOLID, RayType_EndPoint, PlayerFilter, grenade);
if (!TR_DidHit(hTrace))
{
static const float vMins[3] = { -16.0, -16.0, -18.0 };
static const float vMaxs[3] = { 16.0, 16.0, 18.0 };
delete hTrace;
hTrace = TR_TraceHullFilterEx(vPosition, vEndPosition, vMins, vMaxs, MASK_SHOT_HULL, PlayerFilter, grenade);
if (TR_DidHit(hTrace))
{
victim = TR_GetEntityIndex(hTrace);
if (victim < 1 || ZP_IsBSPModel(victim))
{
UTIL_FindHullIntersection(hTrace, vPosition, vMins, vMaxs, PlayerFilter, grenade);
}
}
}
if (TR_DidHit(hTrace))
{
victim = TR_GetEntityIndex(hTrace);
if (victim < 1 || ZP_IsBSPModel(victim))
{
flFraction = TR_GetFraction(hTrace);
if (flBestFraction > flFraction)
{
flBestFraction = flFraction;
TR_GetEndPosition(vEndPosition, hTrace);
TR_GetPlaneNormal(hTrace, vNormal);
}
}
}
delete hTrace;
}
if (flBestFraction < 1.0)
{
TeleportEntity(grenade, vEndPosition, NULL_VECTOR, NULL_VECTOR);
ScaleVector(vNormal, hCvarGrenadeTripwireDistance.FloatValue);
AddVectors(vNormal, vPosition, vEndPosition);
TR_TraceRayFilter(vPosition, vEndPosition, MASK_SOLID, RayType_EndPoint, PlayerFilter, grenade);
TR_GetEndPosition(vEndPosition);
SetEntPropVector(grenade, Prop_Data, "m_vecViewOffset", vEndPosition);
CreateTimer(0.1, GrenadeTripwireThinkHook, EntIndexToEntRef(grenade), TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
SetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget", true);
SetEntityMoveType(grenade, MOVETYPE_NONE);
GrenadeSetBreakable(grenade);
}
else
{
CreateTimer(GetRandomFloat(0.5, 2.0), GrenadeDetonateHook, EntIndexToEntRef(grenade), TIMER_FLAG_NO_MAPCHANGE);
}
}
/**
* @brief Emit tripwire sounds.
*
* @param grenade The grenade index.
* @param iState The state index.
* @param flCounter The counter timer.
**/
Action GrenadeTripwireThinkPowerUp(int grenade, int &iState, float &flCounter)
{
int iCounter = RoundToNearest(flCounter * 10.0);
if (flCounter <= 0.0)
{
EmitSoundToAll("buttons/blip2.wav", grenade);
iState = TRIPWIRE_STATE_DETECT;
flCounter = 0.0;
}
else if (!(iCounter % 2))
{
int iPitch = 200 - iCounter * 4;
if (iPitch <= 100)
{
iPitch = 100;
}
EmitSoundToAll("buttons/blip1.wav", grenade, _, _, _, _, iPitch);
}
return Plugin_Continue;
}
/**
* @brief Detect any victims.
*
* @param grenade The grenade index.
* @param iState The state index.
* @param flCounter The counter timer.
**/
Action GrenadeTripwireThinkDetect(int grenade, int &iState, float &flCounter)
{
int owner = GetEntPropEnt(grenade, Prop_Data, "m_hOwnerEntity");
if (owner != -1)
{
static float vPosition[3]; static float vEndPosition[3];
GetEntPropVector(grenade, Prop_Data, "m_vecAbsOrigin", vPosition);
GetEntPropVector(grenade, Prop_Data, "m_vecViewOffset", vEndPosition);
bool bDetonate; int iTeam = GetEntProp(grenade, Prop_Data, "m_iTeamNum");
TR_TraceRayFilter(vPosition, vEndPosition, (MASK_SHOT|CONTENTS_GRATE), RayType_EndPoint, SelfFilter, grenade);
if (TR_DidHit())
{
TR_GetEndPosition(vEndPosition);
int victim = TR_GetEntityIndex();
if ((IsClientValid(victim)) && (ZP_GetPlayerTeam(victim) != iTeam))
{
bDetonate = true;
}
}
if (bDetonate)
{
CreateTimer(0.1, GrenadeDetonateHook, EntIndexToEntRef(grenade), TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
if (flCounter <= 0.0)
{
static int iPlayers[MAXPLAYERS+1]; static int vColor[4];
int iMaxPlayers = GetClientsInRange(vPosition, RangeType_Audibility, iPlayers, MaxClients);
for (int i = 0; i < iMaxPlayers; i++)
{
int client = iPlayers[i];
if (ZP_GetPlayerTeam(client) == iTeam)
{
vColor = (client == owner) ? GRENADE_SELF_COLOR : GRENADE_TEAMMATE_COLOR;
}
else
{
vColor = GRENADE_ENEMY_COLOR;
}
TE_SetupBeamPoints(vPosition, vEndPosition, gBeam, gHalo, 0, 0, 0.1, 8.0, 8.0, 0, 0.0, vColor, 30);
TE_SendToClient(client);
}
flCounter = 0.1;
}
}
else
{
CreateTimer(GetRandomFloat(0.5, 2.0), GrenadeDetonateHook, EntIndexToEntRef(grenade), TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
return Plugin_Continue;
}
/**
* @brief Timer for tripwire think.
*
* @param hTimer The timer handle.
* @param refID The reference index.
**/
public Action GrenadeTripwireThinkHook(Handle hTimer, int refID)
{
int grenade = EntRefToEntIndex(refID);
Action hResult = Plugin_Stop;
if (grenade != -1)
{
int iState = GetEntProp(grenade, Prop_Data, "m_iHammerID");
float flCounter = GetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime");
if (flCounter > 0.0)
{
flCounter -= 0.1;
}
switch (iState)
{
case TRIPWIRE_STATE_POWERUP :
{
hResult = GrenadeTripwireThinkPowerUp(grenade, iState, flCounter);
}
case TRIPWIRE_STATE_DETECT :
{
hResult = GrenadeTripwireThinkDetect(grenade, iState, flCounter);
}
}
SetEntProp(grenade, Prop_Data, "m_iHammerID", iState);
SetEntPropFloat(grenade, Prop_Data, "m_flDissolveStartTime", flCounter);
}
return hResult;
}
//**********************************************
//* Grenade (satchel) function. *
//**********************************************
/**
* @brief Called right before the grenade touch other entity.
*
* @param grenade The grenade index.
* @param target The entity index of the entity being touched.
**/
public Action GrenadeSatchelTouch(int grenade, int target)
{
if (!GetEntProp(grenade, Prop_Data, "m_bIsAutoaimTarget"))
{
if (!target || ZP_IsBSPModel(target))
{
GrenadeSatchelTrackWall(grenade);
}
}
return Plugin_Handled;
}
/**
* @brief Move to another state.
*
* @param grenade The grenade index.
**/
void GrenadeSatchelTrackWall(int grenade)
{
static float vPosition[3]; static float vEndPosition[3]; static float vNormal[3];
static const int vLoop[6][2] = { {2, 1}, {2, -1}, {0, 1}, {0, -1}, {1, 1}, {1, -1} };
GetEntPropVector(grenade, Prop_Data, "m_vecAbsOrigin", vPosition);
int victim; float flFraction; float flBestFraction = 1.0;
for (int i = 0; i < 6; i++)
{
vEndPosition[vLoop[i][0]] = vPosition[vLoop[i][0]] + (2.0 * float(vLoop[i][1]));
Handle hTrace = TR_TraceRayFilterEx(vPosition, vEndPosition, MASK_SOLID, RayType_EndPoint, PlayerFilter, grenade);
if (!TR_DidHit(hTrace))
{
static const float vMins[3] = { -16.0, -16.0, -18.0 };
static const float vMaxs[3] = { 16.0, 16.0, 18.0 };
delete hTrace;
hTrace = TR_TraceHullFilterEx(vPosition, vEndPosition, vMins, vMaxs, MASK_SHOT_HULL, PlayerFilter, grenade);
if (TR_DidHit(hTrace))
{
victim = TR_GetEntityIndex(hTrace);
if (victim < 1 || ZP_IsBSPModel(victim))
{
UTIL_FindHullIntersection(hTrace, vPosition, vMins, vMaxs, PlayerFilter, grenade);
}
}
}
if (TR_DidHit(hTrace))
{
victim = TR_GetEntityIndex(hTrace);
if (victim < 1 || ZP_IsBSPModel(victim))
{
flFraction = TR_GetFraction(hTrace);
if (flBestFraction > flFraction)
{
flBestFraction = flFraction;
TR_GetEndPosition(vEndPosition, hTrace);
TR_GetPlaneNormal(hTrace, vNormal);
}
}