-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
rtd2.inc
1044 lines (889 loc) · 30.6 KB
/
rtd2.inc
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
#if defined _rtd2_included
#endinput
#endif
#define _rtd2_included
public SharedPlugin __pl_rtd2 = {
name = "RollTheDice2",
file = "rtd2.smx",
#if defined REQUIRE_PLUGIN
required = 1
#else
required = 0
#endif
};
#if !defined REQUIRE_PLUGIN
public void __pl_rtd2_SetNTVOptional(){
MarkNativeAsOptional("RTD2_GetPerkAny");
MarkNativeAsOptional("RTD2_SetPerkAny");
MarkNativeAsOptional("RTD2_GetPerkString");
MarkNativeAsOptional("RTD2_SetPerkString");
MarkNativeAsOptional("RTD2_SetPerkCall");
MarkNativeAsOptional("RTD2_GetPerkPrefString");
MarkNativeAsOptional("RTD2_GetPerkPrefCell");
MarkNativeAsOptional("RTD2_GetPerkPrefFloat");
MarkNativeAsOptional("RTD2_SetPerkPref");
MarkNativeAsOptional("RTD2_Format");
MarkNativeAsOptional("RTD2_GetClientPerkId"); // deprecated
MarkNativeAsOptional("RTD2_GetClientPerk");
MarkNativeAsOptional("RTD2_GetClientPerkTime");
MarkNativeAsOptional("RTD2_AddClientPerkTime");
MarkNativeAsOptional("RTD2_ForcePerk"); // deprecated
MarkNativeAsOptional("RTD2_Force");
MarkNativeAsOptional("RTD2_RollPerk"); // deprecated
MarkNativeAsOptional("RTD2_Roll");
MarkNativeAsOptional("RTD2_RemovePerk"); // deprecated
MarkNativeAsOptional("RTD2_Remove");
MarkNativeAsOptional("RTD2_GetPerkOfString"); // deprecated
MarkNativeAsOptional("RTD2_FindPerk");
MarkNativeAsOptional("RTD2_FindPerks");
MarkNativeAsOptional("RTD2_RegisterPerk"); // deprecated
MarkNativeAsOptional("RTD2_ObtainPerk");
MarkNativeAsOptional("RTD2_DisableModulePerks");
MarkNativeAsOptional("RTD2_IsRegOpen");
MarkNativeAsOptional("RTD2_SetPerkByToken"); // deprecated
MarkNativeAsOptional("RTD2_SetPerkById"); // deprecated
MarkNativeAsOptional("RTD2_DefaultCorePerk"); // deprecated
MarkNativeAsOptional("RTD2_CanPlayerBeHurt");
}
#endif
/*
*=========
* DEFINES
*=========
*/
#define ROLLFLAG_NONE 0
#define ROLLFLAG_OVERRIDE_DISABLED (1 << 0) /* Accept disabled perks */
#define ROLLFLAG_OVERRIDE_CLASS (1 << 1) /* If client is specified, ignore their class */
#define ROLLFLAG_OVERRIDE_LOADOUT (1 << 2) /* Ignore whether the client has irrelevant loadout */
#define ROLLFLAG_IGNORE_PERK_REPEATS (1 << 3) /* Ignore whether the perk was rolled recently */
#define ROLLFLAG_IGNORE_PLAYER_REPEATS (1 << 4) /* Ignore whether the client has rolled the perk recently */
#define ROLLFLAG_IGNORE_GLOBAL_LIMIT (1 << 5) /* Ignore whether the perk is globally limited */
#define ROLLFLAG_IGNORE_TEAM_LIMIT (1 << 6) /* Ignore whether the perk is team limited */
#define RTD2_MAX_PERK_NAME_LENGTH 128
/*
*=======
* ENUMS
*=======
*/
enum RTDPerkProp{
RTDPerk_Name = 0,
RTDPerk_Good,
RTDPerk_Sound,
RTDPerk_Token,
RTDPerk_Time,
RTDPerk_Classes,
RTDPerk_WeaponClasses,
RTDPerk_Tags,
RTDPerk_InternalCall,
RTDPerk_InternalInit,
RTDPerk_NoMedieval,
RTDPerk_LimitGlobal,
RTDPerk_LimitTeam,
RTDPerk_Enabled,
RTDPerk_External
}
enum RTDRemoveReason{
RTDRemove_PluginUnload = 0,
RTDRemove_Death,
RTDRemove_ClassChange,
RTDRemove_WearOff,
RTDRemove_Disconnect,
RTDRemove_Custom,
RTDRemove_NoPrint
}
enum RTDForceResult{
RTDForce_Success = 0,
RTDForce_NullPerk,
RTDForce_ClientDead,
RTDForce_ClientInRoll,
RTDForce_ClientInvalid,
RTDForce_Blocked
}
/*
*==========
* FETCHING
*==========
*/
/**
* Gets perk property of type any or Handle.
*
* @note Prefer to use RTDPerk methodmap over this.
* @note Handle type properties are not null.
* @note Handle type properties are not cloned.
*
* @param perk RTDPerk object
* @param prop RTDPerkProp property
*
* @return Value of specified property
*/
native any RTD2_GetPerkAny(RTDPerk perk, RTDPerkProp prop);
/**
* Sets perk property of type any.
*
* @note Prefer to use RTDPerk methodmap over this.
* @note Unlike RTD2_GetPerkAny, cannot interact with Handle type properties.
*
* @param perk RTDPerk object
* @param prop RTDPerkProp property
* @param value Value to set the property to
*
* @return Same RTDPerk object
*/
native RTDPerk RTD2_SetPerkAny(RTDPerk perk, RTDPerkProp prop, any value);
/**
* Gets perk property of type char[].
*
* @note Prefer to use RTDPerk methodmap over this.
*
* @param perk RTDPerk object
* @param prop RTDPerkProp property
* @param sBuffer char[] buffer to store the result in
* @param iBufferLen Length of the buffer
*
* @noreturn
*/
native void RTD2_GetPerkString(RTDPerk perk, RTDPerkProp prop, char[] sBuffer, int iBufferLen);
/**
* Sets perk property of type char[].
*
* @note Prefer to use RTDPerk methodmap over this.
*
* @param perk RTDPerk object
* @param prop RTDPerkProp property
* @param sStr Value to set the property to
*
* @return Same RTDPerk object
*/
native RTDPerk RTD2_SetPerkString(RTDPerk perk, RTDPerkProp prop, const char[] sStr);
/**
* Prototype for external perk calls.
*
* @param client Client to edit the perk on, guaranteed valid
* @param perk RTDPerk object
* @param bEeable Wether the perk should be enabled or disabled
*/
typedef RTDCall = function void(int client, RTDPerk perk, bool bEnable);
/**
* Set the function to call when perk should operate on client.
*
* @note Prefer to use RTDPerk methodmap over this.
*
* @param perk RTDPerk object
* @param func RTDCall function
*
* @return Same RTDPerk object
*/
native RTDPerk RTD2_SetPerkCall(RTDPerk perk, RTDCall func);
/**
* Gets perk setting of type cell.
*
* @note Prefer to use RTDPerk methodmap over this.
* @note This is just a wrapper for rounding the float type setting.
*
* @param perk RTDPerk object
* @param sKey Setting's key
*
* @return Setting's value
*/
native int RTD2_GetPerkPrefCell(RTDPerk perk, const char[] sKey);
/**
* Gets perk setting of type float.
*
* @note Prefer to use RTDPerk methodmap over this.
*
* @param perk RTDPerk object
* @param sKey Setting's key
*
* @return Setting's value
*/
native float RTD2_GetPerkPrefFloat(RTDPerk perk, const char[] sKey);
/**
* Gets perk setting of type char[].
*
* @note Prefer to use RTDPerk methodmap over this.
*
* @param perk RTDPerk object
* @param sKey Setting's key
* @param sBuffer char[] buffer to store the result in
* @param iBufferLen Length of the buffer
*
* @noreturn
*/
native void RTD2_GetPerkPrefString(RTDPerk perk, const char[] sKey, char[] sBuffer, int iBufferLen);
/**
* Sets perk property of type char[].
*
* @note Prefer to use RTDPerk methodmap over this.
* @note It will be determined internally whether to save the value as char[] or float.
*
* @param perk RTDPerk object
* @param sKey Setting's key
* @param sValue Value to set the setting to
*
* @return Same RTDPerk object
*/
native RTDPerk RTD2_SetPerkPref(RTDPerk perk, const char[] sKey, const char[] sValue);
/**
* Format specific perk properties into a buffer.
* Available specifiers: $Id$, $Name, $Good$,
* $Sound$, $Token$, $Time$, $Tags$, $Class$,
* $WeaponClass$, $Settings$, $InternalCall$,
* $InternalInit$
*
* @note Format example: "Perk: $Id$ - $Name$"
* @note Mind the capitalization.
* @note Prefer to use RTDPerk methodmap over this.
*
* @param perk RTDPerk object
* @param sBuffer Buffer to store the result in
* @param iBufferLen Length of the buffer
* @param sFormat Formatting rules
*
* @return Same RTDPerk object
*/
native RTDPerk RTD2_Format(RTDPerk perk, char[] sBuffer, int iBufferLen, const char[] sFormat);
/* Object-oriented wrapper for perk management */
methodmap RTDPerk{
// Specifies a perk. The perk is defined by the perk's ID.
// Defines getters and setters for accessing all of the
// perk's properties.
//
// RTDPerk methodmap would most of the times be obtained
// through other natives or passed as an argument in a
// forward. You probably don't want to call this
// constructor at all.
//
// For creating perks, use RTD2_ObtainPerk().
// For finding perks, use RTD2_FindPerk() and RTD2_FindPerks().
//
// RTDPerk is a cell under the hood, therefor doesn't need
// to be freed with delete or CloseHandle().
//
// @param sToken Token to bind the ID of
// @return RTDPerk object
public RTDPerk(const char[] sToken){
return view_as<RTDPerk>(0);
}
// Check if the perk is valid. This should be called after RTD2_FindPerk().
property bool Valid{
public get(){return view_as<int>(this) != -1;}
}
// Get name of the perk.
//
// @param sBuffer Buffer to store the result in
// @param iBufferLen Length of the buffer
//
// @noreturn
public void GetName(char[] sBuffer, int iBufferLen){
RTD2_GetPerkString(this, RTDPerk_Name, sBuffer, iBufferLen);}
// Set name of the perk.
//
// @param sVal Value to set the name to
//
// @return Same RTDPerk object
public RTDPerk SetName(const char[] sVal){
return RTD2_SetPerkString(this, RTDPerk_Name, sVal);}
// Retrieves or sets whether the perk is good.
property bool Good{
public get(){
return view_as<bool>(RTD2_GetPerkAny(this, RTDPerk_Good));}
public set(bool bVal){
RTD2_SetPerkAny(this, RTDPerk_Good, bVal);}
}
// Sets whether the perk is good.
//
// @note Prefer the property if not chaining methods.
//
// @param bSet Value to determine whether the perk is good
//
// @return Same RTDPerk object
public RTDPerk SetGood(bool bSet){
return RTD2_SetPerkAny(this, RTDPerk_Good, bSet);}
// Get sound path of the perk.
//
// @param sBuffer Buffer to store the result in
// @param iBufferLen Length of the buffer
//
// @noreturn
public void GetSound(char[] sBuffer, int iBufferLen){
RTD2_GetPerkString(this, RTDPerk_Sound, sBuffer, iBufferLen);}
// Set sound path of the perk.
//
// @param sVal Value to set the sound path to
//
// @return Same RTDPerk object
public RTDPerk SetSound(const char[] sVal){
return RTD2_SetPerkString(this, RTDPerk_Sound, sVal);}
// Get token of the perk.
//
// @param sBuffer Buffer to store the result in
// @param iBufferLen Length of the buffer
//
// @noreturn
public void GetToken(char[] sBuffer, int iBufferLen){
RTD2_GetPerkString(this, RTDPerk_Token, sBuffer, iBufferLen);}
// Retrieves or sets custom time of the perk.
property int Time{
public get(){
return view_as<int>(RTD2_GetPerkAny(this, RTDPerk_Time));}
public set(int iVal){
RTD2_SetPerkAny(this, RTDPerk_Time, iVal);}
}
// Sets custom time of the perk.
//
// @note Prefer the property if not chaining methods.
//
// @param iVal Value to set the time to
//
// @return Same RTDPerk object
public RTDPerk SetTime(int iVal){
return RTD2_SetPerkAny(this, RTDPerk_Time, iVal);}
// Retrieves perk class flags.
property int Classes{
public get(){
return view_as<int>(RTD2_GetPerkAny(this, RTDPerk_Classes));}
}
// Set class flags the perk is applicable to.
//
// @note This string is parsed the same way its config equivalent is.
//
// @param sClasses String with digits representing classes.
//
// @return Same RTDPerk object
public RTDPerk SetClasses(const char[] sClasses){
return RTD2_SetPerkString(this, RTDPerk_Classes, sClasses);}
// Retrieves ArrayList of weapon classes the perk is applicable to. This is never null and is not cloned.
property ArrayList WeaponClasses{
public get(){
return view_as<ArrayList>(RTD2_GetPerkAny(this, RTDPerk_WeaponClasses));}
}
// Set weapon classes the perk is applicable to.
//
// @note Prefer the property if not chaining methods. Manually pushing classes is faster.
// @note This string is parsed the same way its config equivalent is.
// @note This will destroy and create the weapon classes Handle.
//
// @param sWeapClasses String representing weapon classes or parts of them, separated by comma.
//
// @return Same RTDPerk object
public RTDPerk SetWeaponClasses(const char[] sWeapClasses){
return RTD2_SetPerkString(this, RTDPerk_WeaponClasses, sWeapClasses);}
// Retrieves ArrayList of perk's tags. This is never null and is not cloned.
property ArrayList Tags{
public get(){
return view_as<ArrayList>(RTD2_GetPerkAny(this, RTDPerk_Tags));}
}
// Set search tags of the perk.
//
// @note Prefer the property if not chaining methods. Manually pushing tags is faster.
// @note This string is parsed the same way its config equivalent is.
// @note This will destroy and create the tags Handle.
//
// @param sTags String representing tags, separated by comma
//
// @return Same RTDPerk object
public RTDPerk SetTags(const char[] sTags){
return RTD2_SetPerkString(this, RTDPerk_Tags, sTags);}
// Gets perk setting of type cell.
//
// @note This is just a wrapper for rounding the float type setting.
//
// @param sKey Setting's key
//
// @return Setting's value
public int GetPrefCell(const char[] sKey){
return RTD2_GetPerkPrefCell(this, sKey);}
// Gets perk setting of type float.
//
// @param sKey Setting's key
//
// @return Setting's value
public float GetPrefFloat(const char[] sKey){
return RTD2_GetPerkPrefFloat(this, sKey);}
// Gets perk setting of type char[].
//
// @param sKey Setting's key
// @param sBuffer char[] buffer to store the result in
// @param iBufferLen Length of the buffer
//
// @noreturn
public void GetPrefString(const char[] sKey, char[] sBuffer, int iBufferLen){
RTD2_GetPerkPrefString(this, sKey, sBuffer, iBufferLen);}
// Set settings of the perk.
//
// @note This will silently fail if sKey is prefixed with "m_".
//
// @param sKey Setting's key
// @param sValue Value to set the setting to
//
// @return Same RTDPerk object
public RTDPerk SetPref(const char[] sKey, const char[] sValue){
return RTD2_SetPerkPref(this, sKey, sValue);}
// Get internal call function name assigned to the perk.
//
// @param sBuffer Buffer to store the result in
// @param iBufferLen Length of the buffer
//
// @noreturn
public void GetInternalCall(char[] sBuffer, int iBufferLen){
RTD2_GetPerkString(this, RTDPerk_InternalCall, sBuffer, iBufferLen);}
// Set internal call of the perk.
//
// @param sName Name of the function to call during perk's execution.
//
// @return Same RTDPerk object
public RTDPerk SetInternalCall(const char[] sName){
return RTD2_SetPerkString(this, RTDPerk_InternalCall, sName);}
// Retrieves or sets whether the perk is enabled.
property bool Enabled{
public get(){
return view_as<bool>(RTD2_GetPerkAny(this, RTDPerk_Enabled));}
public set(bool bVal){
RTD2_SetPerkAny(this, RTDPerk_Enabled, bVal);}
}
// Sets whether the perk is enabled
//
// @note Prefer the property if not chaining methods.
// @note Perk is automatically enabled on registration.
//
// @param bVal Value to determine whether the perk is enabled
//
// @return Same RTDPerk object
public RTDPerk SetEnabled(bool bVal){
return RTD2_SetPerkAny(this, RTDPerk_Enabled, bVal);}
// Retrieves or sets whether the perk should call an external function.
property bool External{
public get(){
return view_as<bool>(RTD2_GetPerkAny(this, RTDPerk_External));}
public set(bool bVal){
RTD2_SetPerkAny(this, RTDPerk_External, bVal);}
}
// Sets whether the perk should call an external function.
//
// @note Prefer the property if not chaining methods.
// @note Perk is automatically set to call an external function on registration.
//
// @param bVal Value to determine whether the perk should call an external function
//
// @return Same RTDPerk object
public RTDPerk SetExternal(bool bVal){
return RTD2_SetPerkAny(this, RTDPerk_External, bVal);}
// Set external call of the perk.
//
// @note This also sets Enable and External to true.
//
// @param func RTDCall function
//
// @return Same RTDPerk object
public RTDPerk SetCall(RTDCall func){
return RTD2_SetPerkCall(this, func);}
// Sets whether the perk is disabled in Medieval mode.
//
// @note Prefer the property if not chaining methods.
//
// @param bVal Value to determine whether the perk is disabled in Medieval mode
//
// @return Same RTDPerk object
public RTDPerk SetNoMedieval(bool bVal){
return RTD2_SetPerkAny(this, RTDPerk_NoMedieval, bVal);}
// Retrieves or sets whether the perk is disabled in Medieval mode.
property bool NoMedieval{
public get(){
return view_as<bool>(RTD2_GetPerkAny(this, RTDPerk_NoMedieval));}
public set(bool bVal){
RTD2_SetPerkAny(this, RTDPerk_NoMedieval, bVal);}
}
// Sets the active use limit of the perk, globally.
//
// @note Prefer the property if not chaining methods.
//
// @param bVal Value to set the limit to
//
// @return Same RTDPerk object
public RTDPerk SetLimitGlobal(int iVal){
return RTD2_SetPerkAny(this, RTDPerk_LimitGlobal, iVal);}
// Retrieves or sets the active use limit of the perk, globally.
property int LimitGlobal{
public get(){
return view_as<int>(RTD2_GetPerkAny(this, RTDPerk_LimitGlobal));}
public set(int iVal){
RTD2_SetPerkAny(this, RTDPerk_LimitGlobal, iVal);}
}
// Sets the active use limit of the perk, per team.
//
// @note Prefer the property if not chaining methods.
//
// @param bVal Value to set the limit to
//
// @return Same RTDPerk object
public RTDPerk SetLimitTeam(int iVal){
return RTD2_SetPerkAny(this, RTDPerk_LimitTeam, iVal);}
// Retrieves or sets the active use limit of the perk, per team.
property int LimitTeam{
public get(){
return view_as<int>(RTD2_GetPerkAny(this, RTDPerk_LimitTeam));}
public set(int iVal){
RTD2_SetPerkAny(this, RTDPerk_LimitTeam, iVal);}
}
// Format specific perk properties into a buffer.
// Available specifiers: $Id$, $Name, $Good$,
// $Sound$, $Token$, $Time$, $Tags$, $Class$,
// $WeaponClass$, $Settings$, $NoMedieval$,
// $LimitGlobal$, $LimitTeam$.
//
// @note Format example: "Perk: $Id$ - $Name$"
// @note Mind the capitalization.
//
// @param sBuffer Buffer to store the result in
// @param iBufferLen Length of the buffer
// @param sFormat Formatting rules
//
// @return Same RTDPerk object
public RTDPerk Format(char[] sBuffer, int iBufferLen, const char[] sFormat){
return RTD2_Format(this, sBuffer, iBufferLen, sFormat);}
}
// Object-oriented wrapper for ArrayList of RTDPerk's
methodmap RTDPerkList < ArrayList{
// Creates a RTDPerkList. RTDPerkLits inherits from ArrayList and holds
// RTDPerks, which in turn are simply IDs of perks.
//
// The RTDPerkList must be freed via delete or CloseHandle().
//
// @return RTDPerkList object
public RTDPerkList(){
return view_as<RTDPerkList>(new ArrayList());
}
// Wrapper for receiving contents as RTDPerk.
//
// @param i Index to retrieve the perk at.
//
// @return RTDPerk object
public RTDPerk Get(int i){
return view_as<RTDPerk>(view_as<ArrayList>(this).Get(i));
}
// Get random perk from the list.
//
// @return RTDPerk object
public RTDPerk GetRandom(){
int iLen = this.Length;
if(!iLen) return view_as<RTDPerk>(-1);
return this.Get(GetRandomInt(0, --iLen));
}
}
/*
*==========
* FORWARDS
*==========
*/
/**
* Called everytime rtd is activated to determine if the player can use the dice mod.
* Return Plugin_Continue to allow, anything else denies them access.
*
* @note sm_forcertd command and RTD2_Force native do not call this.
*
* @param client Client index.
*/
forward Action RTD2_CanRollDice(int client);
/**
* Called when a perk is about to be forced by an admin (client) on a target (iTarget).
* Return Plugin_Continue to allow, anything else denies the force.
*
* @note Called only by sm_forcertd command and RTD2_Force native.
*
* @param client Client index.
* @param iTarget Target client index.
* @param perk Perk object.
*/
forward Action RTD2_CanForcePerk(int client, int iTarget, RTDPerk perk);
/**
* Called when a perk is about to be removed by an admin (client) from a target (iTarget).
* Return Plugin_Continue to allow, anything else denies the force.
*
* @note Called only by sm_removertd command and RTD2_Remove native.
*
* @param client Client index.
* @param iTarget Target client index.
* @param perk Perk object.
*/
forward Action RTD2_CanRemovePerk(int client, int iTarget, RTDPerk perk);
/**
* Called when a perk has just been activated on a player.
*
* @param client Client Index.
* @param perk Perk object.
* @param iDuration Perk Duration (-1 if no time).
*/
forward void RTD2_Rolled(int client, RTDPerk perk, int iDuration);
/**
* Called when a perk has just been removed from a player.
*
* @param client Client Index.
* @param perk Removed Perk's Index.
* @param reason Reason for removal.
*/
forward void RTD2_Removed(int client, RTDPerk perk, RTDRemoveReason reason);
/*
*=========
* NATIVES
*=========
*/
/**
* Returns player's current perk index. Meant to check if player is using RTD.
*
* @param client Client Index.
*
* @return Perk index if client is using RTD, -1 otherwise.
*/
#pragma deprecated Use RTD2_GetClientPerk instead
native int RTD2_GetClientPerkId(int client);
/**
* Returns player's current RTDPerk. Can be used to check if the player is in roll.
*
* @note RTDPerk.Valid is false if client was not in roll.
*
* @param client Client Index.
*
* @return RTDPerk object
*/
native RTDPerk RTD2_GetClientPerk(int client);
/**
* Returns time in seconds the player has left to the perk end.
*
* @param client Client Index.
*
* @return Time in seconds if client is using RTD, -1 otherwise.
*/
native int RTD2_GetClientPerkTime(int client);
/**
* Adds time to client's current roll.
*
* @param client Client Index.
* @param iAddedTime Additional time in seconds, can be negative to subtract.
*
* @return New remaining perk time, or non-positive if client was not in roll or perk is about to be removed because of this call.
*/
native int RTD2_AddClientPerkTime(int client, int iAddedTime);
/**
* Forces a perk on a player
*
* @param client Client Index.
* @param sPerk Perk string, containing id, token or a tag. If invalid a roll will be used.
* @param iTime Custom perk's time. -1 = don't use.
* @param bOvrClass 0/1 - If perk doesn't match player's class, should it be applied anyway?
* @param initiator Entity which initiated forcing the perk.
*
* @return -1 because deprecated
*/
#pragma deprecated Use RTD2_Force instead
native int RTD2_ForcePerk(int client, const char[] sQuery="", iTime=-1, bOvrClass=0, initiator=0);
/**
* Forces a perk on a player
*
* @param client Client Index.
* @param sQuery Query string, containing id, token or a tag. If invalid a roll will occur.
* @param iTime Custom perk's time. -1 = don't use.
* @param iInitiator Entity which initiated forcing the perk.
*
* @return RTDForceResult enum value
*/
native RTDForceResult RTD2_Force(int client, const char[] sQuery, int iTime=-1, int iInitiator=0);
/**
* Rolls a perk with given data.
*
* @note This does NOT apply the perk to the client.
*
* @param client Client Index.
* @param bOverrideDisabled 0/1 - Roll disabled perks?
* @param bOverrideClass 0/1 - Roll perks NOT for player's class?
* @param bCountRepeat 0/1 - Roll perks which repeated twice in 2 rolls for client? (sm_rtd2_repeat 1 ONLY)
* @param bCountGreatRepeat 0/1 - Roll perks which repeated twice in 3 rolls for client? (sm_rtd2_repeatgreat 1 ONLY)
*
* @return Perk index on success, -1 otherwise
*/
#pragma deprecated Use RTD2_Roll instead
native int RTD2_RollPerk(int client=0, int bOverrideDisabled=0, int bOverrideClass=0, int bCountRepeat=1, int bCountGreatRepeat=1);
/**
* Rolls a perk with given data.
*
* @note This does NOT apply the perk to the client.
* @note RTDPerk.Valid is false is no applicable perks are found.
*
* @param client Client Index.
* @param iRollFlags Roll flag definitions.
* @param sFilter Query by which to filter the applicable perks.
*
* @return RTDPerk object
*/
native RTDPerk RTD2_Roll(int client=0, int iRollFlags=ROLLFLAG_NONE, const char[] sFilter="");
/**
* Removes current perk from the client.
*
* @param client Client Index.
* @param reason Reason.
* @param sReason Provide custom reason IF iReason=RTDRemove_Custom.
*
* @return Perk which got removed, invalid if client wasn't using RTD.
*/
#pragma deprecated Use RTD2_Roll instead
native RTDPerk RTD2_RemovePerk(int client, RTDRemoveReason reason=RTDRemove_WearOff, const char[] sReason="");
/**
* Removes current perk from the client.
*
* @note RTDPerk.Valid is falce if client was not in roll.
*
* @param client Client Index.
* @param reason Reason enum.
* @param sReason Provide custom reason IF reason=RTDRemove_Custom.
* @param bForce Forced removals are treated as loggable actions, whereas non-forced are "natural" reasons. No distinction other than what is logged.
* @param iInitiator Client who initiated the removal. Used only when bForce=true.
*
* @return RTDPerk object
*/
native RTDPerk RTD2_Remove(int client, RTDRemoveReason reason=RTDRemove_WearOff, const char[] sReason="", bool bForce=false, int iInitiator=0);
/**
* Gets the perk's index by either the actual index, perk's token or a single tag
*
* @param sString String to search by.
*
* @return Perk's index on success, -1 otherwise.
*/
#pragma deprecated Use RTD2_FindPerk instead
native RTDPerk RTD2_GetPerkOfString(const char[] sString="");
/**
* Finds a perk by token or ID, where token is prioritized.
*
* @note RTDPerk.Valid is false if perk is not found.
*
* @param sQuery Query to search by.
*
* @return RTDPerk object
*/
native RTDPerk RTD2_FindPerk(const char[] sQuery="");
/**
* Finds perks by token, ID or tags.
*
* @note Will not be null, might be empty.
* @note Must be freed via delete or CloseHandle().
*
* @param sQuery Query to search by.
*
* @return RTDPerkList object
*/
native RTDPerkList RTD2_FindPerks(const char[] sQuery="");
/*
*==========
* EXTERNAL
*==========
*/
/*
The following are grouped individually,
because they are meant to be for plugins
which register their own perks to the RTD.
For a full tutorial on how to use those,
see the RTD's thread on AlliedModders:
https://forums.alliedmods.net/showthread.php?t=278579
*/
/**
* Registers a perk from a different plugin to the core.
* The parameters match the fields in the KV file.
* Perks cannot be unregistered, disable them instead.
* If a token was found in another perk, it will OVERRIDE that perk.
* For in-depth information, see the RTD thread on AlliedModders.
*
* @param sToken Unique token used for addressing the perk.
* @param sName Perk name.
* @param bGood false - bad perk; true - good perk
* @param sSound Path to the initiation sound file.
* @param iTime -1 -> no timer; 0 -> ConVar default time; 0< -> Custom perk time.
* @param sClass Class string to limit the perk to.
* @param sWeapon Weapon classnames to limit the perk to.
* @param sTags Perk's tags used to find or address the perk.
* @param func Callback function; public(int client, RTDPerk perk, bool bEnable)
*
* @return Perk's index on success, -1 otherwise (not all paremeters filled).
*/
#pragma deprecated Use RTD2_ObtainPerk instead
native RTDPerk RTD2_RegisterPerk(const char[] sToken, const char[] sName, bool bGood, const char[] sSound, int iTime, const char[] sClass, const char[] sWeapons, const char[] sTags, RTDCall func);
/**
* Gets a perk by token, or registers one if not found.
* Perks cannot be unregistered, disable them instead.
* If a perk is registered, a new ID is automatically assigned.
* For in-depth information, see the RTD thread on AlliedModders.
*
* @note This sets External to true on that perk.
*
* @param sToken Unique token used for addressing the perk.
*
* @return RTDPerk object
*/
native RTDPerk RTD2_ObtainPerk(const char[] sToken);
/**
* Disables all the perks that were registered by the plugin this
* native is called from, and sets all overriden core perks back
* to the default state.
*
* If registering perks, this must be called in the OnPluginEnd.
* This will make sure perks registered by the module will be
* properly disposed on clients who currently are using them,
* by calling the RTDCall function that disables them.
*
* @noreturn
*/
native void RTD2_DisableModulePerks();
/**
* Registering a perk via external plugin is possible only after all the core ones were registered.
* You can register new perks in OnPluginStart() when this native returns true (if late-loaded).
* Otherwise, register them in the RTD2_OnRegOpen() forward.
*
* @return true if registering is open, false otherwise.
*/
native bool RTD2_IsRegOpen();
/**
* This forward will fire when RTD is ready handle perk registration.
* RTD2_ObtainPerk() should ALWAYS be executed in this forward.
*/
forward void RTD2_OnRegOpen();
/**
* Enables/disables perk by token.
*
* @param sToken The token to find the perk by.
* @param iDir (direction) -1 = disable, 0 = toggle, 1 = enable
*