-
Notifications
You must be signed in to change notification settings - Fork 12
/
World.ts
1022 lines (945 loc) · 26.5 KB
/
World.ts
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
import { Entity, Model, Prop } from './';
import { Blip } from './Blip';
import { Camera } from './Camera';
import { CloudHat, IntersectOptions, MarkerType, Weather } from './enums';
import { CameraTypes } from './enums/CameraTypes';
import { PickupType } from './enums/PickupType';
import { VehicleHash } from './hashes';
import { Ped, Vehicle } from './models';
import { Pickup } from './Pickup';
import { RaycastResult } from './Raycast';
import { Color, Maths, Vector3 } from './utils';
/**
* Class with common world manipulations.
*
* This class includes methods for creating entities and common world rendering.
*
* You can create blips, entities, cameras and more.
*
* @abstract
*/
export abstract class World {
/**
* Get the current camera that's rendering.
*
* @returns The camera that's currently used.
*/
public static get RenderingCamera(): Camera {
return new Camera(GetRenderingCam());
}
/**
* Set the rendering camera. World.RenderingCamera = null to reset.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const myCamera = World.createCamera(position, new Vector3(0,0,0), 180);
* World.RenderingCamera = myCamera;
*
* // Reset to default cam
* World.RenderingCamera = null;
* ```
*
* @param value The camera to render.
*/
public static set RenderingCamera(value: Camera | null) {
if (value === null) {
RenderScriptCams(false, false, 3000, true, false);
} else {
value.IsActive = true;
RenderScriptCams(true, false, 3000, true, false);
}
}
/**
* Get the current date in the world.
*
* @returns The current date.
*/
public static get CurrentDate(): Date {
const year = GetClockYear();
const month = GetClockMonth();
const day = GetClockDayOfMonth();
const hour = GetClockHours();
const minutes = GetClockMinutes();
const seconds = GetClockSeconds();
return new Date(year, month, day, hour, minutes, seconds);
}
/**
* Set the current date of the world.
*/
public static set CurrentDate(date: Date) {
SetClockDate(date.getDate(), date.getMonth(), date.getFullYear());
NetworkOverrideClockTime(date.getHours(), date.getMinutes(), date.getSeconds());
}
/**
* Disables all emissive textures, street/building/vehicle lights. "EMP" effect.
*
* @param value On or off.
*/
public static set Blackout(value: boolean) {
SetBlackout(value);
}
/**
* Get the current cloud hat.
*
* @returns The current cloud hat type.
*/
public static get CloudHat(): CloudHat {
return this.currentCloudHat;
}
/**
* Set the current cloud hat.
*
* @param value The type of cloud hat.
*/
public static set CloudHat(value: CloudHat) {
this.currentCloudHat = value;
if (this.currentCloudHat === CloudHat.Unknown) {
this.currentCloudHat = CloudHat.Clear;
ClearCloudHat();
return;
}
SetCloudHatTransition(this.cloudHatDict.get(this.currentCloudHat) ?? '', 3);
}
/**
* Get the opacity of current cloud hat. Value is between 0-1.
*
* @returns The current cloud opacity between 0.0 and 1.0
*/
public static get CloudHatOpacity(): number {
return GetCloudHatOpacity();
}
/**
* Set opacity of current cloud hat between 0-1.
*
* @param value Opacity between 0.0 and 1.0
*/
public static set CloudHatOpacity(value: number) {
SetCloudHatOpacity(Maths.clamp(value, 0, 1));
}
/**
* Get the current weather type.
*
* @returns The current type of weather.
*/
public static get Weather(): Weather {
switch (GetPrevWeatherTypeHashName()) {
case -1750463879:
return Weather.ExtraSunny;
case 916995460:
return Weather.Clear;
case -1530260698:
return Weather.Neutral;
case 282916021:
return Weather.Smog;
case -1368164796:
return Weather.Foggy;
case 821931868:
return Weather.Clouds;
case -1148613331:
return Weather.Overcast;
case 1840358669:
return Weather.Clearing;
case 1420204096:
return Weather.Raining;
case -1233681761:
return Weather.ThunderStorm;
case 669657108:
return Weather.Blizzard;
case -273223690:
return Weather.Snowing;
case 603685163:
return Weather.Snowlight;
case -1429616491:
return Weather.Christmas;
case -921030142:
return Weather.Halloween;
default:
return Weather.Unknown;
}
}
/**
* Set the current weather.
*
* @param value Type of weather to set.
*/
public static set Weather(value: Weather) {
if (value !== Weather.Unknown) {
const weather = this.weatherDict[value];
SetWeatherTypeOverTime(weather, 1);
setTimeout(() => {
SetWeatherTypeNow(weather);
}, 100);
}
}
/**
* Get the next weather type.
*
* @returns The Weather type
*/
public static get NextWeather(): Weather {
switch (GetNextWeatherTypeHashName()) {
case -1750463879:
return Weather.ExtraSunny;
case 916995460:
return Weather.Clear;
case -1530260698:
return Weather.Neutral;
case 282916021:
return Weather.Smog;
case -1368164796:
return Weather.Foggy;
case 821931868:
return Weather.Clouds;
case -1148613331:
return Weather.Overcast;
case 1840358669:
return Weather.Clearing;
case 1420204096:
return Weather.Raining;
case -1233681761:
return Weather.ThunderStorm;
case 669657108:
return Weather.Blizzard;
case -273223690:
return Weather.Snowing;
case 603685163:
return Weather.Snowlight;
case -1429616491:
return Weather.Christmas;
case -921030142:
return Weather.Halloween;
default:
return Weather.Unknown;
}
}
/**
* Set weather type instantly. Similar to World.transitionToWeather with duration 0.
*/
public static set NextWeather(value: Weather) {
if (value !== Weather.Unknown) {
const weather = this.weatherDict[value];
SetWeatherTypeOverTime(weather, 0);
}
}
/**
* Doesn't work
*/
public static get WeatherTransition(): [string | Weather, string | Weather, number] {
const transition = GetWeatherTypeTransition();
return [this.weatherDict[transition[0]], this.weatherDict[transition[1]], transition[2]];
}
/**
* Doesn't work
*/
public static set WeatherTransition(transition: [string | Weather, string | Weather, number]) {
SetWeatherTypeTransition(transition[0], transition[1], transition[2]);
}
/**
* Transition to different weather type within a certain time.
*
* @param weather Weather type to change to.
* @param duration Time for full weather change (in milliseconds);
*/
public static transitionToWeather(weather: Weather, duration: number): void {
if (weather !== Weather.Unknown) {
SetWeatherTypeOverTime(this.weatherDict[weather], duration);
}
}
/**
* Destroys all existing cameras and sets your rendering camera back to GameplayCam.
*/
public static destroyAllCameras(): void {
DestroyAllCams(false);
}
/**
* Creates a blip at a given position and optionally radius.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const myStoreBlip = World.createBlip(position, 5.0);
* myStoreBlip.Sprite = BlipSprite.Store;
* ```
*
* @param position World coordinate of blip.
* @param radius (Optional) Radius of where blip should be shown.
* @returns Blip object.
*/
public static createBlip(position: Vector3, radius?: number): Blip {
if (radius !== null && radius !== undefined) {
return new Blip(AddBlipForRadius(position.x, position.y, position.z, radius));
}
return new Blip(AddBlipForCoord(position.x, position.y, position.z));
}
/**
* Creates a cam that defaults to {@link CameraTypes.Scripted}
*
* ```ts
* const cam = World.createCamera(CameraTypes.Spline, true);
* ```
* @param camerType the camera type to create
* @param active unknown
* @returns
*/
public static createCamera(cameraType = CameraTypes.Scripted, active = true): Camera {
return new Camera(CreateCam(cameraType, active));
}
/**
* Creates a camera using 'DEFAULT_SCRIPTED_CAMERA'.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const myCamera = World.createCameraWithParams(position, new Vector3(0,0,0), 180);
* ```
*
* @param position World coordinate where the camera should render.
* @param rotation Rotation of camera relative to world.
* @param fieldOfView Field of view angle of camera.
* @returns Camera object.
*/
public static createCameraWithParams(
cameraType = CameraTypes.Scripted,
position: Vector3,
rotation: Vector3,
fieldOfView: number,
): Camera {
return new Camera(
CreateCamWithParams(
cameraType,
position.x,
position.y,
position.z,
rotation.x,
rotation.y,
rotation.z,
fieldOfView,
true,
2,
),
);
}
/**
* Create a ped at a desired location.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const model = new Model("a_f_m_beach_01");
* const myPed = await World.createPed(model, position);
* ```
*
* @param model Ped model to be spawned.
* @param position World position (coordinates) of Ped spawn.
* @param heading Heading of Ped when spawning.
* @param isNetwork
* @returns Ped object.
*/
public static async createPed(
model: Model,
position: Vector3,
heading = 0,
isNetwork = true,
): Promise<Ped | null> {
if (!model.IsPed || !(await model.request(1000))) {
return null;
}
return new Ped(
CreatePed(26, model.Hash, position.x, position.y, position.z, heading, isNetwork, false),
);
}
/**
* Creates a [[`Ped`]] with a random model.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const randomPed = World.createRandomPed(position);
* ```
*
* @param position World coordinate of Ped spawn.
* @returns Ped object.
*/
public static createRandomPed(position: Vector3): Ped {
return new Ped(CreateRandomPed(position.x, position.y, position.z));
}
/**
* Create a vehicle at a desired location.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const model = new Model("adder");
* const myVehicle = await World.createVehicle(model, position);
* ```
*
* @param model Vehicle model to be spawned.
* @param position World position (coordinates) of Vehicle spawn.
* @param heading Heading of Vehicle when spawning.
* @param isNetwork
* @returns Vehicle object.
*/
public static async createVehicle(
model: Model,
position: Vector3,
heading = 0,
isNetwork = true,
): Promise<Vehicle | null> {
if (!model.IsVehicle || !(await model.request(1000))) {
return null;
}
return new Vehicle(
CreateVehicle(model.Hash, position.x, position.y, position.z, heading, isNetwork, false),
);
}
/**
* Create a random vehicle at a desired location.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const randomVehicle = await World.createRandomVehicle(position);
* ```
*
* @param position World position (coordinates) of Vehicle spawn.
* @param heading Heading of Vehicle when spawning.
* @param isNetwork
* @returns Vehicle object.
*/
public static async createRandomVehicle(
position: Vector3,
heading = 0,
isNetwork = true,
): Promise<Vehicle | null> {
const vehicleCount: number = Object.keys(VehicleHash).length / 2; // check
const randomIndex: number = Maths.getRandomInt(0, vehicleCount);
const randomVehicleName: string = VehicleHash[randomIndex];
const modelHash: number = GetHashKey(randomVehicleName);
const model = new Model(modelHash);
if (!model.IsVehicle || !(await model.request(1000))) {
return null;
}
return new Vehicle(
CreateVehicle(model.Hash, position.x, position.y, position.z, heading, isNetwork, false),
);
}
/**
* Spawns a [[`Prop`]] at the given position.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const model = new Model("prop_barrel_02a");
* const myBarrelProp = await World.createProp(model, position, false, true);
* ```
*
* @param model The [[`Model`]] to spawn (must be a Prop)
* @param position Location of Prop
* @param dynamic If set to true, the Prop will have physics otherwise it's static.
* @param placeOnGround If set to true, sets the Prop on the ground nearest to position.
* @param isNetwork
* @returns Prop object.
*/
public static async createProp(
model: Model,
position: Vector3,
dynamic: boolean,
placeOnGround: boolean,
isNetwork = true,
): Promise<Prop | null> {
if (!model.IsProp || !(await model.request(1000))) {
return null;
}
const prop = new Prop(
CreateObject(model.Hash, position.x, position.y, position.z, isNetwork, true, dynamic),
);
if (placeOnGround) {
prop.placeOnGround();
}
return prop;
}
/**
* Create a pickup in a specific position in the world with a specified type and value.
*
* @param type The [[`PickupType`]] of pickup.
* @param position The position in the world it should be spawned.
* @param model The model of the spawned pickup.
* @param value Give a value for the pickup when picked up.
* @param rotation If set, create a rotating pickup with this rotation.
* @returns Pickup object.
*/
public static async CreatePickup(
type: PickupType,
position: Vector3,
model: Model,
value: number,
rotation?: Vector3,
): Promise<Pickup | null> {
if (!(await model.request(1000))) {
return null;
}
let handle = 0;
if (rotation !== undefined)
handle = CreatePickupRotate(
type,
position.x,
position.y,
position.z,
rotation.x,
rotation.y,
rotation.z,
0,
value,
2,
true,
model.Hash,
);
else
handle = CreatePickup(type, position.x, position.y, position.z, 0, value, true, model.Hash);
if (handle === 0) {
return null;
}
return new Pickup(handle);
}
/**
* Creates an ambient pickup.
*
* @param type The [[`PickupType`]] of the pickup.
* @param position The position where it should be spawned.
* @param model The model.
* @param value The value tied to the pickup.
* @returns The pickup in form of a Prop.
*/
public static async CreateAmbientPickup(
type: PickupType,
position: Vector3,
model: Model,
value: number,
): Promise<Prop | null> {
if (!(await model.request(1000))) {
return null;
}
const handle = CreateAmbientPickup(
type,
position.x,
position.y,
position.z,
0,
value,
model.Hash,
false,
true,
);
if (handle === 0) {
return null;
}
return new Prop(handle);
}
/**
* Draw a marker at a desired location. Careful! Must be drawn every tick.
*
* ```typescript
* const position = new Vector3(-802.311, 175.056, 72.8446);
* const zeroVector = new Vector3(0,0,0);
*
* setTick(() => {
* World.drawMarker(MarkerType.ThickChevronUp, position, zeroVector, zeroVector, 1.0, new Color(255,0,0));
* })
* ```
*
* @param type Type of marker.
* @param position Location of marker.
* @param direction Direction facing.
* @param rotation World rotation.
* @param scale Size of marker.
* @param color Color of marker.
* @param bobUpAndDown Animated movement along marker's own X axis.
* @param faceCamera Rendering marker facing rendering camera.
* @param rotateY Rotate along Y axis.
* @param textureDict Custom texture dictionary for custom marker.
* @param textureName Custom texture name for custom marker.
* @param drawOnEntity Render the marker on an entity.
*/
public static drawMarker(
type: MarkerType,
position: Vector3,
direction: Vector3,
rotation: Vector3,
scale: Vector3,
color: Color,
bobUpAndDown = false,
faceCamera = false,
rotateY = false,
textureDict: string | null = null,
textureName: string | null = null,
drawOnEntity = false,
): void {
DrawMarker(
Number(type),
position.x,
position.y,
position.z,
direction.x,
direction.y,
direction.z,
rotation.x,
rotation.y,
rotation.z,
scale.x,
scale.y,
scale.z,
color.r,
color.g,
color.b,
color.a,
bobUpAndDown,
faceCamera,
2,
rotateY,
textureDict as string,
textureName as string,
drawOnEntity,
);
}
/**
* Creates a light in the world with a certain length (range).
*
* @param pos World coordinate where to draw the light.
* @param color RGB colors of the light.
* @param range How far to draw the light.
* @param intensity Intensity of the light ("alpha").
*/
public static drawLightWithRange(
pos: Vector3,
color: Color,
range: number,
intensity: number,
): void {
DrawLightWithRange(pos.x, pos.y, pos.z, color.r, color.g, color.b, range, intensity);
}
/**
* Creates a light in the world. More configurable than World.drawLightWithRange.
*
* @param pos World coordinate of spotlight.
* @param dir Direction to face spotlight.
* @param color RGB colors of spotlight.
* @param distance The maximum distance the spotlight can reach.
* @param brightness Brightness of the spotlight.
* @param roundness "Smoothness" of the edge of the spotlight.
* @param radius Radius size of spotlight.
* @param fadeOut Falloff size of the spotlight's edge.
*/
public static drawSpotLight(
pos: Vector3,
dir: Vector3,
color: Color,
distance: number,
brightness: number,
roundness: number,
radius: number,
fadeOut: number,
): void {
DrawSpotLight(
pos.x,
pos.y,
pos.z,
dir.x,
dir.y,
dir.z,
color.r,
color.g,
color.b,
distance,
brightness,
roundness,
radius,
fadeOut,
);
}
/**
* Creates a light in the world. Same as World.drawSpotlight, but also draws shadows.
*
* @param pos World coordinate of spotlight.
* @param dir Direction to face spotlight.
* @param color RGB colors of spotlight.
* @param distance The maximum distance the spotlight can reach.
* @param brightness Brightness of the spotlight.
* @param roundness "Smoothness" of the edge of the spotlight.
* @param radius Radius size of spotlight.
* @param fadeOut Falloff size of the spotlight's edge.
*/
public static drawSpotLightWithShadow(
pos: Vector3,
dir: Vector3,
color: Color,
distance: number,
brightness: number,
roundness: number,
radius: number,
fadeOut: number,
): void {
DrawSpotLightWithShadow(
pos.x,
pos.y,
pos.z,
dir.x,
dir.y,
dir.z,
color.r,
color.g,
color.b,
distance,
brightness,
roundness,
radius,
fadeOut,
0,
);
}
/**
* Draws a line in the world. It's not possible to change thickness.
*
* @param start World coordinate of start position of line.
* @param end World coordinate of end position of line.
* @param color RGB color of line.
*/
public static drawLine(start: Vector3, end: Vector3, color: Color): void {
DrawLine(start.x, start.y, start.z, end.x, end.y, end.z, color.r, color.g, color.b, color.a);
}
/**
* Draw polygon in the world.
*
* @param vertexA World coordinate of first point.
* @param vertexB World coordinate of second point.
* @param vertexC World coordinate of third point.
* @param color RGB color of polygon.
*/
public static drawPoly(vertexA: Vector3, vertexB: Vector3, vertexC: Vector3, color: Color): void {
DrawPoly(
vertexA.x,
vertexA.y,
vertexA.z,
vertexB.x,
vertexB.y,
vertexB.z,
vertexC.x,
vertexC.y,
vertexC.z,
color.r,
color.g,
color.b,
color.a,
);
}
/**
* Cast ("shoot") a ray in a certain direction to detect entities in the way.
*
* @param source Starting position of raycast.
* @param direction Direction to cast a ray to.
* @param maxDistance Max distance to cast the ray.
* @param options Possible entity types to detect.
* @param ignoreEntity An entity to ignore (usually player's Ped).
* @returns RaycastResult object.
*/
public static raycast(
source: Vector3,
direction: Vector3,
maxDistance: number,
options: IntersectOptions,
ignoreEntity: Entity,
): RaycastResult {
const target = Vector3.add(source, Vector3.multiply(direction, maxDistance));
return new RaycastResult(
StartShapeTestRay(
source.x,
source.y,
source.z,
target.x,
target.y,
target.z,
Number(options),
ignoreEntity.Handle,
7,
),
);
}
/**
* Gets the closest object of this model
*/
public static getClosestObject(
model: Model,
coords: Vector3,
radius = 25.0,
isMission = false,
): Prop | null {
const prop = GetClosestObjectOfType(
coords.x,
coords.y,
coords.z,
radius,
model.Hash,
isMission,
false,
false,
);
if (prop !== 0) {
return new Prop(prop);
}
return null;
}
/**
* Get all [[`Prop`]] entities in your own scope.
*
* We recommend using [[getAllPropsInGamePool]] instead.
*
* @returns Array of Props.
*/
public static getAllProps(): Prop[] {
const handles: number[] = GetGamePool('CObject');
const props: Prop[] = [];
handles.forEach(handle => props.push(new Prop(handle)));
return props;
}
/**
* Get all [[`Prop`]] entities using the GetGamePool.
* @deprecated Use [[getAllProps]] instead.
* @returns Array of Props.
*/
public static getAllPropsInGamePool(): Prop[] {
return this.getAllProps();
}
/**
* Get all [[`Ped`]] entities in your own scope.
*
* We recommend using [[getAllPedsInGamePool]] instead.
*
* @returns Array of Peds.
*/
public static getAllPeds(): Ped[] {
const handles: number[] = GetGamePool('CPed');
const peds: Ped[] = [];
handles.forEach(handle => peds.push(new Ped(handle)));
return peds;
}
/**
* Get all [[`Ped`]] entities using the GetGamePool.
* @deprecated Use [[getAllPeds]] instead
* @returns Array of Peds.
*/
public static getAllPedsInGamePool(): Ped[] {
return this.getAllPeds();
}
/**
* Get all [[`Vehicle`]] entities in your own scope.
*
* We recommend using [[getAllVehiclesInGamePool]] instead.
*
* @returns Array of Vehicles.
*/
public static getAllVehicles(): Vehicle[] {
const handles: number[] = GetGamePool('CVehicle');
const vehicles: Vehicle[] = [];
handles.forEach(handle => vehicles.push(new Vehicle(handle)));
return vehicles;
}
/**
* Get all [[`Vehicle`]] entities using the GetGamePool.
* @deprecated Use [[getAllVehicles]] instead
* @returns Array of Vehicles.
*/
public static getAllVehiclesInGamePool(): Vehicle[] {
return this.getAllVehicles();
}
/**
* Gets the cloest [[`Vehicle`]] to the current coords, or null if none are found
* @returns the closest vehicle or null
*/
public static getClosestVehicle(coords: Vector3): Vehicle | null {
const vehicles = this.getAllVehicles();
let currentVeh: Vehicle | null = null;
let lastDistance = 9999.0;
for (const vehicle of vehicles) {
if (!currentVeh) {
currentVeh = vehicle;
lastDistance = coords.distance(vehicle.Position);
continue;
}
const distance = coords.distance(vehicle.Position);
if (distance < lastDistance) {
currentVeh = vehicle;
lastDistance = distance;
}
}
return currentVeh;
}
/**
* Get all [[`Pickup`]] entities in your own scope.
*
* We recommend using [[getAllPickupsInGamePool]] instead.
*
* @returns Array of Pickups.
*/
public static getAllPickups(): Pickup[] {
const pickups: Pickup[] = [];
const [handle, entityHandle] = FindFirstPickup(0) as unknown as [number, number];
let pickup: Pickup = new Pickup(entityHandle);
if (pickup !== undefined && pickup !== null && pickup.exists()) {
pickups.push(pickup);
}
let findResult: [number | boolean, number] = [false, 0];
do {
findResult = FindNextPickup(handle, 0) as unknown as [number | boolean, number];
if (findResult[0]) {
pickup = new Pickup(findResult[1]);
if (pickup !== undefined && pickup !== null && pickup.exists()) {
pickups.push(pickup);
}
}
} while (findResult[0]);
EndFindPickup(handle);
return pickups;
}
/**
* Get all [[`Pickup`]] entities using the GetGamePool.
* @returns Array of Pickups.
*/
public static getAllPickupsInGamePool(): Pickup[] {
const handles: number[] = GetGamePool('CPickup');
const pickups: Pickup[] = [];
handles.forEach(handle => pickups.push(new Pickup(handle)));
return pickups;
}
private static currentCloudHat: CloudHat = CloudHat.Clear;
private static cloudHatDict: Map<CloudHat, string> = new Map<CloudHat, string>([
[CloudHat.Unknown, 'Unknown'],
[CloudHat.Altostratus, 'altostratus'],
[CloudHat.Cirrus, 'Cirrus'],
[CloudHat.Cirrocumulus, 'cirrocumulus'],
[CloudHat.Clear, 'Clear 01'],
[CloudHat.Cloudy, 'Cloudy 01'],
[CloudHat.Contrails, 'Contrails'],
[CloudHat.Horizon, 'Horizon'],
[CloudHat.HorizonBand1, 'horizonband1'],
[CloudHat.HorizonBand2, 'horizonband2'],
[CloudHat.HorizonBand3, 'horizonband3'],
[CloudHat.Horsey, 'horsey'],
[CloudHat.Nimbus, 'Nimbus'],
[CloudHat.Puffs, 'Puffs'],
[CloudHat.Rain, 'RAIN'],
[CloudHat.Snowy, 'Snowy 01'],
[CloudHat.Stormy, 'Stormy 01'],
[CloudHat.Stratoscumulus, 'stratoscumulus'],