-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrush_duel.sma
1707 lines (1417 loc) · 52.6 KB
/
rush_duel.sma
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 < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < hamsandwich >
#include < regex >
#include < orpheu >
#include < orpheu_stocks >
#include < xs >
//#define DKNIFE_DUEL
//#define TEAM_PLUGIN // if you have teamprotection plugin
#define SQL // if you want to have a ranking system through sql
#define ADMIN_FLAG ADMIN_LEVEL_A
#define PREFIX "^3[RUSH]^1"
#define SLAY_PLAYERS_TIME 9.0
#define MAX_ZONES 4
#if defined SQL
#include < sqlx >
#endif
#if defined TEAM_PLUGIN
/**
* Pauses/Unpauses teams
*
* @note teams don't get removed. You will show as team.
*
* @param id player1 id.
* @param id2 player2 id.
* @param unpause if to unpause teams
*/
native kf_pause_teaming(id, id2, unpause = 0);
#endif
#define set_bit(%1,%2) (%1 |= (1<<(%2&31)))
#define clear_bit(%1,%2) (%1 &= ~(1<<(%2&31)))
#define check_bit(%1,%2) (%1 & (1<<(%2&31)))
new const VERSION[] = "2.0.6";
new const SPRITE_BEAM[] = "sprites/laserbeam.spr";
#if defined SQL
new const host[] = "127.0.0.1";
new const user[] = "root";
new const pass[] = "";
new const db[] = "mysql_dust";
new Handle:tuple;
new bool:bResetRanks;
enum _:eRankData
{
P_ADDED,
P_DUELS,
P_WON,
P_DRAW,
P_LOST,
P_WONSLASH,
P_WONSTAB,
P_WONBOTH
}
new g_SqlInfo[ 33 ][ eRankData ];
new Float:fCheckRank[ 33 ];
#define COOLDOWN 10.0
#endif
#if AMXX_VERSION_NUM < 183
set_fail_state( "Plugin requires 1.8.3 or higher." );
#endif
enum _:eLastData
{
IPLAYER1 = 0,
IPLAYER2,
IROUND1,
IROUND2,
IWINNER,
IREASON,
IPOS,
IZONE,
ITYPE
}
enum
{
TOTAL = 2,
FAKE = 3
}
enum _:eEndRushReason
{
NONE = 0,
FAKE_ROUNDS,
TIME_END,
PLAYER_STOP,
PLAYER_DISCONNECTED
}
enum _:TASKS ( += 1000 )
{
TASK_DRAW = 141,
TASK_COUNTDOWN,
TASK_AUTOKILL,
TASK_RESTART,
TASK_REVIVE
}
enum _:attType
{
SLASH = 0,
STAB = 1,
BOTH = 2
}
enum _:rushData
{
PLAYER1,
PLAYER2,
RUSHTYPE
}
enum _:eWin
{
WON = 0,
LOST,
DRAW
}
new hasDisabledRush;
new hasBlocked[ MAX_PLAYERS + 1 ];
new bool:canRush;
new rushDir[ 128 ];
new activeZones;
new busyZones;
new bHasTouch;
new bIsInRush, bCanRun;
new g_RushInfo[ MAX_ZONES ][ rushData ];
new g_Rounds[ MAX_ZONES ][ 4 ];
new Float:g_HealthCache[ MAX_ZONES ][ 2 ];
new bIsZoneBusy;
new beam;
new editor, edit_zone;
new Float:g_vecOrigin[ MAX_ZONES ][ 2 ][ 3 ];
new Float:g_Velocity [ MAX_ZONES ][ 2 ][ 3 ];
new Float:g_Position [ MAX_ZONES ][ 2 ][ 3 ];
new const DisableAccess = ( 1 << 26 );
new HamHook:PostKilled;
new HamHook:PreKilled;
new HamHook:PlayerTouch;
new HamHook:PlayerSpawnPost;
//new HamHook:PlayerThink; // for some reason this doesn't work, so imma use fakemeta
new PlayerThink;
new OrpheuStruct:ppmove;
new Float:pHealth[ attType ];
new pRounds;
new pAlive;
new pSavePos;
new pSaveHealth;
new pFakeRounds;
public plugin_init()
{
register_plugin( "Rush Duel", VERSION, "DusT" );
register_cvar( "AmX_DusT", "Rush_Duel", FCVAR_SPONLY | FCVAR_SERVER );
register_clcmd( "amx_rush_menu", "AdminRush", ADMIN_FLAG );
register_clcmd( "say /rush", "CmdRush" );
register_clcmd( "say /stop", "CmdStopDuel" );
bind_pcvar_float( create_cvar( "rush_health_slash", "1" ), Float:pHealth[ SLASH ] );
bind_pcvar_float( create_cvar( "rush_health_stab", "35" ), Float:pHealth[ STAB ] );
bind_pcvar_float( create_cvar( "rush_health_both", "35" ), Float:pHealth[ BOTH ] );
bind_pcvar_num( create_cvar( "rush_save_health", "1" ), pSaveHealth );
bind_pcvar_num( create_cvar( "rush_save_pos", "0" ), pSavePos );
bind_pcvar_num( create_cvar( "rush_rounds", "10" ), pRounds );
bind_pcvar_num( create_cvar( "rush_fake_rounds", "3" ), pFakeRounds );
/*
Explanation rush_alive:
- 0: revives who made most kills. In case of draw, both revive.
- 1: revives who made most kills. In case of draw, both dead.
- 2: revives who killed the player on last round.
- 3: both revive.
*/
bind_pcvar_num( create_cvar( "rush_alive", "0", .description="Info on github.com/amxDust/RushDuel-amxx"), pAlive );
DisableHamForward( PostKilled = RegisterHamPlayer( Ham_Killed, "fw_PlayerKilled_Post", 1 ) );
DisableHamForward( PreKilled = RegisterHamPlayer( Ham_Killed, "fw_PlayerKilled_Pre", 0 ) );
//DisableHamForward( PlayerThink = RegisterHamPlayer( Ham_Think, "fw_PlayerThink_Pre", 0 ) );
DisableHamForward( PlayerTouch = RegisterHamPlayer( Ham_Touch, "fw_PlayerTouch" ) );
DisableHamForward( PlayerSpawnPost = RegisterHamPlayer( Ham_Spawn, "fw_PlayerSpawn_Post", 1 ) );
register_logevent( "RoundStart", 2, "1=Round_Start" );
register_logevent( "RoundEnd" , 2, "1=Round_End" );
OrpheuRegisterHook( OrpheuGetFunction( "PM_Duck" ), "OnPM_Duck" );
OrpheuRegisterHook( OrpheuGetFunction( "PM_Jump" ), "OnPM_Jump" );
OrpheuRegisterHook( OrpheuGetDLLFunction( "pfnPM_Move", "PM_Move" ), "OnPM_Move" );
activeZones = CountZones();
#if defined SQL
tuple = SQL_MakeDbTuple( host, user, pass, db );
register_concmd( "amx_rush_reset", "CmdRushReset", ADMIN_FLAG );
register_clcmd( "say /rrank", "CmdGetRank" );
register_clcmd( "say /rstats", "CmdGetRankStats" );
register_clcmd( "say /rtop", "CmdGetTop" );
#endif
}
public plugin_precache()
{
beam = precache_model( SPRITE_BEAM );
}
public client_disconnected( id )
{
if( task_exists( id + TASK_REVIVE ) )
remove_task( id + TASK_REVIVE );
if( check_bit( bIsInRush, id ) )
StopDuelPre( GetZone( id ), PLAYER_DISCONNECTED, id );
hasBlocked[ id ] = 0;
if( check_bit( hasDisabledRush, id ) )
clear_bit( hasDisabledRush, id );
#if defined SQL
arrayset( g_SqlInfo[ id ], 0, eRankData );
fCheckRank[ id ] = 0.0;
#endif
}
public RoundStart()
{
set_task( 2.0, "AllowRush" );
}
public AllowRush()
{
canRush = true;
}
public RoundEnd()
{
canRush = false;
}
public AdminRush( id, level, cid )
{
if( !cmd_access( id, level, cid, 0 ) )
return PLUGIN_HANDLED;
AdminRushMenu( id );
return PLUGIN_HANDLED;
}
AdminRushMenu( id )
{
new menuid = menu_create( fmt( "\rRush Menu^n\yAdmin Menu^n^nCurrent Active Zones: %d", activeZones ), "AdminRushHandler" );
menu_additem( menuid, "Create New Zone", _, activeZones >= MAX_ZONES? DisableAccess:0 );
menu_additem( menuid, "Edit Existing Zone", _, activeZones <= 0? DisableAccess:0 );
menu_display( id, menuid );
return PLUGIN_HANDLED;
}
public AdminRushHandler( id, menuid, item )
{
if( is_user_connected( id ) && item != MENU_EXIT )
{
switch( item )
{
case 0: EditZone( id, activeZones++ );
case 1: EditZoneMenu( id );
}
}
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
public CmdStopDuel( id )
{
if( check_bit( bIsInRush, id ) )
StopDuelPre( GetZone( id ), PLAYER_STOP, id );
}
public CmdRush( id )
{
new menuid = menu_create( "Rush Menu", "CmdRushHandler" );
menu_additem( menuid, "Rush" );
menu_additem( menuid, "Block Player" );
menu_additem( menuid, check_bit( hasDisabledRush, id )? "ENABLE Requests":"DISABLE Requests" );
menu_display( id, menuid );
return PLUGIN_HANDLED;
}
public CmdRushHandler( id, menuid, item )
{
if( is_user_connected( id ) && item != MENU_EXIT )
{
switch( item )
{
case 0:
{
RushMenu( id );
}
case 1:
{
BlockMenu( id );
}
case 2:
{
if( check_bit( hasDisabledRush, id ) )
clear_bit( hasDisabledRush, id );
else
set_bit( hasDisabledRush, id );
CmdRush( id );
}
}
}
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
BlockMenu( id )
{
new players[ 32 ], iNum;
get_players( players, iNum );
new menuid = menu_create( "Block Menu", "BlockMenuHandler" );
new buff[ 2 ];
// using "e" flag on get_players doesn't work always fine.
for( new i; i < iNum; i++ )
{ //spectator
if( id == players[ i ] || get_user_team( id ) == get_user_team( players[ i ] ) || get_user_team( players[ i ] ) == 3 )
continue;
buff[ 0 ] = players[ i ];
buff[ 1 ] = 0;
menu_additem( menuid, fmt( "%n%s", buff[ 0 ], check_bit( hasBlocked[ id ], buff[ 0 ] )? " [UNBLOCK]":"" ), buff );
}
menu_display( id, menuid );
}
public BlockMenuHandler( id, menuid, item )
{
if( is_user_connected( id ) && item != MENU_EXIT )
{
new buff[ 2 ]
menu_item_getinfo( menuid, item, _, buff, charsmax( buff ) );
if( is_user_connected( buff[ 0 ] ) )
{
if( check_bit( hasBlocked[ id ], buff[ 0 ] ) )
clear_bit( hasBlocked[ id ], buff[ 0 ] );
else
set_bit( hasBlocked[ id ], buff[ 0 ] );
}
BlockMenu( id );
}
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
public RushMenu( id )
{
if( !CanPlayerRush( id ) )
return PLUGIN_HANDLED;
new players[ 32 ], num;
get_players( players, num, "ach" );
new menuid = menu_create( "\rRush Menu^n\yChoose a Player", "RushMenuHandler" );
new bool:hasPlayers, buff[ 2 ];
for( new i; i < num; i++ )
{
if( id == players[ i ] || get_user_team( id ) == get_user_team( players[ i ] ) || get_user_team( players[ i ] ) == 3 || check_bit( bIsInRush, players[ i ] ) )
continue;
if( check_bit( hasBlocked[ players[ i ] ], id ) || check_bit( hasDisabledRush, players[ i ] ) )
continue;
buff[ 0 ] = players[ i ];
buff[ 1 ] = 0;
if( !hasPlayers )
hasPlayers = true;
menu_additem( menuid, fmt( "%n", buff[ 0 ] ), buff );
}
if( !hasPlayers )
{
client_print_color( id, print_team_red, "%s There are no players to rush with!", PREFIX );
return PLUGIN_HANDLED;
}
menu_display( id, menuid );
return PLUGIN_HANDLED;
}
public RushMenuHandler( id, menuid, item )
{
if( CanPlayerRush( id ) && item != MENU_EXIT )
{
new buff[ 2 ]
menu_item_getinfo( menuid, item, _, buff, charsmax( buff ) );
if( CanPlayerRush( id, true, buff[ 0 ] ) )
{
new menuid2 = menu_create( "Choose Rush Type", "RushTypeHandler" );
menu_additem( menuid2, "Only Slash ( R1 )", buff );
menu_additem( menuid2, "Only Stab ( R2 )" );
menu_additem( menuid2, "Both ( R1 and R2 )" );
menu_display( id, menuid2 );
}
}
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
public RushTypeHandler( id, menuid, item )
{
if( CanPlayerRush( id ) && item != MENU_EXIT )
{
new buff[ 2 ];
menu_item_getinfo( menuid, 0, _, buff, charsmax( buff ) );
if( CanPlayerRush( id, true, buff[ 0 ] ) )
{
new menuid2 = menu_create( fmt( "\y'%n' wants to rush %s with you!^nAccept?", id, item == 0? "only SLASH(R1)":item == 1? "only STAB(R2)":"(R1 and R2)" ), "SendChallengeHandler" );
new buffer[ 3 ];
buffer[ 0 ] = id;
buffer[ 1 ] = item;
buffer[ 2 ] = 0;
menu_additem( menuid2, "Accept", buffer );
menu_additem( menuid2, "Refuse" );
menu_display( buff[ 0 ], menuid2, _, 10 );
}
}
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
public SendChallengeHandler( id, menuid, item )
{
if( CanPlayerRush( id , false ) && item == 0 )
{
new buff[ 3 ];
menu_item_getinfo( menuid, 0, _, buff, charsmax( buff ) );
if( CanPlayerRush( id, true, buff[ 0 ] ) )
{
client_print_color( id, print_team_red, "%s You accepted %n's challenge.", PREFIX, buff[ 0 ] );
client_print_color( id, print_team_red, "%s %n accepted your challenge.", PREFIX, id );
GetReady( buff[ 0 ], id, buff[ 1 ] );
}
}
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
GetReady( id, pid, type )
{
new i;
for( i = 0; i < activeZones; i++ )
{
if( !check_bit( bIsZoneBusy, i ) )
break;
if( i == activeZones - 1 )
{
client_print_color( id, print_team_red, "%s There are no free zones to play. Retry later.", PREFIX );
return;
}
}
#if defined TEAM_PLUGIN
kf_pause_teaming( id, pid );
#endif
g_RushInfo[ i ][ PLAYER1 ] = id;
g_RushInfo[ i ][ PLAYER2 ] = pid;
g_RushInfo[ i ][ RUSHTYPE ] = type;
g_Rounds[ i ][ PLAYER1 ] = 0;
g_Rounds[ i ][ PLAYER2 ] = 0;
g_Rounds[ i ][ TOTAL ] = 1;
g_Rounds[ i ][ FAKE ] = 0;
set_bit( bIsInRush, id );
set_bit( bIsInRush, pid );
if( !busyZones )
ToggleFwds( true );
set_bit( bIsZoneBusy, i );
busyZones++;
if( pSaveHealth )
{
pev( id, pev_health, g_HealthCache[ i ][ PLAYER1 ] );
pev( pid, pev_health, g_HealthCache[ i ][ PLAYER2 ] );
}
set_pev( id, pev_health, pHealth[ type ] );
set_pev( pid, pev_health, pHealth[ type ] );
if( pSavePos )
{
pev( id, pev_origin, g_Position[ i ][ PLAYER1 ] );
pev( pid, pev_origin, g_Position[ i ][ PLAYER2 ] );
}
TeleportPlayer( id, i, PLAYER1 );
TeleportPlayer( pid, i, PLAYER2 );
LookAtOrigin( id, g_vecOrigin[ i ][ PLAYER2 ] );
LookAtOrigin( pid, g_vecOrigin[ i ][ PLAYER1 ] );
new params[ 1 ];
params[ 0 ] = 3;
set_task( 1.2, "CountDown", TASK_COUNTDOWN + i, params, 1 );
set_task( SLAY_PLAYERS_TIME, "SlayPlayers", TASK_AUTOKILL + i );
}
public ReviveDead( id )
{
id -= TASK_REVIVE;
ExecuteHamB( Ham_CS_RoundRespawn, id );
}
// unfinished__
public ContinueRounds( zone )
{
zone -= TASK_RESTART;
TeleportPlayer( g_RushInfo[ zone ][ PLAYER1 ], zone, PLAYER1 );
TeleportPlayer( g_RushInfo[ zone ][ PLAYER2 ], zone, PLAYER2 );
LookAtOrigin( g_RushInfo[ zone ][ PLAYER1 ], g_vecOrigin[ zone ][ PLAYER2 ] );
LookAtOrigin( g_RushInfo[ zone ][ PLAYER2 ], g_vecOrigin[ zone ][ PLAYER1 ] );
set_pev( g_RushInfo[ zone ][ PLAYER1 ], pev_health, pHealth[ g_RushInfo[ zone ][ RUSHTYPE ] ] );
set_pev( g_RushInfo[ zone ][ PLAYER2 ], pev_health, pHealth[ g_RushInfo[ zone ][ RUSHTYPE ] ] );
if( task_exists( TASK_AUTOKILL + zone ) )
remove_task( TASK_AUTOKILL + zone );
new params[ 1 ];
params[ 0 ] = 1;
set_task( 1.2, "CountDown", TASK_COUNTDOWN + zone, params, 1 );
set_task( SLAY_PLAYERS_TIME, "SlayPlayers", TASK_AUTOKILL + zone );
}
public SlayPlayers( zone )
{
zone -= TASK_AUTOKILL;
client_print_color( g_RushInfo[ zone ][ PLAYER1 ], print_team_red, "%s You took too much", PREFIX );
client_print_color( g_RushInfo[ zone ][ PLAYER2 ], print_team_red, "%s You took too much", PREFIX );
//g_Rounds[ zone ][ TOTAL ]++;
g_Rounds[ zone ][ FAKE ]++;
if( g_Rounds[ zone ][ FAKE ] >= pFakeRounds )
StopDuelPre( zone, FAKE_ROUNDS );
else
{
if( !task_exists( zone + TASK_RESTART ) )
set_task( 0.5, "ContinueRounds", zone + TASK_RESTART );
}
}
public CountDown( params[], zone )
{
zone -= TASK_COUNTDOWN;
new p1 = g_RushInfo[ zone ][ PLAYER1 ];
new p2 = g_RushInfo[ zone ][ PLAYER2 ];
if( !is_user_alive( p1 ) || !is_user_alive( p2 ) )
return;
new time = --params[ 0 ];
if( time > 0 )
{
set_hudmessage( 0, 255, 0, .holdtime = 1.0, .channel = -1 );
if( time == 2 )
{
show_hudmessage( p1, "Knife Rush^nREADY" );
show_hudmessage( p2, "Knife Rush^nREADY" );
client_cmd( p1, "spk ready" );
client_cmd( p2, "spk ready" );
}
else
{
show_hudmessage( p1, "Knife Rush^nSTEADY" );
show_hudmessage( p2, "Knife Rush^nSTEADY" );
}
set_task( 1.2, "CountDown", TASK_COUNTDOWN + zone, params, 1 );
}
else
{
set_hudmessage( 0, 255, 0, .holdtime = 3.0, .channel = -1 );
show_hudmessage( p1, "Knife Rush^nFIGHT!" );
show_hudmessage( p2, "Knife Rush^nFIGHT!" );
client_cmd( p1, "spk ^"/sound/hgrunt/fight!^"" );
client_cmd( p2, "spk ^"/sound/hgrunt/fight!^"" );
set_bit( bCanRun, p1 );
set_bit( bCanRun, p2 );
}
}
TeleportPlayer( id, zone, position )
{
set_pev( id, pev_velocity, Float:{ 0.0, 0.0, 0.0 } );
set_pev( id, pev_origin, g_vecOrigin[ zone ][ position ] );
new Float:distance = get_distance_f( g_vecOrigin[ zone ][ position ], g_vecOrigin[zone][ 1 - position ] );
new Float:vector[ 3 ];
vector[ 0 ] = ( ( g_vecOrigin[ zone ][ 1 - position ][ 0 ] - g_vecOrigin[ zone ][ position ][ 0 ] ) / distance );
vector[ 1 ] = ( ( g_vecOrigin[ zone ][ 1 - position ][ 1 ] - g_vecOrigin[ zone ][ position ][ 1 ] ) / distance );
vector[ 2 ] = ( ( g_vecOrigin[ zone ][ 1 - position ][ 2 ] - g_vecOrigin[ zone ][ position ][ 2 ] ) / distance );
static Float:multiplier = 250.0;
//( multiplier || multiplier = 250.0 );
g_Velocity[ zone ][ position ][ 0 ] = vector[ 0 ] * multiplier;
g_Velocity[ zone ][ position ][ 1 ] = vector[ 1 ] * multiplier;
g_Velocity[ zone ][ position ][ 2 ] = vector[ 2 ] * multiplier;
client_print_color( id, print_team_red, "%s %s ^4allowed^1. Round: ^4%d^1.", PREFIX, g_RushInfo[ zone ][ 2 ] == BOTH? "Both Slash (R1) and Stab (R2) are":g_RushInfo[ zone ][ 2 ] == SLASH? "Only SLASH (R1) is":"Only STAB (R2) is", g_Rounds[ zone ][ TOTAL ] );
}
ToggleFwds( bool:enable )
{
if( enable )
{
EnableHamForward( PreKilled );
EnableHamForward( PostKilled );
//EnableHamForward( PlayerThink );
EnableHamForward( PlayerTouch );
EnableHamForward( PlayerSpawnPost );
PlayerThink = register_forward( FM_PlayerPreThink, "fw_PlayerThink_Pre" );
}
else
{
DisableHamForward( PreKilled );
DisableHamForward( PostKilled );
//DisableHamForward( PlayerThink );
DisableHamForward( PlayerTouch );
DisableHamForward( PlayerSpawnPost );
unregister_forward( FM_PlayerPreThink, PlayerThink );
}
}
bool:CanPlayerRush( id, bool:message = true, player=0 )
{
if( !is_user_connected( id ) )
return false;
if( !canRush )
{
if( message )
client_print_color( id, print_team_red, "%s Rush Plugin is not available right now. Retry in few seconds.", PREFIX );
return false;
}
else if( !activeZones )
{
if( message )
client_print_color( id, print_team_red, "%s This map has no zones available", PREFIX );
return false;
}
else if( busyZones >= activeZones )
{
if( message )
client_print_color( id, print_team_red, "%s There are no free zones to play. Retry later.", PREFIX );
return false;
}
else if( player )
{
if( !is_user_connected( player ) )
{
if( message )
client_print_color( id, print_team_red, "%s Player is not connected.", PREFIX );
return false;
}
else if( !is_user_alive( player ) )
{
if( message )
client_print_color( id, print_team_red, "%s Player is not alive.", PREFIX );
return false;
}
else if( check_bit( bIsInRush, player ) )
{
if( message )
client_print_color( id, print_team_red, "%s Player is already in a challenge.", PREFIX );
return false;
}
else if( get_user_team( id ) == get_user_team( player ) )
{
if( message )
client_print_color( id, print_team_red, "%s You can't challenge a teammate.", PREFIX );
return false;
}
}
else if( !is_user_alive( id ) )
{
if( message )
client_print_color( id, print_team_red, "%s You must be alive in order to access ^4Rush Menu", PREFIX );
return false;
}
else if( check_bit( bIsInRush, id ) )
{
if( message )
client_print_color( id, print_team_red, "%s You are already in a challenge", PREFIX );
return false;
}
return true;
}
public fw_PlayerThink_Pre( id )
{
//client_print( id, print_chat, "%d %d", check_bit( bIsInRush, id ), check_bit( bCanRun, id ) );
if( check_bit( bIsInRush, id ) && check_bit( bCanRun, id ) )
{
//client_print( id, print_chat, "hello" );
new zone = GetZone( id );
new pos = GetPos ( id, zone );
set_pev( g_RushInfo[ zone ][ pos ], pev_velocity, g_Velocity[ zone ][ pos ] );
switch( g_RushInfo[ zone ][ RUSHTYPE ] )
{
case STAB:
{
new btn = pev( id, pev_button );
if( btn & IN_ATTACK )
{
set_pev( id, pev_button, ( btn & ~IN_ATTACK ) | IN_ATTACK2 );
}
}
case SLASH:
{
new btn = pev( id, pev_button );
if( btn & IN_ATTACK2 )
{
set_pev( id, pev_button, ( btn & ~IN_ATTACK2 ) | IN_ATTACK );
}
}
}
}
}
public fw_PlayerSpawn_Post( id )
{
if( check_bit( bIsInRush, id ) )
{
new zone = GetZone( id );
if( !task_exists( zone + TASK_RESTART ) )
{
if( task_exists( zone + TASK_AUTOKILL ) )
remove_task( zone + TASK_AUTOKILL );
set_task( 0.5, "ContinueRounds", zone + TASK_RESTART );
}
}
}
public fw_PlayerKilled_Post( victim, killer )
{
if( check_bit( bIsInRush, victim ) )
{
new zone = GetZone( victim );
new pos = GetPos ( victim, zone );
clear_bit( bCanRun, victim );
clear_bit( bCanRun, g_RushInfo[ zone ][ 1 - pos ] );
clear_bit( bHasTouch, zone );
if( task_exists( zone + TASK_AUTOKILL ) )
remove_task( zone + TASK_AUTOKILL );
if( killer == g_RushInfo[ zone ][ 1 - pos ] )
{
g_Rounds[ zone ][ 1 - pos ]++;
g_Rounds[ zone ][ TOTAL ]++;
client_print_color( killer, print_team_red, "%s You won this round. [ ^4%d^1 | ^3%d^1 | %d ]", PREFIX, g_Rounds[ 1 - pos ], g_Rounds[ pos ], pRounds );
client_print_color( victim, print_team_red, "%s You lost this round. [ ^4%d^1 | ^3%d^1 | %d ]", PREFIX, g_Rounds[ pos ], g_Rounds[ 1 - pos ], pRounds );
}
else
{
client_print( 0, print_chat, "%n %d - %n %d", killer, killer, g_Rounds[ zone ][ 1 - pos ], g_Rounds[ zone ][ 1 - pos ] )
if( g_Rounds[ zone ][ FAKE ] + 1 >= pFakeRounds )
StopDuelPre( zone, FAKE_ROUNDS );
else
{
g_Rounds[ zone ][ FAKE ]++;
client_print( 0, print_chat, "fake incremented to %d", g_Rounds[ zone ][ FAKE ] );
}
}
if( g_Rounds[ zone ][ TOTAL ] <= pRounds )
{
if( task_exists( zone + TASK_RESTART ) )
remove_task( zone + TASK_RESTART );
set_task( 0.1, "ReviveDead", victim + TASK_REVIVE );
set_task( 0.5, "ContinueRounds", zone + TASK_RESTART );
}
else
StopDuelPre( zone );
}
}
public fw_PlayerTouch( ent, id ){
if( check_bit( bIsInRush, id ) && ent != 0 )
{
new zone = GetZone( id );
if( !check_bit( bHasTouch, zone ) )
set_bit( bHasTouch, zone );
}
return HAM_IGNORED
}
public fw_PlayerKilled_Pre( victim, killer )
{
static msgCorpse;
if( check_bit( bIsInRush, victim ) )
{
if( msgCorpse || ( msgCorpse = get_user_msgid( "ClCorpse" ) ) )
set_msg_block( msgCorpse, BLOCK_ONCE );
return HAM_HANDLED;
}
return HAM_IGNORED;
}
StopDuelPre( zone, reason = NONE, player = 0 )
{
new param[ eLastData ];
param[ PLAYER1 ] = g_RushInfo[ zone ][ PLAYER1 ];
param[ PLAYER2 ] = g_RushInfo[ zone ][ PLAYER2 ];
param[ ITYPE ] = g_RushInfo[ zone ][ RUSHTYPE ];
param[ IROUND1 ] = g_Rounds[ zone ][ PLAYER1 ];
param[ IROUND2 ] = g_Rounds[ zone ][ PLAYER2 ];
param[ IREASON ] = reason;
param[ IZONE ] = zone;
if( player )
param[ IPOS ] = GetPos( player, zone );
clear_bit( bIsInRush, param[ PLAYER1 ] );
clear_bit( bIsInRush, param[ PLAYER2 ] );
clear_bit( bCanRun, param[ PLAYER1 ] );
clear_bit( bCanRun, param[ PLAYER2 ] );
if( task_exists( zone + TASK_RESTART ) )
remove_task( zone + TASK_RESTART );
if( task_exists( zone + TASK_AUTOKILL ) )
remove_task( zone + TASK_AUTOKILL );
if( task_exists( zone + TASK_COUNTDOWN ) )
remove_task( zone + TASK_COUNTDOWN );
switch( reason )
{
case NONE:
{
if( param[ IROUND1 ] > param[ IROUND2 ] )
{
param[ IWINNER ] = param[ PLAYER1 ];
}
else if( param[ IROUND2 ] > param[ IROUND1 ] )
{
param[ IWINNER ] = param[ PLAYER2 ];
param[ IPOS ] = PLAYER2;
}
else
param[ IWINNER ] = 0;
switch( pAlive )
{
case 0, 1:
{
if( param[ IWINNER ] )
{
set_task( 0.1, "ReviveDead", param[ IWINNER ] + TASK_REVIVE );
if( is_user_alive( param[ 1 - param[ IPOS ] ] ) )
user_silentkill( param[ 1 - param[ IPOS ] ] );
}
else
{
if( pAlive == 0 )
{
set_task( 0.1, "ReviveDead", param[ PLAYER1 ] + TASK_REVIVE );
set_task( 0.1, "ReviveDead", param[ PLAYER2 ] + TASK_REVIVE );
}
else
{
if( is_user_alive( param[ PLAYER1 ] ) )
user_silentkill( param[ PLAYER1 ] );
if( is_user_alive( param[ PLAYER2 ] ) )
user_silentkill( param[ PLAYER2 ] );
}
}
}
case 2:
{
if( is_user_alive( param[ PLAYER1 ] ) )
set_task( 0.1, "ReviveDead", param[ PLAYER1 ] + TASK_REVIVE );
if( is_user_alive( param[ PLAYER2 ] ) )
set_task( 0.1, "ReviveDead", param[ PLAYER2 ] + TASK_REVIVE );
}
case 3:
{
set_task( 0.1, "ReviveDead", param[ PLAYER1 ] + TASK_REVIVE );
set_task( 0.1, "ReviveDead", param[ PLAYER2 ] + TASK_REVIVE );
}
}
}
case PLAYER_STOP:
{
param[ IWINNER ] = player;
set_task( 0.1, "ReviveDead", param[ 1 - param[ IPOS ] ] + TASK_REVIVE );
}
case PLAYER_DISCONNECTED:
{
param[ IWINNER ] = player;
set_task( 0.1, "ReviveDead", param[ 1 - param[ IPOS ] ] + TASK_REVIVE );
}
case FAKE_ROUNDS:
{
set_task( 0.1, "ReviveDead", param[ param[ IPOS ] ] + TASK_REVIVE );
set_task( 0.1, "ReviveDead", param[ 1 - param[ IPOS ] ] + TASK_REVIVE );
}
}
set_task( 0.5, "StopDuel", _, param, sizeof param );
}
public StopDuel( param[] )
{
busyZones--;