-
Notifications
You must be signed in to change notification settings - Fork 2k
/
World.cs
1756 lines (1632 loc) · 59.5 KB
/
World.cs
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
using CitizenFX.Core.Native;
using System;
using System.Collections.Generic;
using System.Linq;
#if MONO_V2
using CitizenFX.Core;
using API = CitizenFX.FiveM.Native.Natives;
using TaskPed = CitizenFX.Core.Coroutine<CitizenFX.FiveM.Ped>;
using TaskPickup = CitizenFX.Core.Coroutine<CitizenFX.FiveM.Pickup>;
using TaskProp = CitizenFX.Core.Coroutine<CitizenFX.FiveM.Prop>;
using TaskVehicle = CitizenFX.Core.Coroutine<CitizenFX.FiveM.Vehicle>;
using compat_i32_u32 = System.UInt32;
using compat_i32_i64 = System.Int64;
namespace CitizenFX.FiveM
#else
using System.Drawing;
using TaskPed = System.Threading.Tasks.Task<CitizenFX.Core.Ped>;
using TaskPickup = System.Threading.Tasks.Task<CitizenFX.Core.Pickup>;
using TaskProp = System.Threading.Tasks.Task<CitizenFX.Core.Prop>;
using TaskVehicle = System.Threading.Tasks.Task<CitizenFX.Core.Vehicle>;
using compat_i32_u32 = System.Int32;
using compat_i32_i64 = System.Int32;
namespace CitizenFX.Core
#endif
{
class GTACalender : System.Globalization.GregorianCalendar
{
public override int GetDaysInYear(int year, int era)
{
return 31 * 12;
}
public override int GetDaysInMonth(int year, int month, int era)
{
return 31;
}
}
enum ZoneID
{
AIRP,
ALAMO,
ALTA,
ARMYB,
BANHAMC,
BANNING,
BEACH,
BHAMCA,
BRADP,
BRADT,
BURTON,
CALAFB,
CANNY,
CCREAK,
CHAMH,
CHIL,
CHU,
CMSW,
CYPRE,
DAVIS,
DELBE,
DELPE,
DELSOL,
DESRT,
DOWNT,
DTVINE,
EAST_V,
EBURO,
ELGORL,
ELYSIAN,
GALFISH,
golf,
GRAPES,
GREATC,
HARMO,
HAWICK,
HORS,
HUMLAB,
JAIL,
KOREAT,
LACT,
LAGO,
LDAM,
LEGSQU,
LMESA,
LOSPUER,
MIRR,
MORN,
MOVIE,
MTCHIL,
MTGORDO,
MTJOSE,
MURRI,
NCHU,
NOOSE,
OCEANA,
PALCOV,
PALETO,
PALFOR,
PALHIGH,
PALMPOW,
PBLUFF,
PBOX,
PROCOB,
RANCHO,
RGLEN,
RICHM,
ROCKF,
RTRAK,
SanAnd,
SANCHIA,
SANDY,
SKID,
SLAB,
STAD,
STRAW,
TATAMO,
TERMINA,
TEXTI,
TONGVAH,
TONGVAV,
VCANA,
VESP,
VINE,
WINDF,
WVINE,
ZANCUDO,
ZP_ORT,
ZQ_UAR
}
public enum Weather
{
Unknown = -1,
ExtraSunny,
Clear,
Clouds,
Smog,
Foggy,
Overcast,
Raining,
ThunderStorm,
Clearing,
Neutral,
Snowing,
Blizzard,
Snowlight,
Christmas,
Halloween
}
public enum WeatherTypeHash
{
Unknown = -1,
ExtraSunny = -1750463879,
Clear = 916995460,
Neutral = -1530260698,
Smog = 282916021,
Foggy = -1368164796,
Clouds = 821931868,
Overcast = -1148613331,
Clearing = 1840358669,
Raining = 1420204096,
ThunderStorm = -1233681761,
Blizzard = 669657108,
Snowing = -273223690,
Snowlight = 603685163,
Christmas = -1429616491,
Halloween = -921030142
}
public enum CloudHat
{
Unknown = 1,
Altostratus,
Cirrus,
Cirrocumulus,
Clear,
Cloudy,
Contrails,
Horizon,
HorizonBand1,
HorizonBand2,
HorizonBand3,
Horsey,
Nimbus,
Puffs,
Rain,
Snowy,
Stormy,
Stratoscumulus,
Stripey,
Shower,
Wispy
}
[Flags]
public enum IntersectOptions
{
Everything = -1,
Map = 1,
MissionEntities,
Peds1 = 12,
Objects = 16,
Unk1 = 32,
Unk2 = 64,
Unk3 = 128,
Vegetation = 256,
Unk4 = 512
}
public enum MarkerType
{
UpsideDownCone,
VerticalCylinder,
ThickChevronUp,
ThinChevronUp,
CheckeredFlagRect,
CheckeredFlagCircle,
VerticleCircle,
PlaneModel,
LostMCDark,
LostMCLight,
Number0,
Number1,
Number2,
Number3,
Number4,
Number5,
Number6,
Number7,
Number8,
Number9,
ChevronUpx1,
ChevronUpx2,
ChevronUpx3,
HorizontalCircleFat,
ReplayIcon,
HorizontalCircleSkinny,
HorizontalCircleSkinnyArrow,
HorizontalSplitArrowCircle,
DebugSphere,
DollarSign,
HorizontalBars,
WolfHead,
QuestionMark,
PlaneSymbol,
HelicopterSymbol,
BoatSymbol,
CarSymbol,
MotorcycleSymbol,
BikeSymbol,
TruckSymbol,
ParachuteSymbol,
SawbladeSymbol
}
public enum ExplosionType
{
Grenade,
GrenadeL,
StickyBomb,
Molotov1,
Rocket,
TankShell,
HiOctane,
Car,
Plane,
PetrolPump,
Bike,
Steam,
Flame,
WaterHydrant,
GasCanister,
Boat,
ShipDestroy,
Truck,
Bullet,
SmokeGL,
SmokeG,
BZGas,
Flare,
GasCanister2,
Extinguisher,
ProgramAR,
Train,
Barrel,
Propane,
Blimp,
FlameExplode,
Tanker,
PlaneRocket,
VehicleBullet,
GasTank,
FireWork,
SnowBall,
ProxMine,
Valkyrie
}
public static class World
{
#region Fields
internal static readonly string[] _weatherNames = {
"EXTRASUNNY",
"CLEAR",
"CLOUDS",
"SMOG",
"FOGGY",
"OVERCAST",
"RAIN",
"THUNDER",
"CLEARING",
"NEUTRAL",
"SNOW",
"BLIZZARD",
"SNOWLIGHT",
"XMAS"
};
internal static readonly Dictionary<CloudHat, string> CloudHatDict = new Dictionary<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"},
{CloudHat.Stripey, "Stripey"},
{CloudHat.Shower, "shower"},
{CloudHat.Wispy, "Wispy"}
};
#endregion
/// <summary>
/// Gets or sets the current date and time in the GTA World.
/// </summary>
/// <value>
/// The current date and time.
/// </value>
public static DateTime CurrentDate
{
get
{
int year = API.GetClockYear();
int month = API.GetClockMonth();
int day = API.GetClockDayOfMonth();
int hour = API.GetClockHours();
int minute = API.GetClockMinutes();
int second = API.GetClockSeconds();
return new DateTime(year, month, day, hour, minute, second, new GTACalender());
}
set
{
API.SetClockDate(value.Day, value.Month, value.Year);
API.SetClockTime(value.Hour, value.Minute, value.Second);
}
}
/// <summary>
/// Gets or sets the current time of day in the GTA World.
/// </summary>
/// <value>
/// The current time of day
/// </value>
public static TimeSpan CurrentDayTime
{
get
{
int hours = API.GetClockHours();
int minutes = API.GetClockMinutes();
int seconds = API.GetClockSeconds();
return new TimeSpan(hours, minutes, seconds);
}
set
{
API.SetClockTime(value.Hours, value.Minutes, value.Seconds);
}
}
/// <summary>
/// Sets a value indicating whether lights in the <see cref="World"/> should be rendered.
/// </summary>
/// <value>
/// <c>true</c> if blackout; otherwise, <c>false</c>.
/// </value>
public static bool Blackout
{
set
{
API.SetBlackout(value);
}
}
private static CloudHat _currentCloudHat = CloudHat.Clear;
/// <summary>
/// Gets or sets the current Cloud Hat.
/// </summary>
public static CloudHat CloudHat
{
get => _currentCloudHat;
set
{
_currentCloudHat = value;
if (_currentCloudHat == CloudHat.Unknown)
{
_currentCloudHat = CloudHat.Clear;
API.ClearCloudHat();
return;
}
API.SetCloudHatTransition(CloudHatDict.ContainsKey(_currentCloudHat) ? CloudHatDict[_currentCloudHat] : "", 3f);
}
}
/// <summary>
/// Gets or sets the current Cloud Hat opacity. On a scale of 0.0 to 1.0.
/// </summary>
public static float CloudHatOpacity
{
get => API.GetCloudHatOpacity();
set => API.SetCloudHatOpacity(MathUtil.Clamp(value, 0f, 1f));
}
/// <summary>
/// Gets or sets the weather.
/// </summary>
/// <value>
/// The weather.
/// </value>
public static Weather Weather
{
get
{
switch (unchecked((int)API.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
{
if (Enum.IsDefined(typeof(Weather), value) && value != Weather.Unknown)
{
API.SetWeatherTypeNow(_weatherNames[(int)value]);
}
}
}
/// <summary>
/// Gets or sets the next weather.
/// </summary>
/// <value>
/// The next weather.
/// </value>
public static Weather NextWeather
{
get
{
switch (unchecked((int)API.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
{
if (Enum.IsDefined(typeof(Weather), value) && value != Weather.Unknown)
{
API.SetWeatherTypeOverTime(value.ToString(), 0f); // rockstar uses 45 seconds transition time, use TransitionToWeather for that.
}
}
}
/// <summary>
/// Gets or sets the weather transition.
/// </summary>
/// <value>
/// The weather transition.
/// </value>
public static float WeatherTransition
{
get
{
// CFX-TODO: Find a way to get this native to work, currently it doesn't seem to work.
// API.GetWeatherTypeTransition()
return 0.0f;
}
set
{
// doesn't seem to work.
API.SetWeatherTypeTransition(0, 0, value);
}
}
/// <summary>
/// Transitions to weather. Duration is 45f in most scripts.
/// </summary>
/// <param name="weather">The weather.</param>
/// <param name="duration">The duration.</param>
public static void TransitionToWeather(Weather weather, float duration)
{
if (Enum.IsDefined(typeof(Weather), weather) && weather != Weather.Unknown)
{
API.SetWeatherTypeOverTime(_weatherNames[(int)weather], duration);
}
}
/// <summary>
/// Sets the gravity level for all <see cref="World"/> objects.
/// </summary>
/// <value>
/// The gravity level:
/// 9.8f - Default gravity.
/// 2.4f - Moon gravity.
/// 0.1f - Very low gravity.
/// 0.0f - No gravity.
/// </value>
public static float GravityLevel
{
get { return MemoryAccess.ReadWorldGravity(); }
set
{
//write the value you want to the first item in the array where the native reads the gravity level choices from
MemoryAccess.WriteWorldGravity(value);
//call set_gravity_level normally using 0 as gravity type
//the native will then set the gravity level to what we just wrote
API.SetGravityLevel(0);
//reset the array item back to 9.8 so as to restore behaviour of the native
MemoryAccess.WriteWorldGravity(9.800000f);
}
}
/// <summary>
/// Gets or sets the rendering camera.
/// </summary>
/// <value>
/// The rendering <see cref="Camera"/>.
/// </value>
/// <remarks>
/// Setting to <c>null</c> sets the rendering <see cref="Camera"/> to <see cref="GameplayCamera"/>.
/// </remarks>
public static Camera RenderingCamera
{
get
{
return new Camera(API.GetRenderingCam());
}
set
{
if (value == null)
{
API.RenderScriptCams(false, false, 3000, true, false);
}
else
{
value.IsActive = true;
API.RenderScriptCams(true, false, 3000, true, false);
}
}
}
/// <summary>
/// Destroys all user created <see cref="Camera"/>s.
/// </summary>
public static void DestroyAllCameras()
{
API.DestroyAllCams(false);
}
/// <summary>
/// Gets or sets the waypoint position.
/// </summary>
/// <returns>The <see cref="Vector3"/> coordinates of the Waypoint <see cref="Blip"/></returns>
/// <remarks>
/// Returns an empty <see cref="Vector3"/> if a waypoint <see cref="Blip"/> hasn't been set
/// If the game engine cant extract height information the Z component will be 0.0f
/// </remarks>
public static Vector3 WaypointPosition
{
get
{
Blip waypointBlip = GetWaypointBlip();
if (waypointBlip == null)
{
return Vector3.Zero;
}
Vector3 position = waypointBlip.Position;
position.Z = GetGroundHeight(position);
return position;
}
set
{
API.SetNewWaypoint(value.X, value.Y);
}
}
/// <summary>
/// Gets the waypoint blip.
/// </summary>
/// <returns>The <see cref="Vector3"/> coordinates of the Waypoint <see cref="Blip"/></returns>
/// <remarks>
/// Returns <c>null</c> if a waypoint <see cref="Blip"/> hasn't been set
/// </remarks>
public static Blip GetWaypointBlip()
{
if (!Game.IsWaypointActive)
{
return null;
}
for (int it = API.GetBlipInfoIdIterator(), blip = API.GetFirstBlipInfoId(it); API.DoesBlipExist(blip); blip = API.GetNextBlipInfoId(it))
{
if (API.GetBlipInfoIdType(blip) == 4)
{
return new Blip(blip);
}
}
return null;
}
/// <summary>
/// Removes the waypoint.
/// </summary>
public static void RemoveWaypoint()
{
API.SetWaypointOff();
}
/// <summary>
/// Gets the straight line distance between 2 positions.
/// </summary>
/// <param name="origin">The origin.</param>
/// <param name="destination">The destination.</param>
/// <returns>The distance</returns>
public static float GetDistance(Vector3 origin, Vector3 destination)
{
return (float)Math.Sqrt(destination.DistanceToSquared(origin));
}
/// <summary>
/// Calculates the travel distance using roads and paths between 2 positions.
/// </summary>
/// <param name="origin">The origin.</param>
/// <param name="destination">The destination.</param>
/// <returns>The travel distance</returns>
public static float CalculateTravelDistance(Vector3 origin, Vector3 destination)
{
return API.CalculateTravelDistanceBetweenPoints(origin.X, origin.Y, origin.Z, destination.X, destination.Y, destination.Z);
}
/// <summary>
/// Gets the height of the ground at a given position.
/// </summary>
/// <param name="position">The position.</param>
/// <returns>The height measured in meters</returns>
public static float GetGroundHeight(Vector3 position)
{
return GetGroundHeight(new Vector2(position.X, position.Y));
}
/// <summary>
/// Gets the height of the ground at a given position.
/// </summary>
/// <param name="position">The position.</param>
/// <returns>The height measured in meters</returns>
public static float GetGroundHeight(Vector2 position)
{
float resultArg = 0f;
API.RequestCollisionAtCoord(position.X, position.Y, 1000f);
API.GetGroundZFor_3dCoord(position.X, position.Y, 1000f, ref resultArg, false);
return resultArg;
}
/// <summary>
/// Gets an <c>array</c> of all the <see cref="Blip"/>s on the map with a given <see cref="BlipSprite"/>.
/// </summary>
/// <param name="blipTypes">The blip types to include, leave blank to get all <see cref="Blip"/>s.</param>
public static Blip[] GetAllBlips(params BlipSprite[] blipTypes)
{
var res = new List<Blip>();
if (blipTypes.Length == 0)
{
blipTypes = Enum.GetValues(typeof(BlipSprite)).Cast<BlipSprite>().ToArray();
}
foreach (BlipSprite sprite in blipTypes)
{
int handle = API.GetFirstBlipInfoId((int)sprite);
while (API.DoesBlipExist(handle))
{
res.Add(new Blip(handle));
handle = API.GetNextBlipInfoId((int)sprite);
}
}
return res.ToArray();
}
/// <summary>
/// Gets an <c>array</c> of all the <see cref="Prop"/>s on the map.
/// </summary>
public static Prop[] GetAllProps()
{
List<Prop> props = new List<Prop>();
int entHandle = -1;
int handle = API.FindFirstObject(ref entHandle);
Prop prop = (Prop)Entity.FromHandle(entHandle);
if (prop != null && prop.Exists())
props.Add(prop);
entHandle = -1;
while (API.FindNextObject(handle, ref entHandle))
{
prop = (Prop)Entity.FromHandle(entHandle);
if (prop != null && prop.Exists())
props.Add(prop);
entHandle = -1;
}
API.EndFindObject(handle);
return props.ToArray();
}
/// <summary>
/// Gets an <c>array</c> of all the <see cref="Ped"/>s on the map.
/// </summary>
public static Ped[] GetAllPeds()
{
List<Ped> peds = new List<Ped>();
int entHandle = -1;
int handle = API.FindFirstPed(ref entHandle);
Ped ped = (Ped)Entity.FromHandle(entHandle);
if (ped != null && ped.Exists())
peds.Add(ped);
entHandle = -1;
while (API.FindNextPed(handle, ref entHandle))
{
ped = (Ped)Entity.FromHandle(entHandle);
if (ped != null && ped.Exists())
peds.Add(ped);
entHandle = -1;
}
API.EndFindPed(handle);
return peds.ToArray();
}
/// <summary>
/// Gets an <c>array</c> of all the <see cref="Vehicle"/>s on the map.
/// </summary>
public static Vehicle[] GetAllVehicles()
{
List<Vehicle> vehicles = new List<Vehicle>();
int entHandle = -1;
int handle = API.FindFirstVehicle(ref entHandle);
Vehicle veh = (Vehicle)Entity.FromHandle(entHandle);
if (veh != null && veh.Exists())
vehicles.Add(veh);
entHandle = -1;
while (API.FindNextVehicle(handle, ref entHandle))
{
veh = (Vehicle)Entity.FromHandle(entHandle);
if (veh != null && veh.Exists())
vehicles.Add(veh);
entHandle = -1;
}
API.EndFindVehicle(handle);
return vehicles.ToArray();
}
/// <summary>
/// Gets an <c>array</c> of all the <see cref="Pickup"/>s on the map.
/// </summary>
public static Pickup[] GetAllPickups()
{
List<Pickup> pickups = new List<Pickup>();
int entHandle = -1;
int handle = API.FindFirstPickup(ref entHandle);
Pickup pickup = new Pickup(entHandle);
if (pickup != null && pickup.Exists())
pickups.Add(pickup);
entHandle = -1;
while (API.FindNextPickup(handle, ref entHandle))
{
pickup = new Pickup(entHandle);
if (pickup != null && pickup.Exists())
pickups.Add(pickup);
entHandle = -1;
}
API.EndFindPickup(handle);
return pickups.ToArray();
}
// CFX-TODO
/*
/// <summary>
/// Gets an <c>array</c> of all the <see cref="Checkpoint"/>s.
/// </summary>
public static Checkpoint[] GetAllCheckpoints()
{
return Array.ConvertAll<int, Checkpoint>(MemoryAccess.GetCheckpointHandles(), element => new Checkpoint(element));
}
static int[] ModelListToHashList(Model[] models)
{
return Array.ConvertAll<Model, int>(models, model => model.Hash);
}
/// <summary>
/// Gets an <c>array</c>of all <see cref="Ped"/>s in the World.
/// </summary>
/// <param name="models">The <see cref="Model"/> of <see cref="Ped"/>s to get, leave blank for all <see cref="Ped"/> <see cref="Model"/>s.</param>
public static Ped[] GetAllPeds(params Model[] models)
{
return Array.ConvertAll<int, Ped>(MemoryAccess.GetPedHandles(ModelListToHashList(models)), handle => new Ped(handle));
}
/// <summary>
/// Gets an <c>array</c> of all <see cref="Ped"/>s in a given region in the World.
/// </summary>
/// <param name="position">The position to check the <see cref="Ped"/> against.</param>
/// <param name="radius">The maximun distance from the <paramref name="position"/> to detect <see cref="Ped"/>s.</param>
/// <param name="models">The <see cref="Model"/> of <see cref="Ped"/>s to get, leave blank for all <see cref="Ped"/> <see cref="Model"/>s.</param>
public static Ped[] GetNearbyPeds(Vector3 position, float radius, params Model[] models)
{
return Array.ConvertAll<int, Ped>(MemoryAccess.GetPedHandles(position, radius, ModelListToHashList(models)), handle => new Ped(handle));
}
/// <summary>
/// Gets an <c>array</c> of all <see cref="Ped"/>s near a given <see cref="Ped"/> in the world
/// </summary>
/// <param name="ped">The ped to check.</param>
/// <param name="radius">The maximun distance from the <paramref name="ped"/> to detect <see cref="Ped"/>s.</param>
/// <param name="models">The <see cref="Model"/> of <see cref="Ped"/>s to get, leave blank for all <see cref="Ped"/> <see cref="Model"/>s.</param>
/// <remarks>Doesnt include the <paramref name="ped"/> in the result</remarks>
public static Ped[] GetNearbyPeds(Ped ped, float radius, params Model[] models)
{
int[] handles = MemoryAccess.GetPedHandles(ped.Position, radius, ModelListToHashList(models));
var result = new List<Ped>();
foreach (int handle in handles)
{
if (handle == ped.Handle)
{
continue;
}
result.Add(new Ped(handle));
}
return result.ToArray();
}
/// <summary>
/// Gets the closest <see cref="Ped"/> to a given position in the World.
/// </summary>
/// <param name="position">The position to find the nearest <see cref="Ped"/>.</param>
/// <param name="radius">The maximun distance from the <paramref name="position"/> to detect <see cref="Ped"/>s.</param>
/// <param name="models">The <see cref="Model"/> of <see cref="Ped"/>s to get, leave blank for all <see cref="Ped"/> <see cref="Model"/>s.</param>
/// <remarks>Returns <c>null</c> if no <see cref="Ped"/> was in the given region.</remarks>
public static Ped GetClosestPed(Vector3 position, float radius, params Model[] models)
{
Ped[] peds =
Array.ConvertAll<int, Ped>(MemoryAccess.GetPedHandles(position, radius, ModelListToHashList(models)),
handle => new Ped(handle));
return GetClosest<Ped>(position, peds);
}
/// <summary>
/// A fast way to get the total number of vehicles spawned in the world.
/// </summary>
/// // CFX-TODO
public static int VehicleCount { get { return 0; } }// return MemoryAccess.GetNumberOfVehicles(); } }
/// <summary>
/// Gets an <c>array</c> of all <see cref="Vehicle"/>s in the World.
/// </summary>
/// <param name="models">The <see cref="Model"/> of <see cref="Vehicle"/>s to get, leave blank for all <see cref="Vehicle"/> <see cref="Model"/>s.</param>
public static Vehicle[] GetAllVehicles(params Model[] models)
{
return Array.ConvertAll<int, Vehicle>(MemoryAccess.GetVehicleHandles(ModelListToHashList(models)), handle => new Vehicle(handle));
}
/// <summary>
/// Gets an <c>array</c> of all <see cref="Vehicle"/>s in a given region in the World.
/// </summary>
/// <param name="position">The position to check the <see cref="Vehicle"/> against.</param>
/// <param name="radius">The maximun distance from the <paramref name="position"/> to detect <see cref="Vehicle"/>s.</param>
/// <param name="models">The <see cref="Model"/> of <see cref="Vehicle"/>s to get, leave blank for all <see cref="Vehicle"/> <see cref="Model"/>s.</param>
public static Vehicle[] GetNearbyVehicles(Vector3 position, float radius, params Model[] models)
{
return Array.ConvertAll<int, Vehicle>(MemoryAccess.GetVehicleHandles(position, radius, ModelListToHashList(models)), handle => new Vehicle(handle));
}
/// <summary>
/// Gets an <c>array</c> of all <see cref="Vehicle"/>s near a given <see cref="Ped"/> in the world
/// </summary>
/// <param name="ped">The ped to check.</param>
/// <param name="radius">The maximun distance from the <paramref name="ped"/> to detect <see cref="Vehicle"/>s.</param>
/// <param name="models">The <see cref="Model"/> of <see cref="Vehicle"/>s to get, leave blank for all <see cref="Vehicle"/> <see cref="Model"/>s.</param>
/// <remarks>Doesnt include the <see cref="Vehicle"/> the <paramref name="ped"/> is using in the result</remarks>
public static Vehicle[] GetNearbyVehicles(Ped ped, float radius, params Model[] models)
{
int[] handles = MemoryAccess.GetVehicleHandles(ped.Position, radius, ModelListToHashList(models));
var result = new List<Vehicle>();
Vehicle ignore = ped.CurrentVehicle;
int ignoreHandle = Vehicle.Exists(ignore) ? ignore.Handle : 0;
foreach (int handle in handles)
{
if (handle == ignoreHandle)
{
continue;
}
result.Add(new Vehicle(handle));
}
return result.ToArray();
}
/// <summary>
/// Gets the closest <see cref="Vehicle"/> to a given position in the World.
/// </summary>
/// <param name="position">The position to find the nearest <see cref="Vehicle"/>.</param>
/// <param name="radius">The maximun distance from the <paramref name="position"/> to detect <see cref="Vehicle"/>s.</param>