-
Notifications
You must be signed in to change notification settings - Fork 0
/
carnage.sp
2032 lines (1947 loc) · 86.9 KB
/
carnage.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
#include <sourcemod>
#include <sdkhooks>
#include <tf2_stocks>
#pragma newdecls required
#pragma semicolon 1
//By default, calling Debug() does nothing.
public void Debug(const char[] fmt, any ...) { }
//For a full log of carnage score changes, enable this:
//#define Debug PrintToServer
#include "randeffects"
public Plugin myinfo =
{
name = "Carnage Collection and Compensation",
author = "Chris Angelico",
description = "SourceMod extension to encourage carnage by rewarding those who engage in it",
version = "0.99",
url = "https://github.com/Rosuav/TF2BuffBot",
};
//Before you can use !roulette or !gift, you must fill your (invisible) carnage counter.
ConVar sm_ccc_carnage_initial = null; //(0) Carnage points a player has on first joining or changing team
ConVar sm_ccc_carnage_per_solo_kill = null; //(2) Carnage points gained for each unassisted kill
ConVar sm_ccc_carnage_per_kill = null; //(2) Carnage points gained for each kill
ConVar sm_ccc_carnage_per_taunt_kill = null; //(10) Carnage points gained for a taunt kill (or other special kill)
ConVar sm_ccc_carnage_per_assist = null; //(1) Carnage points gained for each assist
ConVar sm_ccc_carnage_per_death = null; //(3) Carnage points gained when you die
ConVar sm_ccc_carnage_per_building = null; //(1) Carnage points gained when you destroy a non-gun building (assists ignored here)
ConVar sm_ccc_carnage_per_sentry = null; //(2) Carnage points gained when you destroy a sentry gun
ConVar sm_ccc_carnage_per_ubercharge = null; //(0) Carnage points gained by a medic who deploys Uber
ConVar sm_ccc_carnage_per_upgrade = null; //(0) Carnage points gained by an engineer who upgrades a building
//No carnage points are granted for achieving map goals (capturing the flag, taking a control point, moving the
//payload, etc). Such actions may help you win, but they don't create death and destruction.
ConVar sm_ccc_carnage_required = null; //(10) Carnage points required to use !roulette or !gift
ConVar sm_ccc_bot_roulette_chance = null; //(20) Percentage chance that a bot will !roulette upon gaining enough points
ConVar sm_ccc_buff_duration = null; //(30) Length of time that each buff/debuff lasts
//When you spin the !roulette wheel, you have these odds of getting different buff categories.
//There will always be exactly one chance that you will die, so scale these numbers accordingly.
ConVar sm_ccc_roulette_chance_good = null; //(64) Chance that a roulette spin will give a beneficial effect
ConVar sm_ccc_roulette_chance_bad = null; //(30) Chance that a roulette spin will give a detrimental effect
ConVar sm_ccc_roulette_chance_weird = null; //(5) Chance that a roulette spin will give a weird effect
//When you grant a !gift, players (other than yourself) will have this many chances each.
ConVar sm_ccc_gift_chance_friendly_human = null; //(20) Chance that each friendly human has of receiving a !gift
ConVar sm_ccc_gift_chance_friendly_bot = null; //(2) Chance that each friendly bot has of receiving a !gift
ConVar sm_ccc_gift_chance_enemy_human = null; //(10) Chance that each enemy human has of receiving a !gift
ConVar sm_ccc_gift_chance_enemy_bot = null; //(1) Chance that each enemy bot has of receiving a !gift
//Debug assistants. Not generally useful for server admins who aren't also coding CCC itself.
ConVar sm_ccc_debug_force_category = null; //(0) Debug - force roulette to give good (1), bad (2), weird (3), or death (4)
ConVar sm_ccc_debug_force_effect = null; //(0) Debug - force roulette to give the Nth effect in that category (ignored if out of bounds)
ConVar sm_ccc_debug_cheats_active = null; //(0) Debug - allow cheaty commands
//More knobs
ConVar sm_ccc_gravity_modifier = null; //(3) Ratio used for gravity effects - either multiply by this or divide by it
ConVar sm_ccc_turret_allowed = null; //(0) Set to 1 to allow the !turret command
ConVar sm_ccc_turret_invuln_after_placement = null; //(30) Length of time a turret can remain invulnerable after deployment
ConVar sm_ccc_turret_invuln_per_kill = null; //(1) Additional time a turret gains each time it gets a kill
ConVar sm_ccc_turret_max_invuln = null; //(60) Maximum 'banked' invulnerability a turret can have
//Not directly triggered by chat, but other ways to encourage carnage
ConVar sm_ccc_crits_on_domination = null; //(5) Number of seconds to crit-boost everyone (both teams) after a domination - 0 to disable
ConVar sm_ccc_ignite_chance_on_capture = null; //(15) Percentage chance that a point/flag capture will set everyone on fire.
ConVar sm_ccc_ignite_chance_on_start_capture = null; //(2) Chance that STARTING a point capture will set everyone on fire.
//For Mann vs Machine, and possibly other situations, co-op mode changes the parameters.
ConVar sm_ccc_coop_mode = null; //(2) 0=normal, 1=co-op mode, 2=autodetect (by map name)
ConVar sm_ccc_coop_gift_multiplier = null; //(2) The cost of !gift is multiplied by this.
ConVar sm_ccc_coop_roulette_multiplier = null; //(3) The cost of !roulette is multiplied by this. Should be higher than the gift multiplier.
ConVar sm_ccc_coop_kill_divisor = null; //(4) It takes this many co-op kills to be worth one regular kill. 4:1 is about right (MVM has a lot of targets available).
ConVar sm_ccc_domheal_amount = null; //(20) Domination building heal hitpoints per tick
ConVar sm_ccc_domheal_percent = null; //(0) Domination building heal percent of max hp per tick
ConVar sm_ccc_admin_chat_name = null; //("") Name of admin for chat purposes
ConVar sm_ccc_market_gardening = null; //(0) If 1, we're market gardening all the way! If 2, it's King of the Bleeding Hill
ConVar sm_ccc_koth_override_timers = null; //(0) If nonzero, KOTH maps will start with this many seconds on the clock
ConVar sm_ccc_ragebox_damage_reduction = null; //(10) The ragebox bearer gets this percentage damage reduction.
char notable_kills[128][128];
//TODO: Echo commands, where pre-written text gets spammed to chat (eg "Server going down yada yada")
#include "convars_carnage"
/* Co-op mode (eg for MVM)
- Gifts always land on your team
- Roulettes are always beneficial
- To compensate, roulette/gift cost is massively increased.
- Since roulette is more useful, its cost is even higher than gift
- Carnage points are earned by the entire team, but spent individually.
- Ergo all carnage point additions must loop over all players.
Since carnage points are earned by everyone, your rate of gain is higher. With a full
six-person MVM team, each kill awards six players the points, which means each player
gets six times as many points as in solo mode (roughly). Additionally, the "two thirds
good one third bad" rule of thumb for !gift and !roulette is removed - gifts always go
to a teammate, and roulette spins are always good. Thirdly, MVM gives you a target-rich
environment, allowing you to clock up carnage points more rapidly than normal. Carnage
point costs should be increased for ALL of these.
The target-rich environment is worth roughly a 4:1 ratio on points, based on the way a
killstreak weapon works (it takes 20 bot kills instead of 5 to get a spree, 80 instead
of 20 to become godlike). Assuming that that part carries over to the carnage points, we
simply divide all kill points by four. (Internally, since everything's done with
integers, everything EXCEPT kill scores - including costs - gets multiplied by four
instead. Try to ensure that the numbers don't get unexpectedly large and overflow.)
It is essential that the actual number of players NOT affect the scaling. Otherwise, a
four-player team might resent a fifth player joining, which is bad for the game as a
whole. Ideally, the numbers should be aimed at 3-5 players; there is no point playing a
game with just one player, and then we should aim for the mid-range rather than the
extremes.
-- 20190106: Maybe this isn't *essential* but merely *highly desirable*. If the variance
caused by a single player coming or going is enough to be felt without being too swingy,
having one idler on the team wouldn't be too much of an issue. One possibility would be
to aim for 4 players, and if you have 5, all robots get 20% damage reduction, and with
6, the robots get 50% DR. Similarly, if you have only 3 players, the humans get 20% DR.
TODO: Code this up and give it a whirl. Especially, be prepared to tweak the numbers -
possibly put the whole kit and kaboodle into cvars.
NOTE: The nature of co-op mode means that some dynamics change. For instance, if a solo
kill is worth the same as an assisted kill (as is the default), a co-op assisted kill is
actually worth more, since both players (and their entire team) get the points for the
kill AND the assist (three in total, with default settings). This means, for instance,
that a medic on a team will tend to mean that more carnage points are scored overall;
this is not considered a bad thing. Yay for medics!
*/
//TODO: What happens when there are six players and another joins? Can we detect the
//"joining spectators" event and force the player to join defenders? Check InitializePlayer
//and see what happens when a seventh player joins. TF2_ChangeClientTeam may do the job.
//TODO: Bot limit check. One wave. Bots only ever seem to spawn up to a max of 22, which
//ties in with the 22 bot slots assigned (either as spectators or on team BLU). Does
//this ever change based on the number of currently-connected players? I suspect not;
//there are enough slots to have 22 bots and 6 players without any issues.
//Rolling array of carnage points per user id. If a user connects, then this many other
//users connect and disconnect, there will be a collision, and they'll share the slot. I
//rather doubt that this will happen often, but it might with bots - I don't know. Given
//that bots all get kicked once there are no humans online, there'd have to be a strong
//level of activity all the time for this to wrap and collide (wrapping itself is going
//to be rare, and on its own isn't a problem).
int carnage_points[16384];
int ticking_down[MAXPLAYERS + 1]; //Any effect that's managed by a timer will tick down in this.
int BeamSprite, HaloSprite;
public void OnPluginStart()
{
RegAdminCmd("sm_hysteria", Command_Hysteria, ADMFLAG_SLAY);
RegAdminCmd("sm_grant_bonkvich", Command_Bonkvich, ADMFLAG_SLAY);
RegAdminCmd("sm_ccc_effects", Command_Effects, ADMFLAG_SLAY);
RegAdminCmd("sm_rage_box", Command_RageBox, ADMFLAG_SLAY);
RegAdminCmd("chat", Command_Chat, ADMFLAG_SLAY);
HookEvent("player_say", Event_PlayerChat);
HookEvent("player_team", InitializePlayer);
HookEvent("player_death", PlayerDied);
HookEvent("object_destroyed", BuildingBlownUp);
HookEvent("player_chargedeployed", Ubered);
HookEvent("player_upgradedobject", Upgraded);
HookEvent("ctf_flag_captured", Captured);
HookEvent("teamplay_point_captured", Captured);
HookEvent("teamplay_point_startcapture", StartCapture);
HookEntityOutput("tank_boss", "OnHealthBelow50Percent", accelerate_tank);
//The actual code to create convars convars is built by the Python script,
//and yes, I'm aware that I now have two problems.
CreateConVars();
HookConVarChange(sm_ccc_coop_mode, CoopModeChanged);
//Load up some sprites from funcommands. This is GPL'd, so the following section
//of code is also GPL'd.
char buffer[PLATFORM_MAX_PATH];
Handle gameConfig = LoadGameConfigFile("funcommands.games");
GameConfGetKeyValue(gameConfig, "SpriteBeam", buffer, sizeof(buffer));
BeamSprite = PrecacheModel(buffer);
GameConfGetKeyValue(gameConfig, "SpriteHalo", buffer, sizeof(buffer));
HaloSprite = PrecacheModel(buffer);
//End GPL code. (The rest of this file is even more freely usable.)
}
public void accelerate_tank(const char[] output, int caller, int activator, float delay)
{
//TODO: Look at the tank's current speed and add 50% to it
//rather than hard-coding a new speed of 100. Or let the Pop
//file choose the speed (either globally or per-tank). Also,
//flag the tank somehow as "have set the speed", and then
//trigger this event also at 40%, 30%, 20%, and 10%, in case
//the 50% event doesn't fire (has been observed).
SetVariantInt(100);
AcceptEntityInput(caller, "SetSpeed", -1, -1, 0);
PrintToChatAll("Relieved of its armor, the tank speeds up!");
}
TFCond hysteria_effects[] = {
TFCond_CritOnDamage,
TFCond_BulletImmune,
TFCond_BlastImmune,
TFCond_FireImmune,
};
void add_hysteria(int target, int blindness)
{
//Add the effects and wash out your vision
for (int i = 0; i < sizeof(hysteria_effects); ++i)
TF2_AddCondition(target, hysteria_effects[i], TFCondDuration_Infinite, 0);
blind(target, blindness);
}
void remove_hysteria(int target)
{
//Remove the effects and clear the vision
for (int i = 0; i < sizeof(hysteria_effects); ++i)
TF2_RemoveCondition(target, hysteria_effects[i]);
blind(target, 0);
}
public Action Command_Hysteria(int client, int args)
{
char player[32];
/* Try and find a matching player */
GetCmdArg(1, player, sizeof(player));
int target = FindTarget(client, player);
if (target == -1) return Plugin_Handled;
char name[MAX_NAME_LENGTH];
GetClientName(target, name, sizeof(name));
if (TF2_IsPlayerInCondition(target, TFCond_CritOnDamage))
{
remove_hysteria(target);
ReplyToCommand(client, "[SM] %s [%d] leaves hysteria behind.", name, target);
}
else
{
add_hysteria(target, 192);
ReplyToCommand(client, "[SM] %s [%d] goes into hysteria mode!", name, target);
}
return Plugin_Handled;
}
int bonkvich_userid = -1;
public Action Command_Bonkvich(int client, int args)
{
char player[32];
GetCmdArg(1, player, sizeof(player));
int target = FindTarget(client, player);
if (target == -1) return Plugin_Handled;
char name[MAX_NAME_LENGTH];
GetClientName(target, name, sizeof(name));
int userid = GetClientUserId(target);
bonkvich_userid = userid;
ReplyToCommand(client, "[SM] %s is granted the Box of Bonkvich.", name);
return Plugin_Handled;
}
public Action Command_Chat(int client, int args)
{
char text[512]; GetCmdArgString(text, sizeof(text));
char admin[32]; GetConVarString(sm_ccc_admin_chat_name, admin, sizeof(admin));
ReplyToCommand(client, "%s: %s", admin, text);
//PrintToChatAll("\x07FE0000%s\x01 : %s", admin, text); //Chat as if red team
PrintToChatAll("\x079ACDFF%s\x01 : %s", admin, text); //Chat as if blue team
return Plugin_Handled;
}
int ragebox_userid = 0;
int ragebox_lastteam;
void set_ragebox(int userid)
{
//Remove rage from the current ragebox holder (if any)
if (ragebox_userid > 0 && ragebox_userid != userid)
{
int target = GetClientOfUserId(ragebox_userid);
if (target)
{
blind(target, 0);
SetEntityRenderColor(target, 255, 255, 255, 255);
}
}
ragebox_userid = userid;
//Add rage to the new ragebox holder (if any - set_ragebox(0) will remove all)
//Setting to -1 means "remember the team, but nobody actually has it".
if (ragebox_userid > 0)
{
int target = GetClientOfUserId(ragebox_userid);
//Record the team on arrival, in case you change teams (it belonged to your previous team)
ragebox_lastteam = GetClientTeam(target);
blind(target, 192);
SetEntityRenderColor(target, 255, 32, 32, 255);
}
}
void randomize_ragebox(int nonrecip)
{
//Randomly assign the rage box to a living member of the last team that got it
//If there are no such members, leave the box with its current holder (even if dead).
//int recip = random.choice([client for client in clients if yada yada])
int recip = 0, count = 0, coop = in_coop_mode();
for (int i = 1; i <= MaxClients; ++i)
if (i != nonrecip && IsClientInGame(i) && IsPlayerAlive(i) && (!coop || GetClientTeam(i) == ragebox_lastteam))
if (GetURandomFloat() * ++count < 1) recip = i;
if (!recip)
{
//With the RB in limbo, we'll be called periodically to rerandomize.
//Eventually it'll succeed... hopefully.
if (ragebox_userid != -1) PrintToChatAll("The Rage Box floats in limbo. Help it find a new host...");
set_ragebox(-1);
return;
}
char name[MAX_NAME_LENGTH];
GetClientName(recip, name, sizeof(name));
set_ragebox(GetClientUserId(recip));
PrintToChatAll("The Rage Box is collected by %s.", name);
return;
}
public Action Command_RageBox(int client, int args)
{
char player[32];
GetCmdArg(1, player, sizeof(player));
int target = FindTarget(client, player);
if (target == -1) {
if (ragebox_userid) {
PrintToChatAll("The Rage Box departs for another world.");
set_ragebox(0);
}
return Plugin_Handled;
}
char name[MAX_NAME_LENGTH];
GetClientName(target, name, sizeof(name));
set_ragebox(GetClientUserId(target));
PrintToChatAll("A Rage Box has entered the game! %s holds it.", name);
return Plugin_Handled;
}
Action koth_set_timers(Handle timer, any entity)
{
ignore(timer);
int time = GetConVarInt(sm_ccc_koth_override_timers);
if (time <= 0) return Plugin_Stop;
SetVariantInt(time);
AcceptEntityInput(entity, "SetRedTimer", -1, -1, 0);
SetVariantInt(time);
AcceptEntityInput(entity, "SetBlueTimer", -1, -1, 0);
return Plugin_Stop;
}
bool medigun_active[2048]; //Maps an entity to whether it's ticking or not
public void OnEntityCreated(int entity, const char[] cls)
{
if (!strcmp(cls, "tf_logic_koth")) CreateTimer(0.0, koth_set_timers, entity);
if (!strcmp(cls, "tank_boss"))
{
//A tank has entered the arena!
//Useful inputs: SetSpeed(float)
//Useful outputs: OnHealthBelow[70]Percent for any multiple of 10%; OnKilled
//TODO: Adjust the tank's speed once it gets below a certain health.
//Does it make sense to start fast and slow down when it gets damaged, or to
//start slower and then speed up as stuff gets kicked off it?
//More generally: Need a way to carry info from the POP file into the runtime.
//AcceptEntityInput(entity, "Ignite", -1, -1, 0); //Create flames under the tank (insignificant amount of DOT)
//PrintToServer("Speed:", GetEntProp(entity, Prop_Data, "speed"));
//PrintToChatAll("iADI[0]: %d", GetEntProp(entity, Prop_Send, "m_iAttributeDefinitionIndex", _, 0));
}
if (entity >= 0 && entity < 2048 && !strcmp(cls, "tf_weapon_medigun"))
{
/* I really want to just hook SDKHook_Think, but I can't get that to work.
So instead, we create a timer for every medigun, and destroy that when the
medigun is removed.
SetEntProp(entity, Prop_Data, "m_nNextThinkTick", GetGameTickCount() + 3);
//SetEntProp(entity, Prop_Data, "m_nNextThinkTick", 1);
SDKHook(entity, SDKHook_Think, medigun_think); //Never gets called
*/
if (medigun_active[entity]) PrintToChatAll("Assertion failed! Duplicate timer!");
//Temporarily disabled (since the primary purpose of this isn't working) - will insta-unset.
//medigun_active[entity] = true;
CreateTimer(0.5, medigun_check, entity, TIMER_REPEAT);
}
}
//void medigun_think(int entity) {PrintToChatAll("Medigun %d is thinking...", entity);}
public void OnEntityDestroyed(int entity) {if (entity >= 0 && entity < 2048) medigun_active[entity] = false;}
//char last_msg[2048][2048];
int last_healing_target[2048];
Action medigun_check(Handle timer, any entity)
{
ignore(timer);
if (!medigun_active[entity]) return Plugin_Stop;
int patient = last_healing_target[entity];
if (patient > 0 //If you were previously healing someone...
&& !GetEntProp(entity, Prop_Send, "m_bHealing") //... and you currently have no patient...
&& GetEntProp(entity, Prop_Send, "m_bAttacking") //... and you're trying to find one (mouse-1 is active)...
&& IsClientInGame(patient) && IsPlayerAlive(patient) //... and your last patient is alive and active...
&& GetClientTeam(patient) == GetEntProp(entity, Prop_Send, "m_iTeamNumber") //... and on your team...
)
{
//... then grab them again!
//TODO: Also check that the patient is within field of view.
//Doesn't actually make the medigun start healing though. hmm.
//May need to trigger it in some more direct way - AcceptEntityInput?
SetEntPropEnt(entity, Prop_Send, "m_hHealingTarget", patient);
SetEntProp(entity, Prop_Send, "m_bHealing", 1);
TF2_AddCondition(patient, TFCond_Healing, -1.0, 0);
/* This doesn't start the patient being healed either.
int healers = GetEntProp(patient, Prop_Send, "m_nNumHealers") + 1;
SetEntProp(patient, Prop_Send, "m_nNumHealers", healers);
PrintToChatAll("Setting heal target! %d healers.", healers);*/
}
if (GetEntProp(entity, Prop_Send, "m_bHealing"))
{
patient = GetEntPropEnt(entity, Prop_Send, "m_hHealingTarget");
if (patient != -1) last_healing_target[entity] = patient;
}
#if 0
char msg[2048];
Format(msg, sizeof(msg), "Medigun %d: %s/%s/%s/%s targ %d last %d resist %d", entity,
GetEntProp(entity, Prop_Send, "m_bHealing") ? "healing": "idle",
GetEntProp(entity, Prop_Send, "m_bAttacking") ? "attacking": "benign",
GetEntProp(entity, Prop_Send, "m_bChargeRelease") ? "ubering": "normal",
GetEntProp(entity, Prop_Send, "m_bHolstered") ? "holstered": "unholstered",
GetEntPropEnt(entity, Prop_Send, "m_hHealingTarget"),
GetEntPropEnt(entity, Prop_Send, "m_hLastHealingTarget"),
GetEntProp(entity, Prop_Send, "m_nChargeResistType")
);
if (!strcmp(msg, last_msg[entity])) return Plugin_Handled;
strcopy(last_msg[entity], 2048, msg);
PrintToChatAll("[%d] %s", GetGameTickCount(), msg);
#endif
return Plugin_Handled;
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_OnTakeDamage, PlayerTookDamage);
SDKHook(client, SDKHook_GetMaxHealth, maxhealthcheck);
SDKHook(client, SDKHook_SpawnPost, respawncheck);
}
public Action maxhealthcheck(int entity, int &maxhealth)
{
/* TODO: GetEntProp(GetPlayerResourceEntity(), Prop_Send, "m_iMaxBuffedHealth", _, entity)
returns the "max buffed health" which may affect overheal. Change that too?? */
if (entity > MaxClients) return Plugin_Continue;
if (TF2_IsPlayerInCondition(entity, TFCond_Unknown2)) maxhealth += 150; //NOTE: This appears to prevent the decay of overheal (????).
if (GetClientUserId(entity) == ragebox_userid) maxhealth += maxhealth / 2;
return Plugin_Changed;
}
public Action PlayerTookDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
int mktgdn = GetConVarInt(sm_ccc_market_gardening);
if (mktgdn)
{
if (damagetype&DMG_FALL) {damage = 0.0; return Plugin_Changed;} //Disable all fall damage
if (attacker == victim) return Plugin_Continue; //Permit all blast jumping
if (!attacker) return Plugin_Continue; //Permit all environmental damage (drowning etc)
if (mktgdn == 2 && attacker <= MAXPLAYERS)
{
//"Bleeding Hill" mode - no damage whatsoever except bleed
damage = 0.0;
return Plugin_Changed;
}
if (attacker <= MAXPLAYERS && !TF2_IsPlayerInCondition(attacker, TFCond_BlastJumping))
{
//I've been seeing some console crashes involving "entity 320/trigger_hurt" dealing
//damage. Not sure what this is, and whether it should get a complete whitelisting
//(like environmental damage), or just ignore this one check.
damage = 0.0;
PrintToChatAll("Damage negated! You weren't blast jumping.");
return Plugin_Changed;
}
if (!(damagetype&DMG_CLUB))
{
damage = 0.0;
PrintToChatAll("Damage negated! Melee only.");
return Plugin_Changed;
}
}
#if 0
PrintToChatAll("Player %d took %f damage (t %d a %d i %d)", victim, damage, damagetype, attacker, inflictor);
if (damagetype&DMG_CRUSH) PrintToChatAll("--> DMG_CRUSH: crushed by falling or moving object.");
if (damagetype&DMG_BULLET) PrintToChatAll("--> DMG_BULLET: shot");
if (damagetype&DMG_SLASH) PrintToChatAll("--> DMG_SLASH: cut, clawed, stabbed");
if (damagetype&DMG_BURN) PrintToChatAll("--> DMG_BURN: heat burned");
if (damagetype&DMG_VEHICLE) PrintToChatAll("--> DMG_VEHICLE: hit by a vehicle");
if (damagetype&DMG_FALL) PrintToChatAll("--> DMG_FALL: fell too far");
if (damagetype&DMG_BLAST) PrintToChatAll("--> DMG_BLAST: explosive blast damage");
if (damagetype&DMG_CLUB) PrintToChatAll("--> DMG_CLUB: crowbar, punch, headbutt");
if (damagetype&DMG_SHOCK) PrintToChatAll("--> DMG_SHOCK: electric shock");
if (damagetype&DMG_SONIC) PrintToChatAll("--> DMG_SONIC: sound pulse shockwave");
if (damagetype&DMG_ENERGYBEAM) PrintToChatAll("--> DMG_ENERGYBEAM: laser or other high energy beam ");
if (damagetype&DMG_PREVENT_PHYSICS_FORCE) PrintToChatAll("--> DMG_PREVENT_PHYSICS_FORCE: Prevent a physics force ");
if (damagetype&DMG_NEVERGIB) PrintToChatAll("--> DMG_NEVERGIB: with this bit OR'd in, no damage type will be able to gib victims upon death");
if (damagetype&DMG_ALWAYSGIB) PrintToChatAll("--> DMG_ALWAYSGIB: with this bit OR'd in, any damage type can be made to gib victims upon death.");
if (damagetype&DMG_DROWN) PrintToChatAll("--> DMG_DROWN: Drowning");
if (damagetype&DMG_PARALYZE) PrintToChatAll("--> DMG_PARALYZE: slows affected creature down");
if (damagetype&DMG_NERVEGAS) PrintToChatAll("--> DMG_NERVEGAS: nerve toxins, very bad");
if (damagetype&DMG_POISON) PrintToChatAll("--> DMG_POISON: blood poisoning - heals over time like drowning damage");
if (damagetype&DMG_RADIATION) PrintToChatAll("--> DMG_RADIATION: radiation exposure");
if (damagetype&DMG_DROWNRECOVER) PrintToChatAll("--> DMG_DROWNRECOVER: drowning recovery");
if (damagetype&DMG_ACID) PrintToChatAll("--> DMG_ACID: toxic chemicals or acid burns");
if (damagetype&DMG_SLOWBURN) PrintToChatAll("--> DMG_SLOWBURN: in an oven");
if (damagetype&DMG_REMOVENORAGDOLL) PrintToChatAll("--> DMG_REMOVENORAGDOLL: with this bit OR'd in, no ragdoll will be created, and the target will be quietly removed.");
if (damagetype&DMG_PHYSGUN) PrintToChatAll("--> DMG_PHYSGUN: Hit by manipulator. Usually doesn't do any damage.");
if (damagetype&DMG_PLASMA) PrintToChatAll("--> DMG_PLASMA: Shot by Cremator");
if (damagetype&DMG_AIRBOAT) PrintToChatAll("--> DMG_AIRBOAT: Hit by the airboat's gun");
if (damagetype&DMG_DISSOLVE) PrintToChatAll("--> DMG_DISSOLVE: Dissolving!");
if (damagetype&DMG_BLAST_SURFACE) PrintToChatAll("--> DMG_BLAST_SURFACE: A blast on the surface of water that cannot harm things underwater");
if (damagetype&DMG_DIRECT) PrintToChatAll("--> DMG_DIRECT: ??");
if (damagetype&DMG_BUCKSHOT) PrintToChatAll("--> DMG_BUCKSHOT: not quite a bullet. Little, rounder, different.");
#endif
if (ragebox_userid <= 0) return Plugin_Continue;
int ragebox_holder = GetClientOfUserId(ragebox_userid);
if (!ragebox_holder) return Plugin_Continue; //If the ragebox holder has left, the userid becomes invalid.
if (ragebox_holder == victim)
{
if (attacker == victim) return Plugin_Continue; //Self-damage isn't affected (to permit blast jumping)
if (!attacker) return Plugin_Continue; //Environmental damage isn't affected (falling to your death still kills you)
int dr = GetConVarInt(sm_ccc_ragebox_damage_reduction);
if (!dr) return Plugin_Continue;
Debug("Hurting the ragebox holder; %d%% damage reduction", dr);
damage *= (100 - dr) / 100.0;
return Plugin_Changed;
}
//TODO: If someone leaves the game, this can crash out.
if (TF2_GetPlayerClass(ragebox_holder) == TFClass_Medic)
{
int index = GetEntPropEnt(ragebox_holder, Prop_Send, "m_hActiveWeapon");
char cls[32]; GetEdictClassname(index, cls, sizeof(cls));
if (!strcmp(cls, "tf_weapon_medigun") && GetEntProp(index, Prop_Send, "m_bHealing") == 1)
{
//TODO: Healing target isn't always a client?? Seeing some cases
//where heal target is 460, which bombs out in GetClientName.
int patient = GetEntPropEnt(index, Prop_Send, "m_hHealingTarget");
char patientname[MAX_NAME_LENGTH];
GetClientName(patient, patientname, sizeof(patientname));
char medicname[MAX_NAME_LENGTH];
GetClientName(ragebox_holder, medicname, sizeof(medicname));
Debug("Medic %s is healing %s", medicname, patientname);
ragebox_holder = patient; //Pass the damage bonus (but not the reduction to incoming damage) to the patient
}
else return Plugin_Continue; //Medics cannot get damage buffed at all.
}
if (ragebox_holder == attacker)
{
//NOTE: If a medic has the ragebox and the patient blast jumps,
//the jump will be twice as high/far. Should this be prevented?
Debug("Ragebox holder dealing damage; 100%% damage bonus");
damage *= 2.0;
return Plugin_Changed;
}
return Plugin_Continue;
}
public void respawncheck(int entity)
{
if (entity <= MaxClients)
{
if (GetClientUserId(entity) == ragebox_userid) set_ragebox(ragebox_userid);
if (GetConVarInt(sm_ccc_market_gardening) == 2) //Bleeding Hill
CreateTimer(1.0, health_drain, entity, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
if (ragebox_userid == -1) randomize_ragebox(0);
}
char[] trim_message(char[] msg)
{
//Apparently, it's okay to return (a pointer to?) a local buffer,
//as long as that buffer was declared with a fixed size. I have
//no idea what SourcePawn thinks strings are; they're not first
//class objects, but they're also not pointer-to-char the way C
//treats them.
char result[128];
if (!strncmp(msg, "\x079ACDFF\x01", 8)) //Suppress the extra color code added by gen_effects_tables.py
Format(result, sizeof(result), msg[8], "<NAME>");
else
Format(result, sizeof(result), msg, "<NAME>");
return result;
}
public Action Command_Effects(int client, int args)
{
ReplyToCommand(client, "[SM] Effects available in category 1 (Good):");
for (int i = 0; i < sizeof(benefits); ++i)
ReplyToCommand(client, "[SM] %3d: %s", i + 1, trim_message(benefits_desc[i]));
ReplyToCommand(client, "[SM] Effects available in category 2 (Bad):");
for (int i = 0; i < sizeof(detriments); ++i)
ReplyToCommand(client, "[SM] %3d: %s", i + 1, trim_message(detriments_desc[i]));
ReplyToCommand(client, "[SM] Effects available in category 3 (Weird):");
for (int i = 0; i < sizeof(weird); ++i)
ReplyToCommand(client, "[SM] %3d: %s", i + 1, trim_message(weird_desc[i]));
ReplyToCommand(client, "[SM] The 1-based indices can be used with sm_ccc_debug_force_effect.");
return Plugin_Handled;
}
public void InitializePlayer(Event event, const char[] name, bool dontBroadcast)
{
if (!event.GetInt("team")) return; //Player is leaving the game
char playername[MAX_NAME_LENGTH]; event.GetString("name", playername, sizeof(playername));
Debug("Player initialized: uid %d cl %d team %d was %d name %s",
event.GetInt("userid"), GetClientOfUserId(event.GetInt("userid")),
event.GetInt("team"),
event.GetInt("oldteam"),
playername);
int points = GetConVarInt(sm_ccc_carnage_initial);
if (in_coop_mode()) points *= GetConVarInt(sm_ccc_coop_kill_divisor);
carnage_points[event.GetInt("userid") % sizeof(carnage_points)] = points;
//TODO: If event.GetInt("autoteam") and not event.GetInt("disconnect")
//and event.GetInt("team") is "Spectators" and coop_mode:
// TF2_ChangeClientTeam(target, TFTeam_Red);
//See what the consequences are of doing that.
}
int coop_mode = 2;
int mvm_map = 0;
int in_coop_mode()
{
//int coop_mode = GetConVarInt(sm_ccc_coop_mode);
if (coop_mode < 2) return coop_mode; //Mode is forced by admin
//flag == 2 means we autodetect. True if we're on an MVM map, false else.
return mvm_map;
}
void CoopModeChanged(ConVar convar, const char[] old, const char[] val)
{
if (old[0]) ignore(convar); //Ignore both those parameters.
int flag = StringToInt(val);
if (flag == 0 || flag == 1)
{
coop_mode = flag; //Force off, or force on
PrintToServer("[SM] Co-op mode is now forced %sactive.", coop_mode ? "" : "in");
}
else
{
coop_mode = 2; //If you set it to an invalid value, assume "autodetect"
PrintToServer("[SM] Co-op mode will be auto-detected based on map name.");
}
}
public void OnMapStart()
{
//Alternatively, look for an entity of class tf_logic_mann_vs_machine?
char mapname[64];
GetCurrentMap(mapname, sizeof(mapname));
mvm_map = !strncmp(mapname, "mvm_", 4);
PrintToServer("[SM] Starting new %smap: %s", mvm_map ? "MVM " : "", mapname);
}
void add_score(int userid, int score, int kill)
{
if (userid <= 0 || score <= 0) return;
if (in_coop_mode())
{
int self = GetClientOfUserId(userid);
int myteam = GetClientTeam(self);
int factor = 1;
if (!kill) factor = GetConVarInt(sm_ccc_coop_kill_divisor);
for (int i = 1; i <= MaxClients; ++i)
if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == myteam)
low_add_score(GetClientUserId(i), score * factor);
}
else low_add_score(userid, score);
}
void low_add_score(int userid, int score)
{
int slot = userid % sizeof(carnage_points);
if (carnage_points[slot] < 0) return; //Turrets don't gain carnage points.
int new_score = carnage_points[slot] += score;
Debug("Score: uid %d +%d now %d points", userid, score, new_score);
int client = GetClientOfUserId(userid);
if (IsFakeClient(client) && IsPlayerAlive(client) && !in_coop_mode()
&& new_score >= GetConVarInt(sm_ccc_carnage_required))
{
//It's a bot (and not an MVM enemy) with enough carnage to pop a roulette.
if (100 * GetURandomFloat() < GetConVarInt(sm_ccc_bot_roulette_chance))
spin_roulette_wheel(userid);
}
/** Uncomment this to get announcements when you can use the commands
int old_score = carnage_points[slot] - score;
int roulette = GetConVarInt(sm_ccc_carnage_required);
int gift = roulette;
if (in_coop_mode())
{
if (IsFakeClient(client)) return;
roulette *= GetConVarInt(sm_ccc_coop_roulette_multiplier) * GetConVarInt(sm_ccc_coop_kill_divisor);
gift *= GetConVarInt(sm_ccc_coop_gift_multiplier) * GetConVarInt(sm_ccc_coop_kill_divisor);
}
roulette = (old_score < roulette && new_score >= roulette);
gift = (old_score < gift && new_score >= gift);
if (!roulette && !gift) return;
char playername[MAX_NAME_LENGTH]; GetClientName(client, playername, sizeof(playername));
if (roulette && gift) PrintToChatAll("%s can now pop !roulette or !gift, have at it!", playername);
else if (roulette) PrintToChatAll("%s can now pop !roulette, have at it!", playername);
else PrintToChatAll("%s can now pop !gift, have at it!", playername);
// End of announcements display */
}
//Getting kills (or assists) as a turret extends the length of time you can stay invulnerable.
void add_turret(int userid)
{
if (userid <= 0) return;
int target = GetClientOfUserId(userid);
if (!TF2_IsPlayerInCondition(target, TFCond_MedigunDebuff)) return;
ticking_down[target] += GetConVarInt(sm_ccc_turret_invuln_per_kill);
if (ticking_down[target] > GetConVarInt(sm_ccc_turret_max_invuln))
ticking_down[target] = GetConVarInt(sm_ccc_turret_max_invuln);
}
void class_specific_buff(int target, int duration)
{
/* Buff a character in a class-specific way. The duration may get scaled.
1. Scout: Crits for duration
2. Soldier: Crits for duration
3. Pyro: Crits for duration
4. Demoman: Mini-crits for 2*duration
5. Heavy: Crits for duration
6. Engineer: Mini-crits for 2*duration
7. Medic: Healing (possibly overheal) of 30*duration hitpoints
8. Sniper: Focus for 3*duration
9. Spy: Crits for duration, even though that's less useful for a spy
The goals of these buffs are:
- Everyone gets something useful
- Nobody's buff is strictly better than anybody else's.
- Buffs are "use it or lose it" (hence demomen don't get full crits, as they could
pump out crit stickies and keep them there). This reduces the chances of abuse.
- Teamwork should not be destroyed. The buff for medics should NOT encourage them
to abandon the team and go play combat medic, or to feel left out because they
received no real buff (one of which would happen if they got crits).
I'm currently not entirely happy with the Medic buff. Previously it was MegaHeal
(immunity to pushback etc - the Quick Fix effect), but it's now an overheal bonus
(a sudden one-shot spike of hitpoints). Neither truly fulfils the goals. Open to
further suggestions. (Can a medic get a buff that means his *patient* gets crits?
Look into the way canteen sharing works maybe.)
*/
TFClassType cls = TF2_GetPlayerClass(target);
TFCond buffs[] = { //These are in the order of TFClassType, *not* the order on the loading screen
TFCond_Slowed, //"Unknown" has an entry
TFCond_CritOnDamage, //Scout
TFCond_FocusBuff, //Sniper
TFCond_CritOnDamage, //Soldier
TFCond_CritCola, //DemoMan
TFCond_Unknown2, //Medic
TFCond_CritOnDamage, //Heavy
TFCond_CritOnDamage, //Pyro
TFCond_CritOnDamage, //Spy
TFCond_CritCola, //Engineer
};
int scales[] = { //Duration gets scaled up for some classes
0, //"Unknown"
1, //Scout
3, //Sniper
1, //Soldier
2, //DemoMan
1, //Medic
1, //Heavy
1, //Pyro
1, //Spy
2, //Engineer
};
apply_effect(target, buffs[cls], duration * scales[cls]);
//Special case: Medics heal buildings for a while.
if (cls == TFClass_Medic)
{
if (!ticking_down[target])
{
//If you're already ticking anything down, don't stack, just reset the timer
CreateTimer(1.0, heal_buildings, target, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
Debug("Applied effect Building Healer to %d", target);
}
//NOTE: If you're already ticking something _else_ down, this just messes with things
//I honestly don't care; it's a pretty narrow edge case I think. If it's a problem,
//might need to create a new way of doing the ticks.
ticking_down[target] = duration * 3;
}
}
public void PlayerDied(Event event, const char[] name, bool dontBroadcast)
{
//Is this the best (only?) way to get the name of the person who just died?
int player = GetClientOfUserId(event.GetInt("userid"));
char playername[MAX_NAME_LENGTH]; GetClientName(player, playername, sizeof(playername));
SetEntityGravity(player, 1.0); //Just in case.
//When the box is in limbo, people can re-claim it by scoring a kill, sometimes.
if (ragebox_userid)
{
if (ragebox_userid == -1 || !GetClientOfUserId(ragebox_userid)) {ragebox_userid = -1; randomize_ragebox(player);}
else set_ragebox(ragebox_userid);
}
//This is the name of a pyrovision-only "assisted by", such as a Pocket Yeti
//char fallback[64]; event.GetString("assister_fallback", fallback, sizeof(fallback));
//All the relevant killstreak counts are available. (Assist seems to be for medics only.)
//TODO: Give extra carnage points for ending a long kill streak? ("High value target")
//PrintToChatAll("Streak: tot %d wep %d asst %d vict %d", event.GetInt("kill_streak_total"),
// event.GetInt("kill_streak_wep"), event.GetInt("kill_streak_assist"), event.GetInt("kill_streak_victim"));
//TODO: If the penetration count is nonzero, maybe give a reward? (cf Machina)
//Make sure you can't just engineer this trivially.
//int pen = event.GetInt("playerpenetratecount");
//if (pen) PrintToChatAll("Penetration count: %d", pen);
if (event.GetInt("userid") == event.GetInt("attacker"))
{
//You killed yourself. Good job.
//This happens if you use the 'kill' or 'explode' commands, or if
//you blow yourself up with rockets or similar - but only if nobody
//else dealt you damage. If an enemy hurts you and THEN you kill
//yourself, the enemy gets the credit (as a "finished off", but that
//doesn't affect our calculations here). So if you destroy yourself,
//award no points. And to maximize the humiliation, we'll announce
//this to everyone in chat. Muahahaha.
PrintToChatAll("%s is awarded no points for self-destruction. May God have mercy on your soul.", playername);
if (event.GetInt("userid") == ragebox_userid) randomize_ragebox(player);
return;
}
if (event.GetInt("userid") == event.GetInt("assister"))
{
//You helped someone kill you. Impressive!
//The only way I've found to trigger this is for you to heal an
//enemy Spy while he kills you. Congrats. We'll let you have the
//points... as a consolation prize.
PrintToChatAll("%s needs to learn to spy check. Well done assisting in your own death.", playername);
}
//TODO: It's possible to assist in a kill on your own teammate (same way as the above).
//Would be nice to give a cool message for that too.
Debug("That's a kill! %s died (uid %d) by %d, assist %d",
playername, event.GetInt("userid"), event.GetInt("attacker"), event.GetInt("assister"));
if (event.GetInt("userid") == ragebox_userid)
{
int recipient = event.GetInt("attacker");
int target = GetClientOfUserId(recipient);
if (target && IsClientConnected(target) && IsClientInGame(target) && IsPlayerAlive(target) && !in_coop_mode())
{
char recipname[MAX_NAME_LENGTH]; GetClientName(target, recipname, sizeof(recipname));
PrintToChatAll("The Rage Box has been conquered by %s!", recipname);
set_ragebox(recipient);
}
else randomize_ragebox(player);
}
if (event.GetInt("assister") == -1)
{
//Solo kill - might be given more points than an assisted one
add_score(event.GetInt("attacker"), GetConVarInt(sm_ccc_carnage_per_solo_kill), 1);
}
else
{
//Assisted kill - award points to both attacker and assister
add_score(event.GetInt("attacker"), GetConVarInt(sm_ccc_carnage_per_kill), 1);
add_score(event.GetInt("assister"), GetConVarInt(sm_ccc_carnage_per_assist), 1);
}
int slot = event.GetInt("userid") % sizeof(carnage_points);
if (carnage_points[slot] < 0) carnage_points[slot] = 0; //Reset everything when you die.
add_score(event.GetInt("userid"), GetConVarInt(sm_ccc_carnage_per_death), 0);
add_turret(event.GetInt("attacker"));
add_turret(event.GetInt("assister"));
int deathflags = event.GetInt("death_flags");
if (deathflags & TF_DEATHFLAG_INTERRUPTED)
{
//I don't know what causes this, and I'm curious.
PrintToChatAll("** Interrupted death, whatever that means **");
}
int customkill = event.GetInt("customkill");
//Some kill types are awarded extra points.
if (customkill >= 0 && customkill < 128 && notable_kills[customkill][0])
{
PrintToChatAll(notable_kills[customkill]);
add_score(event.GetInt("attacker"), GetConVarInt(sm_ccc_carnage_per_taunt_kill), 0);
}
if (deathflags & (TF_DEATHFLAG_KILLERDOMINATION | TF_DEATHFLAG_ASSISTERDOMINATION))
{
//Someone got a domination. Give everyone crits for a few seconds!
//Of course, someone's dead right now. Sucks to be you. :)
//Doesn't happen all the time in large games; it's guaranteed in 6v6,
//but otherwise may "whiff" now and then. In huge games, it'll only
//happen a fraction of the time.
if (deathflags & TF_DEATHFLAG_GIBBED)
PrintToChatAll("Pieces of %s splatter all over everyone. Muahahaha, such happy carnage!", playername);
else
PrintToChatAll("The lifeless corpse of %s flies around the map. Muahahaha, such happy carnage!", playername);
int duration = GetConVarInt(sm_ccc_crits_on_domination);
if (duration)
{
int clients = GetClientCount(true);
int chance = 100 - (clients - 12) * 5; //After 6v6, each additional player drops 5% chance
//(chance could exceed 100, but it won't make any difference)
if (chance < 25) chance = 25; //At 14v14, we bottom out at 25% chance.
Debug("Domination crits: %d clients => %d%% chance", clients, chance);
if (100 * GetURandomFloat() < chance)
{
if (chance < 100)
PrintToChatAll("It's time to celebrate with MORE CARNAGE!");
for (int target = 1; target <= MaxClients; ++target)
if (IsClientConnected(target) && IsClientInGame(target) && IsPlayerAlive(target))
class_specific_buff(target, duration);
}
}
}
//Revenge doesn't have any in-game effect, but we put a message up about it.
if (deathflags & (TF_DEATHFLAG_KILLERREVENGE | TF_DEATHFLAG_ASSISTERREVENGE))
{
int killer = GetClientOfUserId(event.GetInt("attacker"));
char killername[MAX_NAME_LENGTH]; GetClientName(killer, killername, sizeof(killername));
int assister = GetClientOfUserId(event.GetInt("assister"));
char assistername[MAX_NAME_LENGTH]; GetClientName(assister, assistername, sizeof(assistername));
int gibbed = deathflags & TF_DEATHFLAG_GIBBED;
//ugh the verbosity
if ((deathflags & (TF_DEATHFLAG_KILLERREVENGE | TF_DEATHFLAG_ASSISTERREVENGE)) == (TF_DEATHFLAG_KILLERREVENGE | TF_DEATHFLAG_ASSISTERREVENGE))
{
//Double revenge!
if (gibbed)
PrintToChatAll("Bwahahahaha! Ooh that feels good. %s and %s splatter %s everywhere!!", killername, assistername, playername);
else
PrintToChatAll("Double revenge by %s and %s on the dominating %s!!", killername, assistername, playername);
}
else if (deathflags & TF_DEATHFLAG_KILLERREVENGE)
{
if (gibbed)
PrintToChatAll("Takedown! %s splatters %s all over everyone. Feels good.", killername, playername);
else
PrintToChatAll("Takedown! %s kicks the lifeless corpse of %s. Feels good.", killername, playername);
}
else
{
if (gibbed)
PrintToChatAll("%s helps %s to splatter %s all over everyone. Kaboom!", assistername, killername, playername);
else
PrintToChatAll("%s helps %s to kick the corpse of %s. That felt good.", assistername, killername, playername);
}
}
}
public void BuildingBlownUp(Event event, const char[] name, bool dontBroadcast)
{
if (event.GetInt("userid") == event.GetInt("attacker"))
{
//You blew up your own building. Not sure if this can happen, but if it
//does, make sure we award no points. (But there's no need to humiliate.)
return;
}
Debug("Object blown up! uid %d destroyed %d's building.",
event.GetInt("attacker"), event.GetInt("userid"));
if (event.GetInt("objecttype") == 2) //TFObject_Sentry
add_score(event.GetInt("attacker"), GetConVarInt(sm_ccc_carnage_per_sentry), 1);
else
add_score(event.GetInt("attacker"), GetConVarInt(sm_ccc_carnage_per_building), 1);
}
public void Ubered(Event event, const char[] name, bool dontBroadcast)
{
Debug("Ubercharge deployed!");
add_score(event.GetInt("userid"), GetConVarInt(sm_ccc_carnage_per_ubercharge), 0);
}
public void Upgraded(Event event, const char[] name, bool dontBroadcast)
{
if (GetConVarInt(sm_ccc_carnage_per_upgrade)) Debug("Object upgraded!");
add_score(event.GetInt("userid"), GetConVarInt(sm_ccc_carnage_per_upgrade), 0);
}
public void Captured(Event event, const char[] name, bool dontBroadcast)
{
int chance = GetConVarInt(sm_ccc_ignite_chance_on_capture);
if (100 * GetURandomFloat() >= chance) return; //Percentage chance
PrintToChatAll("The air opens with fire and everyone is caught in it!");
for (int target = 1; target <= MaxClients; ++target)
if (IsClientConnected(target) && IsClientInGame(target) && IsPlayerAlive(target))
TF2_IgnitePlayer(target, target);
}
public void StartCapture(Event event, const char[] name, bool dontBroadcast)
{
int chance = GetConVarInt(sm_ccc_ignite_chance_on_start_capture);
if (100 * GetURandomFloat() >= chance) return; //Percentage chance
PrintToChatAll("A spy lit a cigarette and EVERYONE is set on fire! Smoking kills, folks.");
for (int target = 1; target <= MaxClients; ++target)
if (IsClientConnected(target) && IsClientInGame(target) && IsPlayerAlive(target))
TF2_IgnitePlayer(target, target);
}
//Turret-specific regeneration (similar to regenerate() below)
Action returret(Handle timer, any target)
{
ignore(timer);
//When you die, you stop regenerating. This allows you to kill yourself
//(eg change class, or with the console) to de-turret yourself.
if (!IsClientConnected(target)) return Plugin_Stop;
int slot = GetClientUserId(target) % sizeof(carnage_points);
if (!IsClientInGame(target) || !IsPlayerAlive(target)) carnage_points[slot] = 0;
if (carnage_points[slot] >= 0) return Plugin_Stop; //Something's reset you. Maybe a team change or map change.
if (!TF2_IsPlayerInCondition(target, TFCond_MedigunDebuff)) return Plugin_Stop; //Ghost mode activated.
//Debug("Regenerating %d", target);
//TF2_RegeneratePlayer(target); //This is just too powerful.
//TODO: Slow ammo regeneration. If you just hold mouse 1, you will quickly run
//out, but if you're cautious, you should be able to hold the point.
if (--ticking_down[target] <= 0)
{
//Your immunity has just run out. Suddenly and without warning.
TF2_RemoveCondition(target, TFCond_UberchargedOnTakeDamage);
}
//Ensure that knockback immunity remains. If the turret gets healed by a
//medic, MegaHeal disappears; but this way, it'll kick in again momentarily.
//So in effect, a turret can be moved by knockback only while it's being
//healed. A bit odd, but less so than the alternative.
if (!TF2_IsPlayerInCondition(target, TFCond_MegaHeal))