-
Notifications
You must be signed in to change notification settings - Fork 23
/
callbacks.inc
1332 lines (1116 loc) · 38.9 KB
/
callbacks.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
/*
New SA-MP callbacks by Emmet_
Description:
An include which offers a wide selection of callbacks for scripters to use.
Start Date:
01/26/2014 @ 11:58 AM.
Last Update:
02/29/2016 @ 12:00 AM
Callbacks:
OnPlayerPause(playerid)
Description: Called when a player is paused.
OnPlayerResume(playerid, time)
Description: Called when a player has resumed.
OnPlayerHoldingKey(playerid, keys)
Description: Called when a player begins holding a specific key.
OnPlayerReleaseKey(playerid, keys)
Description: Called when a player releases a key.
OnPlayerFall(playerid, Float:damage)
Description: Called when a player falls and loses damage.
OnPlayerPacketLoss(playerid, Float:newpacket, Float:oldpacket)
Description: Called when a player experiences packet loss.
OnPlayerUseVending(playerid, type)
Description: Called when a player uses a vending machine.
OnPlayerCrashVehicle(playerid, vehicleid, Float:damage)
Description: Called when a player crashes a vehicle.
OnPlayerFPSChange(playerid, oldfps, newfps)
Description: Called when a player's FPS rate changes.
OnPlayerJackVehicle(playerid, targetid, vehicleid)
Description: Called when a player jacks another player's vehicle.
OnPlayerEmptyWeapon(playerid, weaponid)
Description: Called when a player depletes all ammo in a weapon.
OnPlayerFriendlyFire(playerid, targetid, weaponid)
Description: Called when a player shoots at a teammate.
OnPlayerTargetPlayer(playerid, targetid, weaponid)
Description: Called when a player targets a player with their weapon.
OnPlayerHideCursor(playerid, hovercolor)
Description: Called when a player cancels textdraw selection.
OnPlayerAntiReload(playerid, weaponid)
Description: Called when a player shoots without reloading their weapon.
OnPlayerAnimationPlay(playerid, animlib[], animname[])
Description: Called when an animation is played.
OnPlayerReloadWeapon(playerid, weaponid, ammo)
Description: Called when a player reloads their weapon.
OnPlayerActionChange(playerid, oldaction, newaction)
Description: Called when a player's action change (see action list).
OnPlayerRamPlayer(playerid, driverid, vehicleid, Float:damage)
Description: Called when a player rams another player.
OnPlayerSprayAtVehicle(playerid, vehicleid)
Description: Called wehn a player is spraying at a vehicle.
OnPlayerStartBurn(playerid)
Description: Called when a player is burning from fire.
OnPlayerStopBurn(playerid)
Description: Called when a player stops burning.
OnPlayerStartAim(playerid, weaponid)
Description: Called when a player is aiming a weapon.
OnPlayerStopAim(playerid)
Description: Called when a player stops aiming.
OnPlayerUseCamera(playerid)
Description: Called when a player snaps a picture with a camera (weapon ID: 43).
OnPlayerJump(playerid)
Description: Called when a player jumps (SHIFT key).
OnPlayerUseGarage(playerid, vehicleid, type)
Description: Called when a player uses a Pay'n'Spray or bomb shop.
OnVehicleCreated(vehicleid, color1, color2)
Description: Called when a vehicle is created by the server.
Definitions:
POTENTIAL_CRASH_DAMAGE
Description: The maximum amount of damage a vehicle must take before being ruled as a crash.
MAX_ACCUMULATED_SHOTS
Description: The maximum amount of shots the player fired without reloading before calling OnPlayerAntiReload.
*/
/*
native IsPlayerPaused(playerid);
native IsPlayerBurning(playerid);
native IsPlayerAiming(playerid);
native IsPlayerSwimming(playerid);
native IsPlayerSkydiving(playerid);
native IsPlayerJumping(playerid);
native IsPlayerNearVending(playerid);
native IsPlayerNearGarage(playerid, type);
native IsPlayerSprayingVehicle(playerid, vehicleid);
native GetPlayerFPS(playerid);
native GetPlayerAction(playerid);
native GetPlayerPausedTime(playerid);
native GetConnectedTime(playerid);
native GetPlayerPacketLoss(playerid);
*/
#if !defined POTENTIAL_CRASH_DAMAGE
#define POTENTIAL_CRASH_DAMAGE 55.0
#endif
#if !defined MAX_ACCUMULATED_SHOTS
#define MAX_ACCUMULATED_SHOTS 5
#endif
#define PLAYER_ACTION_NONE 0
#define PLAYER_ACTION_SHOOTING 1
#define PLAYER_ACTION_SWIMMING 2
#define PLAYER_ACTION_SKYDIVING 3
#define VENDING_TYPE_SPRUNK 1
#define VENDING_TYPE_CANDY 2
#define GARAGE_BOMBSHOP 1
#define GARAGE_PAYNSPRAY 2
// --------------------------------------------------
// Enumerators
// --------------------------------------------------
enum _:e_PLAYER_TICK_ENUM {
e_PLAYER_TICK,
e_PLAYER_LAST_UPDATE,
e_PLAYER_LAST_SHOT,
e_PLAYER_LAST_JUMP,
e_PLAYER_BURN_TICK,
e_PLAYER_VENDING_TICK
};
enum e_PLAYER_DATA {
e_PLAYER_FLAGS:e_bFlags,
Float:e_fPacket,
e_iHoldTimer,
e_iFrames,
e_iDrunk,
e_iMoney,
e_iTargetID,
e_iAction,
e_iAnimIndex,
e_iHoverColor,
e_iShotsFired[12],
e_iLastGun,
e_iLastAmmo,
e_iVehicleID
};
enum e_VEHICLE_DATA {
e_iPanels,
e_iDoors,
e_iLights,
Float:e_fHealth,
Float:e_fSpeed
};
enum e_PLAYER_FLAGS (<<= 1) {
e_bUpdate = 1,
e_bPaused,
e_bHoldKey,
e_bSelectTD,
e_bAnimSet,
e_bKeyPress,
e_bReloading,
e_bBurning,
e_bAiming
};
static
s_aPlayerInfo[MAX_PLAYERS][e_PLAYER_DATA],
s_aPlayerTickInfo[MAX_PLAYERS][e_PLAYER_TICK_ENUM],
s_aVehicleInfo[MAX_VEHICLES][e_VEHICLE_DATA];
// --------------------------------------------------
// Arrays
// --------------------------------------------------
enum e_VENDING_MACHINES {
e_VENDING_MACHINE_TYPE,
Float:e_VENDING_MACHINE_X,
Float:e_VENDING_MACHINE_Y,
Float:e_VENDING_MACHINE_Z,
};
enum e_VEHICLE_GARAGES {
e_VEHICLE_GARAGE_TYPE,
Float:e_VEHICLE_GARAGE_X,
Float:e_VEHICLE_GARAGE_Y,
Float:e_VEHICLE_GARAGE_Z
};
static
s_aVendingMachines[75][e_VENDING_MACHINES] = {
{VENDING_TYPE_SPRUNK, 2326.0273, -1645.9480, 14.8270},
{VENDING_TYPE_SPRUNK, 2060.1038, -1898.4542, 13.5538},
{VENDING_TYPE_SPRUNK, 1729.8389, -1943.8608, 13.5687},
{VENDING_TYPE_SPRUNK, 1929.5480, -1772.3799, 13.5469},
{VENDING_TYPE_SPRUNK, 1788.3971, -1369.2784, 15.7578},
{VENDING_TYPE_SPRUNK, 2352.9934, -1357.0977, 24.3984},
{VENDING_TYPE_SPRUNK, 1153.9095, -1460.9143, 15.7969},
{VENDING_TYPE_SPRUNK, 200.2008, -107.6411, 1.5513},
{VENDING_TYPE_SPRUNK, 1278.5946, 372.2171, 19.5547},
{VENDING_TYPE_SPRUNK, 2320.0242, 2532.0378, 10.8203},
{VENDING_TYPE_SPRUNK, 2086.5876, 2071.3574, 11.0579},
{VENDING_TYPE_SPRUNK, 1519.3347, 1055.2349, 10.8203},
{VENDING_TYPE_SPRUNK, 2503.1370, 1244.5089, 10.8203},
{VENDING_TYPE_SPRUNK, 373.8246, -178.9297, 1000.6328},
{VENDING_TYPE_SPRUNK, 2575.9084, -1284.4164, 1060.9844},
{VENDING_TYPE_SPRUNK, 495.9450, -23.5309, 1000.6797},
{VENDING_TYPE_SPRUNK, 501.8352, -2.2189, 1000.6797},
{VENDING_TYPE_SPRUNK, 2224.4141, -1153.4738, 1025.7969},
{VENDING_TYPE_SPRUNK, 2156.6990, 1606.7858, 999.9718},
{VENDING_TYPE_SPRUNK, 2209.1143, 1607.1713, 999.9691},
{VENDING_TYPE_SPRUNK, 2222.9924, 1606.8201, 999.9758},
{VENDING_TYPE_SPRUNK, -14.7329, 1176.1732, 19.5634},
{VENDING_TYPE_SPRUNK, -862.8334, 1537.4231, 22.5870},
{VENDING_TYPE_SPRUNK, -252.9273, 2597.9426, 62.8582},
{VENDING_TYPE_SPRUNK, -2419.5483, 985.9162, 45.2969},
{VENDING_TYPE_SPRUNK, -2419.5837, 984.5789, 45.2969},
{VENDING_TYPE_SPRUNK, -1349.3037, 492.3072, 11.1953},
{VENDING_TYPE_SPRUNK, -1981.6035, 142.6650, 27.6875},
{VENDING_TYPE_SPRUNK, -2005.6317, -490.8682, 35.5313},
{VENDING_TYPE_SPRUNK, -2034.4124, -490.8690, 35.5313},
{VENDING_TYPE_SPRUNK, -2063.2695, -490.8681, 35.5313},
{VENDING_TYPE_SPRUNK, -2092.0920, -490.8683, 35.5313},
{VENDING_TYPE_SPRUNK, -2119.7566, -423.4371, 35.5313},
{VENDING_TYPE_SPRUNK, -2119.4058, -422.2168, 35.5313},
{VENDING_TYPE_SPRUNK, -2097.2969, -397.5224, 35.5313},
{VENDING_TYPE_SPRUNK, -2068.5955, -397.5209, 35.5313},
{VENDING_TYPE_SPRUNK, -2039.8862, -397.5221, 35.5313},
{VENDING_TYPE_SPRUNK, -2011.1857, -397.5218, 35.5313},
{VENDING_TYPE_SPRUNK, -32.5050, -185.9060, 1003.5469},
{VENDING_TYPE_SPRUNK, -16.1550, -90.8514, 1003.5469},
{VENDING_TYPE_SPRUNK, -15.1533, -139.4374, 1003.5469},
{VENDING_TYPE_SPRUNK, -35.7115, -139.4262, 1003.5469},
{VENDING_TYPE_SPRUNK, -19.0527, -57.0465, 1003.5469},
{VENDING_TYPE_CANDY, -75.2803, 1227.9558, 19.7359},
{VENDING_TYPE_CANDY, -252.9929, 2599.7952, 62.8582},
{VENDING_TYPE_CANDY, -1455.1244, 2592.4136, 55.8359},
{VENDING_TYPE_CANDY, -1349.3669, 493.8326, 11.1953},
{VENDING_TYPE_CANDY, -2229.1858, 287.1634, 35.3203},
{VENDING_TYPE_CANDY, -33.9020, -186.0259, 1003.5469},
{VENDING_TYPE_CANDY, -17.5500, -90.9689, 1003.5469},
{VENDING_TYPE_CANDY, -16.4742, -139.5535, 1003.5469},
{VENDING_TYPE_CANDY, -36.1270, -57.1352, 1003.5469},
{VENDING_TYPE_CANDY, 1634.0918, -2238.2810, 13.5078},
{VENDING_TYPE_CANDY, 2480.8667, -1958.5234, 13.5830},
{VENDING_TYPE_CANDY, 2140.2676, -1161.4753, 23.9922},
{VENDING_TYPE_CANDY, 2153.8462, -1015.7134, 62.8837},
{VENDING_TYPE_CANDY, 662.4010, -551.4146, 16.3359},
{VENDING_TYPE_CANDY, 2271.7383, -77.2105, 26.5812},
{VENDING_TYPE_CANDY, 2845.7246, 1294.2957, 11.3906},
{VENDING_TYPE_CANDY, 1398.8699, 2223.3665, 11.0234},
{VENDING_TYPE_CANDY, 1659.4425, 1722.1097, 10.8281},
{VENDING_TYPE_CANDY, 2647.6428, 1128.9147, 11.1797},
{VENDING_TYPE_CANDY, 374.8246, 188.2364, 1008.3893},
{VENDING_TYPE_CANDY, 361.5366, 159.3573, 1008.3828},
{VENDING_TYPE_CANDY, 351.6461, 206.0936, 1008.3828},
{VENDING_TYPE_CANDY, 371.5602, 177.7127, 1019.9844},
{VENDING_TYPE_CANDY, 331.9078, 177.7589, 1019.9912},
{VENDING_TYPE_CANDY, 330.6430, 177.7591, 1019.9912},
{VENDING_TYPE_CANDY, 378.2992, -178.8477, 1000.6328},
{VENDING_TYPE_CANDY, 316.2407, -140.3572, 999.6016},
{VENDING_TYPE_CANDY, 500.6049, -2.1070, 1000.6797},
{VENDING_TYPE_CANDY, 2156.5854, 1607.8103, 999.9692},
{VENDING_TYPE_CANDY, 2202.4285, 1617.7483, 999.9766},
{VENDING_TYPE_CANDY, 2209.2668, 1620.4711, 999.9827},
{VENDING_TYPE_CANDY, 2223.1074, 1602.5835, 999.9734}
},
s_aVehicleGarages[][e_VEHICLE_GARAGES] = {
{GARAGE_PAYNSPRAY, -100.0488, 1117.3574, 19.7417},
{GARAGE_PAYNSPRAY, -1420.5437, 2585.5051, 55.8433},
{GARAGE_PAYNSPRAY, -2425.8203, 1022.0131, 50.3977},
{GARAGE_PAYNSPRAY, -1904.3649, 284.2363, 41.0469},
{GARAGE_PAYNSPRAY, 2065.1960, -1831.4946, 13.5469},
{GARAGE_PAYNSPRAY, 1025.0665, -1024.4612, 32.1016},
{GARAGE_PAYNSPRAY, 720.1285, -457.2187, 16.3359},
{GARAGE_PAYNSPRAY, 487.4250, -1739.0385, 10.8542},
{GARAGE_PAYNSPRAY, 1974.4723, 2162.3350, 11.0703},
{GARAGE_BOMBSHOP, 1849.0271, -1856.3948, 13.3828},
{GARAGE_BOMBSHOP, 2005.9357, 2312.9939, 10.8203}
}
;
// --------------------------------------------------
// Callbacks
// --------------------------------------------------
forward OnPlayerPause(playerid);
forward OnPlayerResume(playerid, time);
forward OnPlayerHoldingKey(playerid, keys);
forward OnPlayerReleaseKey(playerid, keys, time);
forward OnPlayerFall(playerid, Float:damage);
forward OnPlayerPacketLoss(playerid, Float:oldloss, Float:newloss);
forward OnPlayerCrashVehicle(playerid, vehicleid, Float:damage);
forward OnPlayerUseVending(playerid, type);
forward OnPlayerFPSChange(playerid, oldfps, newfps);
forward OnPlayerJackVehicle(playerid, targetid, vehicleid);
forward OnPlayerEmptyWeapon(playerid, weaponid);
forward OnPlayerFriendlyFire(playerid, targetid, weaponid);
forward OnPlayerTargetPlayer(playerid, targetid, weaponid);
forward OnPlayerHideCursor(playerid, hovercolor);
forward OnPlayerAntiReload(playerid, weaponid);
forward OnPlayerAnimationPlay(playerid, animlib[], animname[]);
forward OnPlayerReloadWeapon(playerid, weaponid, ammo);
forward OnPlayerActionChange(playerid, oldaction, newaction);
forward OnPlayerRamPlayer(playerid, driverid, vehicleid, Float:damage);
forward OnPlayerSprayAtVehicle(playerid, vehicleid);
forward OnPlayerStartBurn(playerid);
forward OnPlayerStopBurn(playerid);
forward OnPlayerStartAim(playerid, weaponid);
forward OnPlayerStopAim(playerid);
forward OnPlayerUseCamera(playerid);
forward OnPlayerJump(playerid);
forward OnPlayerUseGarage(playerid, vehicleid, type);
forward OnVehicleCreated(vehicleid, color1, color2);
// --------------------------------------------------
// Internal functions
// --------------------------------------------------
stock static Callback_GetFlag(playerid, e_PLAYER_FLAGS:flag)
{
return s_aPlayerInfo[playerid][e_bFlags] & flag;
}
stock static Callback_SetFlag(playerid, e_PLAYER_FLAGS:flag, status)
{
if(status)
return s_aPlayerInfo[playerid][e_bFlags] |= flag;
else
return s_aPlayerInfo[playerid][e_bFlags] &= ~flag;
}
stock static Callback_GetDriver(vehicleid)
{
// Returns the driver of a vehicle (obvious).
for(new i = 0, l = GetPlayerPoolSize(); i <= l; i ++)
{
if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
return i;
}
}
return INVALID_PLAYER_ID;
}
stock static Callback_GetMaxClip(weaponid)
{
// Returns the clip capacity for the specified weapon (required by OnPlayerAntiReload).
switch(weaponid)
{
case 22:
return 34;
case 23:
return 17;
case 24, 27:
return 7;
case 28, 32:
return 100;
case 29, 30:
return 30;
case 26:
return 4;
case 31:
return 50;
}
return 0;
}
stock static Float:Callback_GetSpeed(vehicleid)
{
// This is only for basic speed calculations. No need to get the real speed.
new
Float:fX,
Float:fY,
Float:fZ
;
GetVehicleVelocity(vehicleid, fX, fY, fZ);
return (floatsqroot((fX * fX) + (fY * fY) + (fZ * fZ)) * 100);
}
stock static Callback_IsVehicleInPoint(vehicleid, Float:range, Float:x, Float:y, Float:z)
{
// Checks if a vehicle is in range of a point.
new
Float:fX,
Float:fY,
Float:fZ
;
GetVehiclePos(vehicleid, fX, fY, fZ);
fX -= x;
fY -= y;
fZ -= z;
return ((fX * fX) + (fY * fY) + (fZ * fZ)) < (range * range);
}
// --------------------------------------------------
// External functions
// --------------------------------------------------
stock IsPlayerPaused(playerid)
{
return Callback_GetFlag(playerid, e_bPaused);
}
stock IsPlayerBurning(playerid)
{
return Callback_GetFlag(playerid, e_bBurning);
}
stock IsPlayerAiming(playerid)
{
return Callback_GetFlag(playerid, e_bAiming);
}
stock IsPlayerSwimming(playerid)
{
return (1538 <= GetPlayerAnimationIndex(playerid) <= 1544);
}
stock IsPlayerSkydiving(playerid)
{
return (GetPlayerWeapon(playerid) == 46 && GetPlayerAnimationIndex(playerid) == 1134);
}
stock IsPlayerJumping(playerid)
{
new
index = GetPlayerAnimationIndex(playerid),
keys,
ud,
lr
;
GetPlayerKeys(playerid, keys, ud, lr);
return (keys & KEY_JUMP) && (1196 <= index <= 1198);
}
stock GetPlayerFPS(playerid)
{
return s_aPlayerInfo[playerid][e_iFrames];
}
stock GetPlayerPausedTime(playerid)
{
return (GetConnectedTime(playerid) - s_aPlayerTickInfo[playerid][e_PLAYER_TICK]);
}
stock Float:GetPlayerPacketLoss(playerid)
{
return s_aPlayerInfo[playerid][e_fPacket];
}
stock GetPlayerAction(playerid)
{
return s_aPlayerInfo[playerid][e_iAction];
}
stock GetConnectedTime(playerid)
{
return NetStats_GetConnectedTime(playerid);
}
stock IsPlayerNearVending(playerid, type)
{
for(new i = 0; i < sizeof(s_aVehicleGarages); i ++)
{
if(s_aVendingMachines[i][e_VENDING_MACHINE_TYPE] == type && IsPlayerInRangeOfPoint(playerid, 2.0, s_aVendingMachines[i][e_VENDING_MACHINE_X], s_aVendingMachines[i][e_VENDING_MACHINE_Y], s_aVendingMachines[i][e_VENDING_MACHINE_Z]))
{
return 1;
}
}
return 0;
}
stock IsPlayerNearGarage(playerid, type)
{
for(new i = 0; i < sizeof(s_aVehicleGarages); i ++)
{
if(s_aVehicleGarages[i][e_VEHICLE_GARAGE_TYPE] == type && IsPlayerInRangeOfPoint(playerid, 8.0, s_aVehicleGarages[i][e_VEHICLE_GARAGE_X], s_aVehicleGarages[i][e_VEHICLE_GARAGE_Y], s_aVehicleGarages[i][e_VEHICLE_GARAGE_Z]))
{
return 1;
}
}
return 0;
}
stock IsPlayerSprayingVehicle(playerid, vehicleid)
{
new
index = GetPlayerAnimationIndex(playerid),
Float:x,
Float:y,
Float:z,
Float:a
;
if(IsVehicleStreamedIn(vehicleid, playerid))
{
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
x += 2.0 * floatsin(-a, degrees);
y += 2.0 * floatcos(-a, degrees);
if(Callback_IsVehicleInPoint(vehicleid, 2.0, x, y, z))
{
return (1160 <= index <= 1163) || index == 1167 || index == 640;
}
}
return 0;
}
// --------------------------------------------------
// Native hooks
// --------------------------------------------------
stock CB_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, addsiren = 0)
{
new
vehicleid = CreateVehicle(modelid, x, y, z, rotation, color1, color2, respawn_delay, addsiren);
if(vehicleid != INVALID_VEHICLE_ID)
{
CallLocalFunction("OnVehicleCreated", "iii", vehicleid, color1, color2);
}
return vehicleid;
}
stock CB_AddStaticVehicle(modelid, Float:x, Float:y, Float:z, Float:rotation, color1, color2)
{
new
vehicleid = AddStaticVehicle(modelid, x, y, z, rotation, color1, color2);
if(vehicleid != INVALID_VEHICLE_ID)
{
CallLocalFunction("OnVehicleCreated", "iii", vehicleid, color1, color2);
}
return vehicleid;
}
stock CB_AddStaticVehicleEx(modelid, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, addsiren = 0)
{
new
vehicleid = AddStaticVehicleEx(modelid, x, y, z, rotation, color1, color2, respawn_delay, addsiren);
if(vehicleid != INVALID_VEHICLE_ID)
{
CallLocalFunction("OnVehicleCreated", "iii", vehicleid, color1, color2);
}
return vehicleid;
}
stock CB_ApplyAnimation(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync = 0)
{
new
ret = ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
if(ret)
{
SetTimerEx("Callback_CheckAnimation", 100, false, "i", playerid);
}
return ret;
}
stock CB_SelectTextDraw(playerid, hovercolor)
{
new
ret = SelectTextDraw(playerid, hovercolor);
if(ret)
{
s_aPlayerInfo[playerid][e_iHoverColor] = hovercolor;
Callback_SetFlag(playerid, e_bSelectTD, true);
}
return ret;
}
stock CB_CancelSelectTextDraw(playerid)
{
new
ret = CancelSelectTextDraw(playerid);
if(ret)
{
s_aPlayerInfo[playerid][e_iHoverColor] = 0;
Callback_SetFlag(playerid, e_bSelectTD, false);
}
return ret;
}
// --------------------------------------------------
// SA-MP Callbacks
// --------------------------------------------------
public OnPlayerDisconnect(playerid, reason)
{
if(Callback_GetFlag(playerid, e_bHoldKey))
{
KillTimer(s_aPlayerInfo[playerid][e_iHoldTimer]);
}
for(new i = 0; i < e_PLAYER_TICK_ENUM; i ++)
{
s_aPlayerTickInfo[playerid][i] = 0;
}
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_NONE;
s_aPlayerInfo[playerid][e_iLastGun] = 0;
s_aPlayerInfo[playerid][e_iLastAmmo] = 0;
s_aPlayerInfo[playerid][e_iFrames] = 0;
s_aPlayerInfo[playerid][e_iDrunk] = 0;
s_aPlayerInfo[playerid][e_iMoney] = 0;
s_aPlayerInfo[playerid][e_iTargetID] = 0;
s_aPlayerInfo[playerid][e_iAnimIndex] = 0;
s_aPlayerInfo[playerid][e_iHoverColor] = 0;
s_aPlayerInfo[playerid][e_fPacket] = 0.0;
s_aPlayerInfo[playerid][e_iVehicleID] = INVALID_VEHICLE_ID;
s_aPlayerInfo[playerid][e_bFlags] = e_PLAYER_FLAGS:0;
for(new i = 0; i < 12; i ++)
{
s_aPlayerInfo[playerid][e_iShotsFired][i] = 0;
}
#if defined CB_OnPlayerDisconnect
return CB_OnPlayerDisconnect(playerid, reason);
#else
return 1;
#endif
}
public OnFilterScriptInit()
{
SetTimer("Callback_TabCheck", 600, true);
#if defined CB_OnFilterScriptInit
return CB_OnFilterScriptInit();
#else
return 1;
#endif
}
public OnGameModeInit()
{
SetTimer("Callback_TabCheck", 600, true);
#if defined CB_OnGameModeInit
return CB_OnGameModeInit();
#else
return 1;
#endif
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
new
capacity = Callback_GetMaxClip(weaponid),
teamid = GetPlayerTeam(playerid);
if((teamid != NO_TEAM && hittype == BULLET_HIT_TYPE_PLAYER) && GetPlayerTeam(hitid) == teamid)
{
CallLocalFunction("OnPlayerFriendlyFire", "iii", playerid, hitid, weaponid);
}
if(GetPlayerWeaponState(playerid) == WEAPONSTATE_LAST_BULLET && GetPlayerAmmo(playerid) == 1)
{
CallLocalFunction("OnPlayerEmptyWeapon", "ii", playerid, weaponid);
}
if((WEAPON_COLT45 <= weaponid <= WEAPON_TEC9) && weaponid != WEAPON_SHOTGUN)
{
new
index = (weaponid - WEAPON_COLT45);
s_aPlayerInfo[playerid][e_iShotsFired][index]++;
if(s_aPlayerInfo[playerid][e_iShotsFired][index] - capacity >= MAX_ACCUMULATED_SHOTS)
{
CallLocalFunction("OnPlayerAntiReload", "ii", playerid, weaponid);
s_aPlayerInfo[playerid][e_iShotsFired][index] = 0;
}
}
if(s_aPlayerInfo[playerid][e_iAction] != PLAYER_ACTION_SHOOTING)
{
CallLocalFunction("OnPlayerActionChange", "iii", playerid, s_aPlayerInfo[playerid][e_iAction], PLAYER_ACTION_SHOOTING);
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_SHOOTING;
}
s_aPlayerTickInfo[playerid][e_PLAYER_LAST_SHOT] = GetConnectedTime(playerid);
#if defined CB_OnPlayerWeaponShot
return CB_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, fX, fY, fZ);
#else
return 1;
#endif
}
public OnPlayerUpdate(playerid)
{
new
weaponid = GetPlayerWeapon(playerid),
level = GetPlayerDrunkLevel(playerid),
Float:health,
animlib[32],
animname[32];
if(IsPlayerSkydiving(playerid) && s_aPlayerInfo[playerid][e_iAction] != PLAYER_ACTION_SKYDIVING)
{
CallLocalFunction("OnPlayerActionChange", "iii", playerid, s_aPlayerInfo[playerid][e_iAction], PLAYER_ACTION_SKYDIVING);
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_SKYDIVING;
}
else if(!IsPlayerSkydiving(playerid) && s_aPlayerInfo[playerid][e_iAction] == PLAYER_ACTION_SKYDIVING)
{
CallLocalFunction("OnPlayerActionChange", "iii", playerid, s_aPlayerInfo[playerid][e_iAction], PLAYER_ACTION_NONE);
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_SKYDIVING;
}
else if(IsPlayerSwimming(playerid) && s_aPlayerInfo[playerid][e_iAction] != PLAYER_ACTION_SWIMMING)
{
CallLocalFunction("OnPlayerActionChange", "iii", playerid, s_aPlayerInfo[playerid][e_iAction], PLAYER_ACTION_SWIMMING);
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_SWIMMING;
}
else if(!IsPlayerSwimming(playerid) && s_aPlayerInfo[playerid][e_iAction] == PLAYER_ACTION_SWIMMING)
{
CallLocalFunction("OnPlayerActionChange", "iii", playerid, s_aPlayerInfo[playerid][e_iAction], PLAYER_ACTION_NONE);
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_NONE;
}
else if(s_aPlayerInfo[playerid][e_iAction] == PLAYER_ACTION_SHOOTING && (GetConnectedTime(playerid) - s_aPlayerTickInfo[playerid][e_PLAYER_LAST_SHOT]) > 1200)
{
CallLocalFunction("OnPlayerActionChange", "iii", playerid, s_aPlayerInfo[playerid][e_iAction], PLAYER_ACTION_NONE);
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_NONE;
}
if((GetConnectedTime(playerid) - s_aPlayerTickInfo[playerid][e_PLAYER_BURN_TICK]) >= 1500 && Callback_GetFlag(playerid, e_bBurning))
{
Callback_SetFlag(playerid, e_bBurning, false);
CallLocalFunction("OnPlayerStopBurn", "i", playerid);
}
switch(GetPlayerState(playerid))
{
case PLAYER_STATE_ONFOOT:
{
if(!s_aPlayerInfo[playerid][e_iTargetID] && GetPlayerTargetPlayer(playerid) == INVALID_PLAYER_ID)
{
s_aPlayerInfo[playerid][e_iTargetID] = INVALID_PLAYER_ID;
}
else if(GetPlayerTargetPlayer(playerid) != s_aPlayerInfo[playerid][e_iTargetID])
{
CallLocalFunction("OnPlayerTargetPlayer", "iii", playerid, s_aPlayerInfo[playerid][e_iTargetID], GetPlayerWeapon(playerid));
s_aPlayerInfo[playerid][e_iTargetID] = GetPlayerTargetPlayer(playerid);
}
if(!Callback_GetFlag(playerid, e_bReloading) && (WEAPON_COLT45 <= weaponid <= WEAPON_SNIPER) && GetPlayerWeaponState(playerid) == WEAPONSTATE_RELOADING)
{
Callback_SetFlag(playerid, e_bReloading, true);
CallLocalFunction("OnPlayerReloadWeapon", "iii", playerid, weaponid, GetPlayerAmmo(playerid));
}
else if(GetPlayerWeaponState(playerid) != WEAPONSTATE_RELOADING)
{
Callback_SetFlag(playerid, e_bReloading, false);
}
for(new i = 0; i < sizeof(s_aVendingMachines); i ++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, s_aVendingMachines[i][e_VENDING_MACHINE_X], s_aVendingMachines[i][e_VENDING_MACHINE_Y], s_aVendingMachines[i][e_VENDING_MACHINE_Z]))
{
if(GetPlayerAnimationIndex(playerid) == 1660 && (GetConnectedTime(playerid) - s_aPlayerTickInfo[playerid][e_PLAYER_VENDING_TICK]) > 3500)
{
CallLocalFunction("OnPlayerUseVending", "ii", playerid, s_aVendingMachines[i][e_VENDING_MACHINE_TYPE]);
s_aPlayerTickInfo[playerid][e_PLAYER_VENDING_TICK] = GetConnectedTime(playerid);
return 1;
}
}
}
if((GetConnectedTime(playerid) - s_aPlayerTickInfo[playerid][e_PLAYER_LAST_JUMP] >= 1000) && IsPlayerJumping(playerid))
{
CallLocalFunction("OnPlayerJump", "i", playerid);
s_aPlayerTickInfo[playerid][e_PLAYER_LAST_JUMP] = GetConnectedTime(playerid);
}
}
case PLAYER_STATE_DRIVER:
{
new
money = GetPlayerMoney(playerid);
if(s_aPlayerInfo[playerid][e_iMoney] != money)
{
if(GetPlayerCameraMode(playerid) == 15)
{
switch(s_aPlayerInfo[playerid][e_iMoney] - money)
{
case 100:
{
if(IsPlayerNearGarage(playerid, GARAGE_PAYNSPRAY))
{
CallLocalFunction("OnPlayerUseGarage", "iii", playerid, GetPlayerVehicleID(playerid), GARAGE_PAYNSPRAY);
}
}
case 500:
{
if(IsPlayerNearGarage(playerid, GARAGE_BOMBSHOP))
{
CallLocalFunction("OnPlayerUseGarage", "iii", playerid, GetPlayerVehicleID(playerid), GARAGE_BOMBSHOP);
}
}
}
}
s_aPlayerInfo[playerid][e_iMoney] = money;
}
new
vehicleid = GetPlayerVehicleID(playerid),
panels,
doors,
lights,
tires
;
GetVehicleHealth(vehicleid, health);
if(s_aVehicleInfo[vehicleid][e_fHealth] > health && floatabs(s_aVehicleInfo[vehicleid][e_fHealth] - health) >= POTENTIAL_CRASH_DAMAGE && floatabs(s_aVehicleInfo[vehicleid][e_fSpeed] - Callback_GetSpeed(vehicleid)) >= 5.0)
{
GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
if(s_aVehicleInfo[vehicleid][e_iPanels] != panels || s_aVehicleInfo[vehicleid][e_iDoors] != doors || s_aVehicleInfo[vehicleid][e_iLights] != lights)
{
CallLocalFunction("OnPlayerCrashVehicle", "iif", playerid, vehicleid, floatsub(s_aVehicleInfo[vehicleid][e_fHealth], health));
}
GetVehicleDamageStatus(vehicleid, s_aVehicleInfo[vehicleid][e_iPanels], s_aVehicleInfo[vehicleid][e_iDoors], s_aVehicleInfo[vehicleid][e_iLights], tires);
}
s_aVehicleInfo[vehicleid][e_fHealth] = health;
s_aVehicleInfo[vehicleid][e_fSpeed] = Callback_GetSpeed(vehicleid);
}
}
new
difference = s_aPlayerInfo[playerid][e_iDrunk] - level;
if(GetPlayerDrunkLevel(playerid) < 100)
{
SetPlayerDrunkLevel(playerid, 2000);
}
else if(s_aPlayerInfo[playerid][e_iDrunk] != level)
{
if((0 <= difference <= 200) && s_aPlayerInfo[playerid][e_iFrames] != difference)
{
if(s_aPlayerInfo[playerid][e_iFrames] < 0)
{
s_aPlayerInfo[playerid][e_iFrames] = 0;
}
CallLocalFunction("OnPlayerFPSChange", "iii", playerid, s_aPlayerInfo[playerid][e_iFrames], difference);
}
s_aPlayerInfo[playerid][e_iFrames] = difference;
s_aPlayerInfo[playerid][e_iDrunk] = level;
}
new
Float:packet = NetStats_PacketLossPercent(playerid);
if(floatcmp(packet, 0.0) != 0 && floatcmp(packet, s_aPlayerInfo[playerid][e_fPacket]) != 0)
{
CallLocalFunction("OnPlayerPacketLoss", "iff", playerid, s_aPlayerInfo[playerid][e_fPacket], packet);
s_aPlayerInfo[playerid][e_fPacket] = packet;
}
if(Callback_GetFlag(playerid, e_bAnimSet) && s_aPlayerInfo[playerid][e_iAnimIndex] != GetPlayerAnimationIndex(playerid))
{
Callback_SetFlag(playerid, e_bAnimSet, false);
GetAnimationName(s_aPlayerInfo[playerid][e_iAnimIndex], animlib, sizeof(animlib), animname, sizeof(animname));
if(strlen(animlib) > 0 && strlen(animname) > 0)
{
CallLocalFunction("OnPlayerAnimationPlay", "iss", playerid, animlib, animname);
}
}
new
ammo = GetPlayerAmmo(playerid);
if(s_aPlayerInfo[playerid][e_iLastAmmo] != ammo)
{
if(GetPlayerWeapon(playerid) == WEAPON_CAMERA && s_aPlayerInfo[playerid][e_iLastAmmo] > ammo)
{
CallLocalFunction("OnPlayerUseCamera", "i", playerid);
}
else if(GetPlayerWeapon(playerid) == WEAPON_SPRAYCAN && s_aPlayerInfo[playerid][e_iLastAmmo] > ammo)
{
for(new i = 1, l = GetVehiclePoolSize(); i <= l; i ++)
{
if(IsPlayerSprayingVehicle(playerid, i))
{
CallLocalFunction("OnPlayerSprayAtVehicle", "ii", playerid, i);
break;
}
}
}
s_aPlayerInfo[playerid][e_iLastAmmo] = ammo;
}
if(s_aPlayerInfo[playerid][e_iLastGun] != weaponid)
{
new
lastweapon = s_aPlayerInfo[playerid][e_iLastGun];
if((WEAPON_COLT45 <= lastweapon <= WEAPON_TEC9) && lastweapon != WEAPON_SHOTGUN)
{
s_aPlayerInfo[playerid][e_iShotsFired][lastweapon - WEAPON_COLT45] = 0;
}
s_aPlayerInfo[playerid][e_iLastGun] = weaponid;
}
else
{
if((WEAPON_COLT45 <= weaponid <= WEAPON_TEC9) && weaponid != WEAPON_SHOTGUN && GetPlayerWeaponState(playerid) == WEAPONSTATE_RELOADING)
{
s_aPlayerInfo[playerid][e_iShotsFired][weaponid - WEAPON_COLT45] = 0;
}
}
if(!Callback_GetFlag(playerid, e_bUpdate))
{
Callback_SetFlag(playerid, e_bUpdate, true);
}
s_aPlayerTickInfo[playerid][e_PLAYER_LAST_UPDATE] = GetConnectedTime(playerid);
#if defined CB_OnPlayerUpdate
return CB_OnPlayerUpdate(playerid);
#else
return 1;
#endif
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new
vehicleid = GetPlayerVehicleID(playerid);
switch(newstate)
{
case PLAYER_STATE_DRIVER:
{
GetVehicleHealth(vehicleid, s_aVehicleInfo[vehicleid][e_fHealth]);
s_aPlayerInfo[playerid][e_iVehicleID] = vehicleid;
}
case PLAYER_STATE_WASTED:
{
s_aPlayerInfo[playerid][e_iAction] = PLAYER_ACTION_NONE;
}