-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMathPlugin.cpp
1872 lines (1303 loc) · 56.6 KB
/
MathPlugin.cpp
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
//#define NO_EVENT_HANDLER
#include "MathPlugin.h"
#include <math.h>
#include <string>
//#include "source/CScripting.h"
#include <sys/stat.h>
#include <sys/types.h>
std::list<AMX *> p_Amx;
void **ppPluginData;
extern void *pAMXFunctions;
// track activity
int lastplayerinput[max_players];
int lastplayerupdate[max_players];
WaterDataTriQuad watertris[6] = {
{ 0.0, { -1610.0, 108.0 }, { -1550.0, 168.0 }, { -1610.0, 168.0 }, { -1550.0, 168.0 }, { -1550.0, 108.0 } },
{ 0.0, { -1728.0, -222.0 }, { -1568.0, -62.0 }, { -1728.0, -62.0 }, { -1568.0, -62.0 }, { -1728.0, -222.0 } },
{ 0.0, { -1724.0, 58.0 }, { -1612.0, 170.0 }, { -1724.0, 170.0 }, { -1612.0, 170.0 }, { -1724.0, 58.0 } },
{ 0.0, { -1550.0, -20.0 }, { -1362.0, 168.0 }, { -1550.0, 168.0 }, { -1362.0, 168.0 }, { -1550.0, -20.0 } },
{ 0.0, { -1722.0, -62.0 }, { -1574.0, 86.0 }, { -1722.0, -62.0 }, { -1574.0, -62.0 }, { -1574.0, 86.0 } },
{ 0.0, { -912.0, 20.0 }, { -724.0, 208.0 }, { -912.0, 208.0 }, { -724.0, 208.0 }, { -912.0, 20.0 } }
};
WaterDataQuad waterrects[301] = {
{ 1083.0, { 1270.0, -780.0 }, { 1290.0, -768.0 } },
{ 112.0, { 1084.0, -684.0 }, { 1104.0, -660.0 } },
{ 87.0, { 1270.0, -812.0 }, { 1290.0, -800.0 } },
{ 78.0, { 502.0, -1114.0 }, { 522.0, -1098.0 } },
{ 77.0, { 178.0, -1244.0 }, { 206.0, -1216.0 } },
{ 74.0, { 218.0, -1180.0 }, { 238.0, -1172.0 } },
{ 74.0, { 214.0, -1208.0 }, { 246.0, -1180.0 } },
{ 41.0, { -1248.0, 2536.0 }, { -1088.0, 2824.0 } },
{ 41.0, { -1400.0, 2074.0 }, { -1328.0, 2150.0 } },
{ 41.0, { -550.0, 2004.0 }, { -494.0, 2036.0 } },
{ 41.0, { -1088.0, 2416.0 }, { -832.0, 2544.0 } },
{ 41.0, { -1040.0, 2304.0 }, { -864.0, 2416.0 } },
{ 41.0, { -1024.0, 2144.0 }, { -864.0, 2304.0 } },
{ 41.0, { -604.0, 2036.0 }, { -484.0, 2060.0 } },
{ 41.0, { -1200.0, 2114.0 }, { -1072.0, 2242.0 } },
{ 41.0, { -976.0, 2016.0 }, { -848.0, 2144.0 } },
{ 41.0, { -1072.0, 2152.0 }, { -1024.0, 2264.0 } },
{ 41.0, { -700.0, 2272.0 }, { -484.0, 2320.0 } },
{ 41.0, { -608.0, 2320.0 }, { -528.0, 2352.0 } },
{ 41.0, { -816.0, 2060.0 }, { -496.0, 2144.0 } },
{ 41.0, { -1328.0, 2082.0 }, { -1200.0, 2210.0 } },
{ 41.0, { -1088.0, 2544.0 }, { -1040.0, 2800.0 } },
{ 41.0, { -1040.0, 2544.0 }, { -832.0, 2760.0 } },
{ 41.0, { -848.0, 2044.0 }, { -816.0, 2144.0 } },
{ 41.0, { -864.0, 2144.0 }, { -448.0, 2272.0 } },
{ 35.0, { -2522.0, -310.0 }, { -2382.0, -234.0 } },
{ 30.0, { -2048.0, -962.0 }, { -2004.0, -758.0 } },
{ 23.0, { 2248.0, -1182.0 }, { 2260.0, -1170.0 } },
{ 22.0, { 890.0, -1106.0 }, { 902.0, -1098.0 } },
{ 22.0, { 2292.0, -1432.0 }, { 2328.0, -1400.0 } },
{ 18.0, { 1928.0, -1222.0 }, { 2012.0, -1178.0 } },
{ 16.0, { 2564.0, 2370.0 }, { 2604.0, 2398.0 } },
{ 10.0, { 2058.0, 1868.0 }, { 2110.0, 1964.0 } },
{ 10.0, { 2090.0, 1670.0 }, { 2146.0, 1694.0 } },
{ 9.0, { 2506.0, 1546.0 }, { 2554.0, 1586.0 } },
{ 9.0, { 1202.0, -2414.0 }, { 1278.0, -2334.0 } },
{ 9.0, { 1888.0, 1468.0 }, { 2036.0, 1700.0 } },
{ 9.0, { 1836.0, 1468.0 }, { 1888.0, 1568.0 } },
{ 8.0, { 1744.0, 2780.0 }, { 1792.0, 2868.0 } },
{ 8.0, { 2110.0, 1234.0 }, { 2178.0, 1330.0 } },
{ 8.0, { 2108.0, 1084.0 }, { 2180.0, 1172.0 } },
{ 5.0, { -664.0, -1924.0 }, { -464.0, -1864.0 } },
{ 5.0, { -848.0, -2082.0 }, { -664.0, -1866.0 } },
{ 3.0, { -2778.0, -522.0 }, { -2662.0, -414.0 } },
{ 0.0, { -2000.0, -1536.0 }, { -1856.0, -1280.0 } },
{ 0.0, { -1856.0, -1648.0 }, { -1728.0, -1440.0 } },
{ 0.0, { -1728.0, -1728.0 }, { -1584.0, -1520.0 } },
{ 0.0, { -1360.0, -2052.0 }, { -1216.0, -1696.0 } },
{ 0.0, { -1440.0, -2110.0 }, { -1360.0, -1950.0 } },
{ 0.0, { -1484.0, -2180.0 }, { -1440.0, -2036.0 } },
{ 0.0, { -1572.0, -2352.0 }, { -1484.0, -2096.0 } },
{ 0.0, { -1216.0, -2208.0 }, { -1104.0, -1864.0 } },
{ 0.0, { -1232.0, -2304.0 }, { -1120.0, -2208.0 } },
{ 0.0, { -1270.0, -2480.0 }, { -1178.0, -2304.0 } },
{ 0.0, { -1260.0, -2560.0 }, { -1188.0, -2480.0 } },
{ 0.0, { -1262.0, -2640.0 }, { -1146.0, -2560.0 } },
{ 0.0, { -1216.0, -2752.0 }, { -1080.0, -2640.0 } },
{ 0.0, { -1200.0, -2896.0 }, { -928.0, -2752.0 } },
{ 0.0, { -2016.0, -3000.0 }, { -1520.0, -2704.0 } },
{ 0.0, { -1520.0, -3000.0 }, { -1376.0, -2894.0 } },
{ 0.0, { -2256.0, -3000.0 }, { -2016.0, -2772.0 } },
{ 0.0, { -2448.0, -3000.0 }, { -2256.0, -2704.0 } },
{ 0.0, { -3000.0, -3000.0 }, { -2448.0, -2704.0 } },
{ 0.0, { -3000.0, -2704.0 }, { -2516.0, -2576.0 } },
{ 0.0, { -3000.0, -2576.0 }, { -2600.0, -2448.0 } },
{ 0.0, { -3000.0, -2448.0 }, { -2628.0, -2144.0 } },
{ 0.0, { -3000.0, -2144.0 }, { -2670.0, -2032.0 } },
{ 0.0, { -3000.0, -2032.0 }, { -2802.0, -1904.0 } },
{ 0.0, { -3000.0, -1904.0 }, { -2920.0, -1376.0 } },
{ 0.0, { -3000.0, -1376.0 }, { -2936.0, -1186.0 } },
{ 0.0, { -768.0, 208.0 }, { -720.0, 672.0 } },
{ 0.0, { -720.0, 256.0 }, { -656.0, 672.0 } },
{ 0.0, { -656.0, 276.0 }, { -496.0, 576.0 } },
{ 0.0, { -496.0, 298.0 }, { -384.0, 566.0 } },
{ 0.0, { -384.0, 254.0 }, { -224.0, 530.0 } },
{ 0.0, { -224.0, 212.0 }, { -64.0, 528.0 } },
{ 0.0, { -64.0, 140.0 }, { 64.0, 544.0 } },
{ 0.0, { 64.0, 140.0 }, { 304.0, 544.0 } },
{ 0.0, { 120.0, 544.0 }, { 304.0, 648.0 } },
{ 0.0, { 304.0, 164.0 }, { 384.0, 608.0 } },
{ 0.0, { 384.0, 222.0 }, { 464.0, 630.0 } },
{ 0.0, { 464.0, 304.0 }, { 544.0, 656.0 } },
{ 0.0, { 544.0, 362.0 }, { 800.0, 646.0 } },
{ 0.0, { 800.0, 432.0 }, { 944.0, 704.0 } },
{ 0.0, { 944.0, 480.0 }, { 976.0, 720.0 } },
{ 0.0, { 976.0, 528.0 }, { 1040.0, 704.0 } },
{ 0.0, { 1040.0, 560.0 }, { 1280.0, 672.0 } },
{ 0.0, { 1280.0, 480.0 }, { 1472.0, 640.0 } },
{ 0.0, { 1472.0, 432.0 }, { 1616.0, 640.0 } },
{ 0.0, { 1616.0, 416.0 }, { 1824.0, 608.0 } },
{ 0.0, { 1824.0, 400.0 }, { 2160.0, 576.0 } },
{ 0.0, { 2160.0, 400.0 }, { 2432.0, 512.0 } },
{ 0.0, { 2432.0, 368.0 }, { 2560.0, 544.0 } },
{ 0.0, { 2560.0, 336.0 }, { 2720.0, 576.0 } },
{ 0.0, { 2720.0, 196.0 }, { 2816.0, 560.0 } },
{ 0.0, { 2816.0, 160.0 }, { 3000.0, 576.0 } },
{ 0.0, { 2860.0, -80.0 }, { 3000.0, 160.0 } },
{ 0.0, { -1376.0, -3000.0 }, { -544.0, -2896.0 } },
{ 0.0, { -928.0, -2896.0 }, { -544.0, -2800.0 } },
{ 0.0, { -544.0, -3000.0 }, { -320.0, -2824.0 } },
{ 0.0, { -320.0, -3000.0 }, { -192.0, -2876.0 } },
{ 0.0, { -192.0, -3000.0 }, { 160.0, -2920.0 } },
{ 0.0, { -128.0, -2920.0 }, { 160.0, -2872.0 } },
{ 0.0, { -60.0, -2872.0 }, { 160.0, -2816.0 } },
{ 0.0, { -4.0, -2816.0 }, { 160.0, -2672.0 } },
{ 0.0, { 40.0, -2672.0 }, { 160.0, -2256.0 } },
{ 0.0, { 16.0, -2560.0 }, { 40.0, -2256.0 } },
{ 0.0, { -32.0, -2440.0 }, { 16.0, -2256.0 } },
{ 0.0, { -32.0, -2488.0 }, { 16.0, -2440.0 } },
{ 0.0, { -96.0, -2440.0 }, { -32.0, -2256.0 } },
{ 0.0, { -168.0, -2384.0 }, { -96.0, -2256.0 } },
{ 0.0, { -224.0, -2256.0 }, { 160.0, -2080.0 } },
{ 0.0, { -248.0, -2080.0 }, { 160.0, -1968.0 } },
{ 0.0, { -280.0, -1968.0 }, { -128.0, -1824.0 } },
{ 0.0, { -264.0, -2016.0 }, { -248.0, -1968.0 } },
{ 0.0, { -264.0, -1824.0 }, { -128.0, -1640.0 } },
{ 0.0, { -128.0, -1768.0 }, { 124.0, -1648.0 } },
{ 0.0, { -128.0, -1792.0 }, { 140.0, -1768.0 } },
{ 0.0, { -128.0, -1968.0 }, { 148.0, -1792.0 } },
{ 0.0, { 160.0, -2128.0 }, { 592.0, -1976.0 } },
{ 0.0, { 480.0, -1976.0 }, { 592.0, -1896.0 } },
{ 0.0, { 352.0, -1976.0 }, { 480.0, -1896.0 } },
{ 0.0, { 232.0, -1976.0 }, { 352.0, -1880.0 } },
{ 0.0, { 160.0, -1976.0 }, { 232.0, -1872.0 } },
{ 0.0, { 160.0, -2784.0 }, { 592.0, -2128.0 } },
{ 0.0, { 160.0, -3000.0 }, { 592.0, -2784.0 } },
{ 0.0, { 352.0, -1896.0 }, { 544.0, -1864.0 } },
{ 0.0, { 592.0, -2112.0 }, { 976.0, -1896.0 } },
{ 0.0, { 736.0, -1896.0 }, { 904.0, -1864.0 } },
{ 0.0, { 704.0, -1896.0 }, { 736.0, -1728.0 } },
{ 0.0, { 736.0, -1864.0 }, { 752.0, -1728.0 } },
{ 0.0, { 688.0, -1728.0 }, { 752.0, -1480.0 } },
{ 0.0, { 592.0, -2192.0 }, { 976.0, -2112.0 } },
{ 0.0, { 592.0, -2328.0 }, { 1008.0, -2192.0 } },
{ 0.0, { 592.0, -3000.0 }, { 1008.0, -2328.0 } },
{ 0.0, { 1008.0, -3000.0 }, { 1072.0, -2368.0 } },
{ 0.0, { 1008.0, -2368.0 }, { 1064.0, -2320.0 } },
{ 0.0, { 1072.0, -2672.0 }, { 1288.0, -2412.0 } },
{ 0.0, { 1072.0, -2768.0 }, { 1288.0, -2672.0 } },
{ 0.0, { 1072.0, -3000.0 }, { 1288.0, -2768.0 } },
{ 0.0, { 1288.0, -3000.0 }, { 1448.0, -2760.0 } },
{ 0.0, { 1288.0, -2760.0 }, { 1392.0, -2688.0 } },
{ 0.0, { 1448.0, -3000.0 }, { 1720.0, -2754.0 } },
{ 0.0, { 1720.0, -3000.0 }, { 2064.0, -2740.0 } },
{ 0.0, { 2064.0, -3000.0 }, { 2144.0, -2742.0 } },
{ 0.0, { 2144.0, -3000.0 }, { 2208.0, -2700.0 } },
{ 0.0, { 2208.0, -3000.0 }, { 2272.0, -2684.0 } },
{ 0.0, { 2272.0, -3000.0 }, { 2376.0, -2312.0 } },
{ 0.0, { 2376.0, -2480.0 }, { 2472.0, -2240.0 } },
{ 0.0, { 2472.0, -2376.0 }, { 2776.0, -2240.0 } },
{ 0.0, { 2776.0, -2336.0 }, { 2856.0, -2192.0 } },
{ 0.0, { -2880.0, -1168.0 }, { -2768.0, -896.0 } },
{ 0.0, { 2856.0, -2336.0 }, { 3000.0, -2136.0 } },
{ 0.0, { 2888.0, -2136.0 }, { 3000.0, -1840.0 } },
{ 0.0, { 2872.0, -1880.0 }, { 2888.0, -1840.0 } },
{ 0.0, { 2864.0, -1840.0 }, { 3000.0, -1720.0 } },
{ 0.0, { 2888.0, -1720.0 }, { 3000.0, -1664.0 } },
{ 0.0, { 2896.0, -1664.0 }, { 3000.0, -1592.0 } },
{ 0.0, { 2920.0, -1592.0 }, { 3000.0, -1504.0 } },
{ 0.0, { 2940.0, -1504.0 }, { 3000.0, -1344.0 } },
{ 0.0, { 2908.0, -1344.0 }, { 3000.0, -1096.0 } },
{ 0.0, { 2912.0, -1096.0 }, { 3000.0, -800.0 } },
{ 0.0, { 2918.0, -800.0 }, { 3000.0, -472.0 } },
{ 0.0, { 2872.0, -472.0 }, { 3000.0, -376.0 } },
{ 0.0, { 2912.0, -376.0 }, { 3000.0, -80.0 } },
{ 0.0, { 2864.0, -376.0 }, { 2912.0, -80.0 } },
{ 0.0, { 2560.0, -2560.0 }, { 2680.0, -2456.0 } },
{ 0.0, { -992.0, -422.0 }, { -848.0, -238.0 } },
{ 0.0, { -848.0, -384.0 }, { -512.0, -256.0 } },
{ 0.0, { -512.0, -400.0 }, { -320.0, -272.0 } },
{ 0.0, { -320.0, -400.0 }, { -208.0, -304.0 } },
{ 0.0, { -384.0, -528.0 }, { -100.0, -460.0 } },
{ 0.0, { -384.0, -704.0 }, { -64.0, -528.0 } },
{ 0.0, { -336.0, -816.0 }, { -80.0, -704.0 } },
{ 0.0, { -208.0, -936.0 }, { -48.0, -816.0 } },
{ 0.0, { -48.0, -936.0 }, { 144.0, -874.0 } },
{ 0.0, { 32.0, -1024.0 }, { 128.0, -936.0 } },
{ 0.0, { -16.0, -1104.0 }, { 96.0, -1024.0 } },
{ 0.0, { 0.0, -1200.0 }, { 144.0, -1104.0 } },
{ 0.0, { -16.0, -1296.0 }, { 128.0, -1200.0 } },
{ 0.0, { -16.0, -1440.0 }, { 112.0, -1296.0 } },
{ 0.0, { 0.0, -1552.0 }, { 96.0, -1440.0 } },
{ 0.0, { -128.0, -1648.0 }, { 96.0, -1552.0 } },
{ 0.0, { -64.0, -672.0 }, { 32.0, -576.0 } },
{ 0.0, { -64.0, -576.0 }, { 96.0, -496.0 } },
{ 0.0, { 16.0, -496.0 }, { 144.0, -392.0 } },
{ 0.0, { 144.0, -448.0 }, { 240.0, -384.0 } },
{ 0.0, { 240.0, -432.0 }, { 304.0, -320.0 } },
{ 0.0, { 304.0, -384.0 }, { 352.0, -288.0 } },
{ 0.0, { 352.0, -332.0 }, { 400.0, -252.0 } },
{ 0.0, { 400.0, -298.0 }, { 464.0, -234.0 } },
{ 0.0, { 464.0, -288.0 }, { 576.0, -208.0 } },
{ 0.0, { 576.0, -272.0 }, { 688.0, -192.0 } },
{ 0.0, { 688.0, -256.0 }, { 768.0, -144.0 } },
{ 0.0, { 768.0, -212.0 }, { 800.0, -124.0 } },
{ 0.0, { 800.0, -180.0 }, { 976.0, -92.0 } },
{ 0.0, { 976.0, -160.0 }, { 1200.0, -64.0 } },
{ 0.0, { 1200.0, -244.0 }, { 1264.0, -108.0 } },
{ 0.0, { 1264.0, -330.0 }, { 1344.0, -158.0 } },
{ 0.0, { 1344.0, -320.0 }, { 1456.0, -208.0 } },
{ 0.0, { 1456.0, -282.0 }, { 1520.0, -198.0 } },
{ 0.0, { 1520.0, -208.0 }, { 1648.0, -80.0 } },
{ 0.0, { 1568.0, -80.0 }, { 1648.0, 16.0 } },
{ 0.0, { 1648.0, -64.0 }, { 1792.0, 16.0 } },
{ 0.0, { 1792.0, -128.0 }, { 1888.0, 0.0 } },
{ 0.0, { 1888.0, -268.0 }, { 2016.0, -20.0 } },
{ 0.0, { 2016.0, -256.0 }, { 2144.0, -16.0 } },
{ 0.0, { 2144.0, -272.0 }, { 2224.0, -96.0 } },
{ 0.0, { 2224.0, -272.0 }, { 2288.0, -144.0 } },
{ 0.0, { 2048.0, -16.0 }, { 2144.0, 112.0 } },
{ 0.0, { 2096.0, 112.0 }, { 2224.0, 240.0 } },
{ 0.0, { 2098.0, 240.0 }, { 2242.0, 400.0 } },
{ 0.0, { 2160.0, 512.0 }, { 2432.0, 576.0 } },
{ 0.0, { 2432.0, 544.0 }, { 2560.0, 592.0 } },
{ 0.0, { 2560.0, 576.0 }, { 2720.0, 608.0 } },
{ 0.0, { 2720.0, 560.0 }, { 2816.0, 608.0 } },
{ 0.0, { 2816.0, 576.0 }, { 3000.0, 752.0 } },
{ 0.0, { -656.0, 576.0 }, { -496.0, 672.0 } },
{ 0.0, { -740.0, 672.0 }, { -484.0, 784.0 } },
{ 0.0, { -720.0, 784.0 }, { -384.0, 1008.0 } },
{ 0.0, { -640.0, 1008.0 }, { -400.0, 1216.0 } },
{ 0.0, { -880.0, 1296.0 }, { -688.0, 1408.0 } },
{ 0.0, { -688.0, 1216.0 }, { -400.0, 1424.0 } },
{ 0.0, { -672.0, 1424.0 }, { -448.0, 1616.0 } },
{ 0.0, { -832.0, 1616.0 }, { -512.0, 1728.0 } },
{ 0.0, { -984.0, 1632.0 }, { -832.0, 1712.0 } },
{ 0.0, { -832.0, 1728.0 }, { -576.0, 2032.0 } },
{ 0.0, { -1584.0, -1826.0 }, { -1360.0, -1642.0 } },
{ 0.0, { -3000.0, 354.0 }, { -2832.0, 2942.0 } },
{ 0.0, { -2832.0, 1296.0 }, { -2704.0, 2192.0 } },
{ 0.0, { -2704.0, 1360.0 }, { -2240.0, 2224.0 } },
{ 0.0, { -2240.0, 1432.0 }, { -2000.0, 2224.0 } },
{ 0.0, { -2064.0, 1312.0 }, { -2000.0, 1432.0 } },
{ 0.0, { -2000.0, 1392.0 }, { -1712.0, 1792.0 } },
{ 0.0, { -2000.0, 1792.0 }, { -1724.0, 2016.0 } },
{ 0.0, { -2000.0, 2016.0 }, { -1836.0, 2176.0 } },
{ 0.0, { -2000.0, 2176.0 }, { -1920.0, 2224.0 } },
{ 0.0, { -2208.0, 2224.0 }, { -2000.0, 2432.0 } },
{ 0.0, { -2208.0, 2432.0 }, { -2000.0, 2576.0 } },
{ 0.0, { -2352.0, 2448.0 }, { -2208.0, 2576.0 } },
{ 0.0, { -2312.0, 2344.0 }, { -2208.0, 2448.0 } },
{ 0.0, { -1712.0, 1360.0 }, { -1600.0, 1792.0 } },
{ 0.0, { 2376.0, -3000.0 }, { 3000.0, -2688.0 } },
{ 0.0, { 2520.0, -2688.0 }, { 3000.0, -2560.0 } },
{ 0.0, { -1664.0, 1280.0 }, { -1600.0, 1360.0 } },
{ 0.0, { -1600.0, 1280.0 }, { -1440.0, 1696.0 } },
{ 0.0, { -1248.0, -144.0 }, { -992.0, 208.0 } },
{ 0.0, { -1176.0, -432.0 }, { -992.0, -144.0 } },
{ 0.0, { -1792.0, -592.0 }, { -1728.0, -144.0 } },
{ 0.0, { -1792.0, 170.0 }, { -1600.0, 274.0 } },
{ 0.0, { -1600.0, 168.0 }, { -1256.0, 208.0 } },
{ 0.0, { -1574.0, -44.0 }, { -1550.0, 108.0 } },
{ 0.0, { -1600.0, 1696.0 }, { -1488.0, 1744.0 } },
{ 0.0, { -464.0, -1908.0 }, { -280.0, -1832.0 } },
{ 0.0, { -1440.0, 1440.0 }, { -1232.0, 1696.0 } },
{ 0.0, { -1232.0, 1440.0 }, { -1136.0, 1616.0 } },
{ 0.0, { -1440.0, 1280.0 }, { -1136.0, 1440.0 } },
{ 0.0, { -1136.0, 1248.0 }, { -1104.0, 1424.0 } },
{ 0.0, { -1520.0, 1104.0 }, { -1104.0, 1248.0 } },
{ 0.0, { -1520.0, 1248.0 }, { -1136.0, 1280.0 } },
{ 0.0, { -1600.0, 1200.0 }, { -1520.0, 1280.0 } },
{ 0.0, { -1104.0, 944.0 }, { -932.0, 1136.0 } },
{ 0.0, { -1424.0, 944.0 }, { -1104.0, 1104.0 } },
{ 0.0, { -1520.0, 1008.0 }, { -1424.0, 1104.0 } },
{ 0.0, { 2808.0, -2560.0 }, { 3000.0, -2336.0 } },
{ 0.0, { -1424.0, 784.0 }, { -896.0, 944.0 } },
{ 0.0, { -1488.0, 560.0 }, { -896.0, 784.0 } },
{ 0.0, { -1536.0, 560.0 }, { -1488.0, 672.0 } },
{ 0.0, { -2832.0, 2888.0 }, { 3000.0, 3000.0 } },
{ 0.0, { -896.0, 208.0 }, { -768.0, 732.0 } },
{ 0.0, { 1520.0, -252.0 }, { 1572.0, -208.0 } },
{ 0.0, { 2922.0, 752.0 }, { 3000.0, 2888.0 } },
{ 0.0, { -3000.0, -446.0 }, { -2910.0, 354.0 } },
{ 0.0, { -2434.0, 2224.0 }, { -2294.0, 2340.0 } },
{ 0.0, { -2294.0, 2224.0 }, { -2208.0, 2312.0 } },
{ 0.0, { -1600.0, 208.0 }, { -896.0, 560.0 } },
{ 0.0, { -3000.0, 2942.0 }, { -2832.0, 3000.0 } },
{ 0.0, { -992.0, -144.0 }, { -912.0, 208.0 } },
{ 0.0, { -896.0, 842.0 }, { -776.0, 954.0 } },
{ 0.0, { -2240.0, 1336.0 }, { -2088.0, 1432.0 } },
{ 0.0, { -3000.0, -822.0 }, { -2930.0, -446.0 } },
{ 0.0, { -2660.0, 2224.0 }, { -2520.0, 2264.0 } },
{ 0.0, { -378.0, -460.0 }, { -138.0, -400.0 } },
{ 0.0, { -1748.0, -816.0 }, { -1180.0, -592.0 } },
{ 0.0, { -1458.0, -592.0 }, { -1054.0, -432.0 } },
{ 0.0, { -3000.0, -1186.0 }, { -2880.0, -822.0 } },
{ 0.0, { 1072.0, -2412.0 }, { 1128.0, -2372.0 } },
{ 0.0, { -2768.0, -1106.0 }, { -2656.0, -830.0 } },
{ 0.0, { -2656.0, -1024.0 }, { -2512.0, -816.0 } },
{ 0.0, { -1484.0, 784.0 }, { -1424.0, 840.0 } },
{ 0.0, { -496.0, 566.0 }, { -432.0, 642.0 } },
{ 0.0, { 250.0, 2808.0 }, { 818.0, 2888.0 } },
{ 0.0, { 2502.0, -2240.0 }, { 2670.0, -2120.0 } },
{ 0.0, { -2512.0, -976.0 }, { -2400.0, -816.0 } },
{ 0.0, { 88.0, 544.0 }, { 120.0, 572.0 } },
{ 0.0, { 1856.0, -202.0 }, { 1888.0, -158.0 } },
{ 0.0, { -2400.0, -1056.0 }, { -2256.0, -864.0 } },
{ 0.0, { -2256.0, -1198.0 }, { -2144.0, -950.0 } },
{ 0.0, { -2144.0, -1408.0 }, { -2000.0, -1072.0 } },
{ 0.0, { 2872.0, -2136.0 }, { 2888.0, -2120.0 } },
{ 0.0, { 2760.0, -2240.0 }, { 2776.0, -2232 } }
};
using namespace sampgdk;
// And an array containing the native function-names and the functions
// specified with them.
AMX_NATIVE_INFO natives[ ] =
{
{ "MPGetVehicleDriver", nat_MPGetVehicleDriver },
{ "MPGetVehicleDriverCount", nat_MPGetVehicleDriverCount },
{ "MPGetPlayerVehicleOtherDriver", nat_MPGetPlayerVehicleOtherDriver },
{ "MPGetVehicleOccupantCnt", nat_MPGetVehicleOccupantCnt },
{ "MPGetVehicleOccupantOtherTeam", nat_MPGetVehicleNonDriverTeamOccupants },
{ "MPGetVehicleSurfersCnt", nat_MPGetVehicleSurfersCnt},
{ "MPCrossProduct", nat_MPCrossProduct },
{ "MPDotProduct", nat_MPDotProduct },
{ "MPDistanceCameraToLocation", nat_MPDistanceCameraTargetToLocation },
{ "MPProjectPointOnVehicle", nat_MPProjectPointOnVehicle},
{ "MPProjectPointOnPlayer", nat_MPProjectPointOnPlayer},
{ "MPProjectPointXYZA", nat_MPProjectPointXYZA},
{ "MPGetAimTarget", nat_MPGetAimTarget },
{ "MPDistancePointLine", nat_MPDistancePointLine },
{ "MPInterpolatePoint", nat_MPInterpolatePoint},
{ "MPDistance", nat_MPDistance },
{ "MPFDistance", nat_MPFDistance },
{ "MPFSQRT", nat_MPFSQRT },
{ "MPFloatIsFinite", nat_MPFloatIsFinite },
{ "MPReturnInf", nat_returninf },
{ "MPReturnNan", nat_returnnan },
{ "MPFiniteFloat", nat_normalizefloat },
{ "MPClamp360", nat_MPClamp360 },
{ "MPFNormalize", nat_MPFNormalize },
{ "MPGetVehicleUpsideDown", nat_MPGetVehicleUpsideDown },
{ "MPGetTrailerTowingVehicle", nat_MPGetTrailerTowingVehicle },
{ "MPVecLength", nat_MPVecLength },
{ "MPFVecLength", nat_MPFVecLength },
{ "MPInRange", nat_MPWithinRange },
{ "MPPtInRect2D", nat_MPPtInRect2D },
{ "MPPtInRect3D", nat_MPPtInRect3D },
{ "IsBitSet", nat_IsBitSet },
{ "BitToOn", nat_BitToOn },
{ "BitToOff", nat_BitToOff },
{ "UtilGetWaterZlevel", nat_UtilGetWaterZlevel },
{ "UtilGetPlayerIdleTime", nat_GetPlayerIdleTime },
{ "UtilGetPlayerAbsentTime", nat_GetPlayerTimeSinceUpdate },
// ticks related
{ "GetTimeDistanceMs", nat_GetTimeDistance },
{ "GetTimeMs", nat_GetTimeMs },
{ 0, 0 }
};
#ifndef NO_EVENT_HANDLER
static samputils theGameMode;
samputils::samputils() {
// Register our gamemode in order to catch events - if we don't do this
// somewhere none of the HelloWorld callbacks will be ever called.
this->Register();
}
samputils::~samputils() {}
/*
int samputils::getidletime(int playerid) {
return samputils::lastplayerinput[playerid];
}
*/
#endif
// i got this from blueg's plugin, no idea who wrote this originally
std::string GetString(AMX* amx,cell param)
{
cell *pString;
char *szDest;
int nLen;
amx_GetAddr(amx,param,&pString);
amx_StrLen(pString, &nLen);
szDest = new char[nLen+1];
amx_GetString(szDest, pString, 0, UNLIMITED);
szDest[nLen] = '\0';
std::string szReturn(szDest);
delete szDest;
return szReturn;
}
float refcell2float(AMX* amx, cell param) {
cell* padd;
amx_GetAddr(amx, param, &padd);
cell value = *padd;
return amx_ctof(value);
}
// google 0x5f3759df
float FastSqrt(float number) {
long i;
float x, y;
const float f = 1.5F;
x = number * 0.5F;
y = number;
i = * ( long * ) &y;
i = 0x5f3759df - ( i >> 1 );
y = * ( float * ) &i;
y = y * ( f - ( x * y * y ) );
y = y * ( f - ( x * y * y ) );
return number * y;
}
void Normalize(float &vx, float &vy, float &vz) {
float Length;
Length = 1 /FastSqrt(vx * vx + vy * vy + vz * vz);
vx = vx * Length;
vy = vy * Length;
vz = vz * Length;
}
int GetPlayerVehicleOtherDriver(int playerid) {
if (playerid == INVALID_PLAYER_ID)
return INVALID_PLAYER_ID;
int vehicleid = GetPlayerVehicleID(playerid);
if ((!IsValidVehicle(vehicleid)) || (vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
return INVALID_PLAYER_ID; // not possible to find any vehicle, so there is no "other" driver.
int i;
for (i = 0; i < MAX_PLAYERS; i++) {
if ((IsPlayerConnected(i) == false) || (playerid == i)) // no connected player in slot or this is same player?
continue;
if (GetPlayerState(i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle?
int thisplayervehid = GetPlayerVehicleID(i);
if (!IsVehicleStreamedIn(thisplayervehid, i)) // so players who are in wrong virtual world (like a pause sysstem would do) are not returned as drivers anymore.
continue;
// todo: maybe use IsPlayerInVehicle instead.
if (thisplayervehid == vehicleid) // found a connected driver in this car.
return i;
}
return INVALID_PLAYER_ID;
}
int GetTrailerTowingVehicle(int trailerid) {
if ((trailerid == 0) || (trailerid == INVALID_VEHICLE_ID) || (trailerid > MAX_VEHICLES))
return INVALID_PLAYER_ID;
int i;
for (i = 0; i < MAX_VEHICLES; i++) {
if (GetVehicleModel(i) == 0) // invalid vehicle.
continue;
if (GetVehicleTrailer(i) == trailerid)
return i;
}
return INVALID_VEHICLE_ID; // found no driver.
}
int GetVehicleDriver(int vehicleid) {
if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
return INVALID_PLAYER_ID;
int i;
for (i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i) == false) // no connected player in slot?
continue;
if (GetPlayerState(i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle?
int thisplayervehid = GetPlayerVehicleID(i);
if (!IsVehicleStreamedIn(thisplayervehid, i)) // so players who are in wrong virtual world (like a pause sysstem would do) are not returned as drivers anymore.
continue;
// todo: maybe use IsPlayerInVehicle instead.
if (thisplayervehid == vehicleid) // found a connected driver in this car.
return i;
}
return INVALID_PLAYER_ID; // found no driver.
}
SCRIPT_NATIVE nat_MPGetVehicleDriver(AMX* amx, cell* params) {
int vehicleid;
CHECK_PARAM_COUNT(nat_MPGetVehicleDriver, 1);
vehicleid = (int)params[1];
return GetVehicleDriver(vehicleid);
}
SCRIPT_NATIVE nat_MPGetTrailerTowingVehicle(AMX* amx, cell* params) {
int vehicleid;
CHECK_PARAM_COUNT(nat_MPGetTrailerTowingVehicle, 1);
vehicleid = (int)params[1];
return GetTrailerTowingVehicle(vehicleid);
}
SCRIPT_NATIVE nat_MPGetPlayerVehicleOtherDriver(AMX* amx, cell* params) {
int playerid;
CHECK_PARAM_COUNT(nat_MPGetPlayerVehicleOtherDriver, 1);
playerid = (int)params[1];
return GetPlayerVehicleOtherDriver(playerid);
}
int GetVehicleDriverCount(int vehicleid) {
if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
return INVALID_PLAYER_ID;
int i;
int totaldrivers = 0;
for (i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i) == false) // no connected player in slot?
continue;
if (GetPlayerState(i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle?
int thisplayervehid = GetPlayerVehicleID(i);
if (!IsVehicleStreamedIn(thisplayervehid, i)) // so players who are in wrong virtual world (like a pause sysstem would do) are not returned as drivers anymore.
continue;
if (thisplayervehid == vehicleid) // found a connected driver in this car.
totaldrivers++;
}
return totaldrivers; // return how many there are.
}
int GetVehicleOccupantCnt(int vehicleid) {
if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
return INVALID_PLAYER_ID;
int i;
int totalocc = 0;
for (i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i) == false) // no connected player in slot?
continue;
if (GetPlayerVirtualWorld(i) != GetVehicleVirtualWorld(vehicleid)) // solves specific issues if you put paused players into separate virtual world.
continue;
int thisplayervehid = GetPlayerVehicleID(i);
if (!IsVehicleStreamedIn(thisplayervehid, i)) // so players who are in wrong virtual world (like a pause sysstem would do) are not returned as drivers anymore.
continue;
if (thisplayervehid == vehicleid) // found a connected player in this car.
totalocc++;
}
return totalocc; // return how many there are.
}
void ProjectPointXYZA(
float origin_x, float origin_y, float origin_z, float playerheading,
float incoords_x, float incoords_y, float incoords_z, float &outx, float &outy, float &outz) {
float originalangle;
originalangle = atan2(incoords_x, incoords_y) * 180.0 / PI;
float originaldistance;
originaldistance = FastSqrt(incoords_x * incoords_x + incoords_y * incoords_y);
originalangle -= playerheading;
// *PI/180 = degtorad
outx = origin_x + sin(originalangle * PI/180.0) * originaldistance;
outy = origin_y + cos(originalangle * PI/180.0) * originaldistance;
outz = incoords_z + origin_z; // nothing magical on Z!
}
void ProjectPointOnPlayer(int PlayerID, float incoords_x, float incoords_y, float incoords_z, float &outx, float &outy, float &outz) {
float playerpos[3];
float playerheading;
GetPlayerPos(PlayerID, &playerpos[0], &playerpos[1], &playerpos[2]);
GetPlayerFacingAngle(PlayerID, &playerheading);
float originalangle;
originalangle = atan2(incoords_x, incoords_y) * 180 / PI;
float originaldistance;
originaldistance = FastSqrt(incoords_x * incoords_x + incoords_y * incoords_y);
originalangle -= playerheading;
// *PI/180 = degtorad
outx = playerpos[0] + sin(originalangle * PI/180) * originaldistance;
outy = playerpos[1] + cos(originalangle * PI/180) * originaldistance;
outz = incoords_z + playerpos[2]; // nothing magical on Z!
}
int GetVehicleSurfersCnt(int vehicleid) {
if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
return INVALID_PLAYER_ID;
int i;
int totalocc = 0;
for (i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i) == false) // no connected player in slot?
continue;
if (GetPlayerVirtualWorld(i) != GetVehicleVirtualWorld(vehicleid)) // solves specific issues if you put paused players into separate virtual world.
continue;
int thisplayervehid;
thisplayervehid = GetPlayerSurfingVehicleID(i);
if (thisplayervehid == vehicleid) // found a connected player in this car.
totalocc++;
}
return totalocc; // return how many there are.
}
SCRIPT_NATIVE nat_MPGetVehicleDriverCount(AMX* amx, cell* params) {
int vehicleid;
CHECK_PARAM_COUNT(nat_MPGetVehicleDriverCount, 1);
vehicleid = (int)params[1];
return GetVehicleDriverCount(vehicleid);
}
int GetVehicleOccupantEnemyTeam(int vehicleid) {
if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES))
return INVALID_PLAYER_ID;
int i;
int totalocc = 0;
int cardriver = GetVehicleDriver(vehicleid);
if (cardriver == INVALID_PLAYER_ID)
return INVALID_PLAYER_ID; // no driver - no enemy drivers.
for (i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i) == false) // no connected player in slot?
continue;
if (GetPlayerVirtualWorld(i) != GetVehicleVirtualWorld(vehicleid)) // solves specific issues if you put paused players into separate virtual world.
continue;
int thisplayervehid = GetPlayerVehicleID(i);
if (!IsVehicleStreamedIn(thisplayervehid, i)) // so players who are in wrong virtual world (like a pause sysstem would do) are not returned as drivers anymore.
continue;
if (GetPlayerTeam(i) == GetPlayerTeam(cardriver)) // same team.. this one is ok.
continue;
if (thisplayervehid == vehicleid) // found a connected player in this car.
return i;
}
return INVALID_PLAYER_ID; // return first enemy player found
}
SCRIPT_NATIVE nat_MPGetVehicleNonDriverTeamOccupants(AMX* amx, cell* params) {
int vehicleid;
CHECK_PARAM_COUNT(nat_MPGetVehicleNonDriverTeamOccupants, 1);
vehicleid = (int)params[1];
return GetVehicleOccupantEnemyTeam(vehicleid);
}
SCRIPT_NATIVE nat_MPGetVehicleOccupantCnt(AMX* amx, cell* params) {
int vehicleid;
CHECK_PARAM_COUNT(nat_MPGetVehicleOccupantCnt, 1);
vehicleid = (int)params[1];
return GetVehicleOccupantCnt(vehicleid);
}
SCRIPT_NATIVE nat_MPGetVehicleSurfersCnt(AMX* amx, cell* params) {
int vehicleid;
CHECK_PARAM_COUNT(nat_MPGetVehicleSurfersCnt, 1);
vehicleid = (int)params[1];
return GetVehicleSurfersCnt(vehicleid);
}
void MPCrossProduct(float v1[3], float v2[3], float &resx, float &resy, float &resz) {
resx = (v1[1]*v2[2]) - (v1[2]*v2[1]);
resy = (v1[2]*v2[0]) - (v1[0]*v2[2]);
resz = (v1[0]*v2[1]) - (v1[1]*v2[0]);
}
SCRIPT_NATIVE nat_MPCrossProduct(AMX* amx, cell* params) {
CHECK_PARAM_COUNT(nat_MPCrossProduct, 9);
float v1[3];
float v2[3];
float resx, resy, resz;
v1[0] = amx_ctof(params[1]);
v1[1] = amx_ctof(params[2]);
v1[2] = amx_ctof(params[3]);
v2[0] = amx_ctof(params[4]);
v2[1] = amx_ctof(params[5]);
v2[2] = amx_ctof(params[6]);
MPCrossProduct(v1, v2, resx, resy, resz);;
cell* padd;
amx_GetAddr(amx, params[7], &padd);
*padd = amx_ftoc(resx);
amx_GetAddr(amx, params[8], &padd);
*padd = amx_ftoc(resy);
amx_GetAddr(amx, params[9], &padd);
*padd = amx_ftoc(resz);
return 1;
}
float DotProduct(float AX, float AY, float AZ, float BX, float BY, float BZ) {
return AX * BX + AY * BY + AZ * BZ;
}
SCRIPT_NATIVE nat_MPDotProduct(AMX* amx, cell* params) {
CHECK_PARAM_COUNT(nat_MPDotProduct, 6);
float ret = DotProduct(amx_ctof(params[1]), amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]), amx_ctof(params[5]), amx_ctof(params[6]));
return amx_ftoc(ret);
}
float DistanceCameraTargetToLocation(float CamX, float CamY, float CamZ, float ObjX, float ObjY, float ObjZ, float FrX, float FrY, float FrZ) {
float TGTDistance;
// get distance from camera to target
TGTDistance = sqrt((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
float tmpX, tmpY, tmpZ;
tmpX = FrX * TGTDistance + CamX;
tmpY = FrY * TGTDistance + CamY;
tmpZ = FrZ * TGTDistance + CamZ;
return sqrt((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
SCRIPT_NATIVE nat_MPDistanceCameraTargetToLocation(AMX* amx, cell* params) {
CHECK_PARAM_COUNT(nat_MPDistanceCameraTargetToLocation, 9);
float resdist = DistanceCameraTargetToLocation(amx_ctof(params[1]), amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]), amx_ctof(params[5]), amx_ctof(params[6]), amx_ctof(params[7]), amx_ctof(params[8]), amx_ctof(params[9]));
return amx_ftoc(resdist);
}
// transforms a vector using a 4x4 matrix (translation and scaling is ignored, only 3x3 part is used, we only need rotation!)
void MatrixTransformVector(float vector[3], float m[4][4], float &resx, float &resy, float &resz) {
resz = vector[2] * m[0][0] + vector[1] * m[0][1] + vector[0] * m[0][2] + m[0][3];
resy = vector[2] * m[1][0] + vector[1] * m[1][1] + vector[0] * m[1][2] + m[1][3];
resx = -(vector[2] * m[2][0] + vector[1] * m[2][1] + vector[0] * m[2][2] + m[2][3]); // don't ask why -x was needed, i don't know either.
}
void MPProjectPointOnVehicle(int vehid, float Invector[3], float &resx, float &resy, float &resz, int worldspace) {
float Quaternion[4];
float transformationmatrix[4][4];
// to native!
GetVehicleRotationQuat(vehid, &Quaternion[0], &Quaternion[1], &Quaternion[2], &Quaternion[3]);
// build a transformation matrix out of the quaternion
float xx = Quaternion[0] * Quaternion[0];
float xy = Quaternion[0] * Quaternion[1];
float xz = Quaternion[0] * Quaternion[2];
float xw = Quaternion[0] * Quaternion[3];
float yy = Quaternion[1] * Quaternion[1];
float yz = Quaternion[1] * Quaternion[2];
float yw = Quaternion[1] * Quaternion[3];
float zz = Quaternion[2] * Quaternion[2];
float zw = Quaternion[2] * Quaternion[3];
transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
transformationmatrix[0][1] = 2 * ( xy - zw );
transformationmatrix[0][2] = 2 * ( xz + yw );
transformationmatrix[0][3] = 0.0;
transformationmatrix[1][0] = 2 * ( xy + zw );
transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
transformationmatrix[1][2] = 2 * ( yz - xw );
transformationmatrix[1][3] = 0.0;
transformationmatrix[2][0] = 2 * ( xz - yw );
transformationmatrix[2][1] = 2 * ( yz + xw );
transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
transformationmatrix[2][3] = 0;
transformationmatrix[3][0] = 0;
transformationmatrix[3][1] = 0;
transformationmatrix[3][2] = 0;
transformationmatrix[3][3] = 1;
// transform the point thru car's rotation
MatrixTransformVector(Invector, transformationmatrix, resx, resy, resz);
// if worldspace is set it'll return the coords in global space - useful to check tire coords against tire spike proximity directly, etc..
if (worldspace == 1) {
float fX, fY, fZ;
GetVehiclePos(vehid, &fX, &fY, &fZ);
resx += fX;
resy += fY;
resz += fZ;
}
}
float Distance(float fPos1x, float fPos1y, float fPos1z, float fPos2x, float fPos2y, float fPos2z) {
return sqrt((fPos1x - fPos2x) * (fPos1x - fPos2x) + (fPos1y - fPos2y) * (fPos1y - fPos2y) + (fPos1z - fPos2z) * (fPos1z - fPos2z));
}
float FDistance(float fPos1x, float fPos1y, float fPos1z, float fPos2x, float fPos2y, float fPos2z) {
return FastSqrt((fPos1x - fPos2x) * (fPos1x - fPos2x) + (fPos1y - fPos2y) * (fPos1y - fPos2y) + (fPos1z - fPos2z) * (fPos1z - fPos2z));
}
SCRIPT_NATIVE nat_MPDistance(AMX* amx, cell* params) {
CHECK_PARAM_COUNT(nat_MPDistance, 6);
float tmpret;
tmpret = Distance(amx_ctof(params[1]), amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4]), amx_ctof(params[5]), amx_ctof(params[6]));
return amx_ftoc(tmpret);
}
SCRIPT_NATIVE nat_MPFloatIsFinite(AMX* amx, cell* params) {
CHECK_PARAM_COUNT(nat_MPFloatIsFinite, 1);
float tmpret;
tmpret = amx_ctof(params[1]);
return isfinite(tmpret);
}
SCRIPT_NATIVE nat_returninf(AMX* amx, cell* params) {
float tmpret;
if (params[1] == 1)
tmpret = INFINITY;
else
tmpret = -INFINITY;
return amx_ftoc(tmpret);
}
SCRIPT_NATIVE nat_returnnan(AMX* amx, cell* params) {
float tmpret;
if (params[1] == 1)
tmpret = NAN;
else
tmpret = -NAN;
return amx_ftoc(tmpret);
}
SCRIPT_NATIVE nat_normalizefloat(AMX* amx, cell* params) {
CHECK_PARAM_COUNT(nat_normalizefloat, 2);
float tmpret;
tmpret = amx_ctof(params[1]);
if (!isfinite(tmpret))
tmpret = amx_ctof(params[2]);
return amx_ftoc(tmpret);