-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
527 lines (490 loc) · 18.4 KB
/
Utils.cs
File metadata and controls
527 lines (490 loc) · 18.4 KB
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
using CitizenFX.Core;
using FivePD.API.Utils;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core.Native;
using CitizenFX.Core.NaturalMotion;
using FivePD_HostageScenarioCallout;
using FivePD.API;
using Newtonsoft.Json.Linq;
namespace FivePD_HostageScenarioCallout
{
internal class Utils
{
public static void CalloutError(Exception err, Callout callout)
{
try
{
Debug.WriteLine("^3=================^2Kilo's Hostage Callout^3=================");
Debug.WriteLine("^8ERROR DETECTED^7: " + err.Message);
Debug.WriteLine("^3=================^2Kilo's Hostage Callout^3=================");
Debug.WriteLine("^5Callout Ended");
if ((bool)GetConfig()["AnonymousErrorReporting"])
{
BaseScript.TriggerServerEvent("KiloHostage::ErrorToWebhook",
"Error in KiloHostage Callout: \n" + err.ToString());
}
callout.EndCallout();
}
catch (Exception err2)
{
// Do nothing
}
}
public static async Task TaskPedTakeTargetPedHostage(Ped ped, Ped targetPed)
{
// Define parameters
string suspectAnimDict = "anim@gangops@hostage@";
string suspectAnimSet = "perp_idle";
string victimAnimDict = suspectAnimDict;
string victimAnimSet = "victim_idle";
// Request memory resources
await RequestAnimDict(suspectAnimDict);
await RequestAnimDict(victimAnimDict);
RequestAnimSet(suspectAnimSet);
RequestAnimSet(victimAnimSet);
Debug.WriteLine("After await anims");
// Code
if (ped == null)
Debug.WriteLine("Ped is null");
if (targetPed == null)
Debug.WriteLine("Target is null");
ped.Task.ClearSecondary();
ped.Detach();
API.AttachEntityToEntity(targetPed.Handle, ped.Handle, 0, -0.24f, 0.11f, 0f, 0.5f, 0.5f, 0f, false, false,
false, false, 2, false);
ped.Task.PlayAnimation(suspectAnimDict, suspectAnimSet, 8f, -8f, -1, AnimationFlags.Loop, 1f);
targetPed.Task.PlayAnimation(victimAnimDict, victimAnimSet, 8f, -8f, -1, AnimationFlags.Loop, 1f);
}
public static async Task RequestAnimDict(string animDict)
{
if (!API.HasAnimDictLoaded(animDict))
API.RequestAnimDict(animDict);
while (!API.HasAnimDictLoaded(animDict))
await BaseScript.Delay(100);
}
public static async Task RequestAnimSet(string animSet)
{
if (!API.HasAnimSetLoaded(animSet))
API.RequestAnimSet(animSet);
while (!API.HasAnimSetLoaded(animSet))
await BaseScript.Delay(100);
}
public static void UnloadAnimDict(string animDict)
{
API.RemoveAnimDict(animDict);
}
public static void UnloadAnimSet(string animSet)
{
API.RemoveAnimSet(animSet);
}
public static List<Entity> EntitiesInMemory = new List<Entity>();
public static async Task<Ped> SpawnPedOneSync(PedHash pedHash, Vector3 location, [Optional] bool keepTask, [Optional] float heading)
{
Ped ped = await World.CreatePed(new(pedHash), location, heading);
ped.IsPersistent = true;
EntitiesInMemory.Add(ped);
if (keepTask)
{
ped.AlwaysKeepTask = true;
ped.BlockPermanentEvents = true;
}
return ped;
}
public static void ReleaseEntity(Entity ent)
{
if (ent.Model.IsPed)
{
Ped ped = (Ped)ent;
ped.AlwaysKeepTask = false;
ped.BlockPermanentEvents = false;
}
if (EntitiesInMemory.Contains(ent))
EntitiesInMemory.Remove(ent);
ent.IsPersistent = false;
}
public static Vector4 GetRandomLocationFromArray(Array array)
{
var chance = new Random().Next(array.Length - 1);
var result = array.GetValue(chance);
return (Vector4)result;
}
public static List<Vector4> GetLocationArrayFromJArray(JArray jObject, string name)
{
List<Vector4> locationArray = new List<Vector4>();
var locationsObject = (JArray)jObject;
foreach (JObject jToken in locationsObject)
{
if (jToken.GetValue("x") == null)
Debug.WriteLine("No x");
locationArray.Add(JSONCoordsToVector4((JObject)jToken[name]));
}
return locationArray;
}
public static JObject GetChildFromParent(JToken parent, string name)
{
return (JObject)parent[name];
}
public static JObject GetConfig()
{
JObject result = null;
try
{
string data = API.LoadResourceFile("fivepd", "callouts/KiloHostage/settings.json");
result = JObject.Parse(data);
}
catch (Exception err)
{
Debug.WriteLine("^8ERROR^7: ^3Please add the following line into the 'files' section of your fivepd fxmanifest.lua:");
Debug.WriteLine("^1===================================================================================================");
Debug.WriteLine("^9'callouts/KiloHostage/*.json'");
Debug.WriteLine("^1===================================================================================================");
Debug.WriteLine("^8ERROR (Kilo's Hostage Callout)^7: ^2 The above line will allow the callout to read the json files here in the callout folder!");
}
return result;
}
public static Vector3 GetRandomLocationInRadius(int min, int max)
{
int distance = new Random().Next(min, max);
float offsetX = new Random().Next(-1 * distance, distance);
float offsetY = new Random().Next(-1 * distance, distance);
return World.GetNextPositionOnStreet(Game.PlayerPed.GetOffsetPosition(new Vector3(offsetX, offsetY, 0)));
}
public static async Task PedTaskSassyChatAnimation(Ped ped)
{
if (!API.HasAnimDictLoaded("oddjobs@assassinate@vice@hooker"))
API.RequestAnimDict("oddjobs@assassinate@vice@hooker");
Debug.WriteLine("Requesting anim dict");
if (!API.HasAnimSetLoaded("argue_b"))
API.RequestAnimSet("argue_b");
Debug.WriteLine("Requesting anim set");
while (!API.HasAnimDictLoaded("oddjobs@assassinate@vice@hooker"))
await BaseScript.Delay(200);
Debug.WriteLine("Loaded anim dict");
Debug.WriteLine("Loaded anim set");
Debug.WriteLine("after waiting load");
ped.Task.ClearAllImmediately();
ped.Task.PlayAnimation("oddjobs@assassinate@vice@hooker", "argue_b", 8f, 8f, 10000, AnimationFlags.Loop,
1f);
}
public static async Task KeepTaskEnterVehicle(Ped ped, Vehicle veh, VehicleSeat targetSeat)
{
SetIntoVehicleAfterTimer(ped, veh, VehicleSeat.Any, 30000);
while (true)
{
Vector3 startPos = ped.Position;
await BaseScript.Delay(2500);
if (!ped.IsInVehicle(veh) && ped.Position.DistanceTo(startPos) < 1f)
ped.Task.EnterVehicle(veh, targetSeat);
await BaseScript.Delay(2500);
}
}
public static async Task WaitUntilPedIsInVehicle(Ped ped, Vehicle veh, VehicleSeat targetSeat)
{
while (true)
{
if (ped.IsInVehicle(veh) || ped.IsInVehicle() && ped.SeatIndex == targetSeat)
return;
await BaseScript.Delay(500);
}
}
public static async Task SetIntoVehicleAfterTimer(Ped ped, Vehicle veh, VehicleSeat targetSeat, int ms)
{
await BaseScript.Delay(ms);
if (!ped.IsInVehicle(veh))
{
ped.SetIntoVehicle(veh, targetSeat);
}
}
public static async Task KeepTaskGoToForPed(Ped ped, Vector3 pos, float buffer)
{
Vector3 startPos = ped.Position;
while (true)
{
await BaseScript.Delay(1000);
if (ped.Position == startPos)
{
ped.Task.GoTo(pos);
}
if (ped.Position.DistanceTo(pos) < buffer)
return;
await BaseScript.Delay(1000);
}
}
public static async Task WaitUntilEntityIsAtPos(Entity ent, Vector3 pos, float buffer)
{
if (ent == null || !ent.Exists())
return;
while (true)
{
if (ent == null || !ent.Exists())
return;
if (ent.Position.DistanceTo(pos) < buffer)
break;
await BaseScript.Delay(200);
}
}
public static PedHash GetRandomPed()
{
return RandomUtils.GetRandomPed(exclusions);
}
public static Vector3 JSONCoordsToVector3(JObject coordsObj)
{
return new Vector3((float)coordsObj["x"], (float)coordsObj["y"], (float)coordsObj["z"]);
}
public static Vector4 JSONCoordsToVector4(JObject coordsObj)
{
return new Vector4((float)coordsObj["x"], (float)coordsObj["y"], (float)coordsObj["z"],
(float)coordsObj["w"]);
}
public static void KeepTask(Ped ped)
{
if (ped == null || !ped.Exists()) return;
ped.IsPersistent = true;
ped.AlwaysKeepTask = true;
ped.BlockPermanentEvents = true;
}
public static void UnKeepTask(Ped ped)
{
ped.IsPersistent = false;
ped.AlwaysKeepTask = false;
ped.BlockPermanentEvents = false;
}
public static Vector3[] ConvenienceLocations = new Vector3[]
{
new(-712.12f, -913.06f, 19.22f),
new(29.49f, -1346.94f, 29.5f),
new(-50.78f, -1753.61f, 29.42f),
new(376.4f, 325.75f, 103.57f),
new(-1223.94f, -906.52f, 12.33f)
};
public static Vector3[] HomeLocations = new Vector3[]
{
new(-120.15f, -1574.39f, 34.18f),
new(-148.07f, -1596.64f, 38.21f),
new(-32.44f, -1446.5f, 31.89f),
new(-14.11f, -1441.93f, 31.1f),
new(72.21f, -1938.59f, 21.37f),
new(126.68f, -1930.01f, 21.38f),
new(270.2f, -1917.19f, 26.18f),
new(325.68f, -2050.86f, 20.93f),
new(1099.52f, -438.65f, 67.79f),
new(1046.24f, -498.14f, 64.28f),
new(980.1f, -627.29f, 59.24f),
new(943.45f, -653.49f, 58.43f),
new(1223.08f, -696.85f, 60.8f),
new(1201.06f, -575.68f, 69.14f),
new(1265.9f, -648.33f, 67.92f),
new(1241.5f, -566.4f, 69.66f),
new(1204.73f, -557.74f, 69.62f),
new(1223.06f, -696.74f, 60.81f),
new(930.88f, -244.82f, 69.0f),
new(880.01f, -205.01f, 71.98f),
new(798.39f, -158.83f, 74.89f),
new(820.86f, -155.84f, 80.75f), // Second floor
new(208.65f, 74.53f, 87.9f),
new(119.34f, 494.13f, 147.34f),
new(79.74f, 486.13f, 148.2f),
new(151.2f, 556.09f, 183.74f),
new(232.1f, 672.06f, 189.98f),
new(-66.76f, 490.13f, 144.88f),
new(-175.94f, 502.73f, 137.42f),
new(-230.26f, 488.29f, 128.77f),
new(-355.91f, 469.56f, 112.61f),
new(-353.17f, 423.13f, 110.98f),
new(-312.53f, 474.91f, 111.83f),
new(-348.99f, 514.99f, 120.65f),
new(-376.59f, 547.66f, 123.85f),
new(-406.6f, 566.28f, 124.61f),
new(-520.28f, 594.07f, 120.84f),
new(-581.37f, 494.04f, 108.26f),
new(-678.67f, 511.67f, 113.53f),
new(-784.46f, 459.47f, 100.25f),
new(-824.67f, 422.6f, 92.13f),
new(-881.97f, 364.1f, 85.36f),
new(-967.59f, 436.88f, 80.57f),
new(-1570.71f, 23.0f, 59.55f),
new(-1629.9f, 36.25f, 62.94f),
new(-1750.22f, -695.19f, 11.75f),
new(-1270.03f, -1296.53f, 4.0f),
new(-1148.96f, -1523.2f, 10.63f),
new(-1105.61f, -1596.67f, 4.61f)
};
public static bool IsPedNonLethalOrMelee(Ped ped)
{
WeaponHash weapon = ped.Weapons.Current;
return nonlethals.Contains(weapon) || melee.Contains(weapon);
}
public static WeaponHash[] nonlethals =
{
WeaponHash.Ball,
WeaponHash.Parachute,
WeaponHash.Flare,
WeaponHash.Snowball,
WeaponHash.Unarmed,
WeaponHash.StunGun,
WeaponHash.FireExtinguisher
};
public static WeaponHash[] melee =
{
WeaponHash.Crowbar,
WeaponHash.Bat,
WeaponHash.Bottle,
WeaponHash.Flashlight,
WeaponHash.Hatchet,
WeaponHash.Knife,
WeaponHash.Machete,
WeaponHash.Nightstick,
WeaponHash.Unarmed,
WeaponHash.PoolCue,
WeaponHash.StoneHatchet
};
public static VehicleHash GetRandomVehicleForRobberies()
{
return RandomUtils.GetRandomVehicle(FourPersonVehicleClasses);
}
public static IEnumerable<VehicleClass> FourPersonVehicleClasses = new List<VehicleClass>()
{
VehicleClass.Compacts,
VehicleClass.Sedans,
VehicleClass.Vans,
VehicleClass.SUVs
};
public static PedHash GetRandomSuspect()
{
return suspects[new Random().Next(suspects.Length - 1)];
}
public static WeaponHash GetRandomWeapon()
{
int index = new Random().Next(weapons.Length);
return weapons[index];
}
public static WeaponHash[] weapons =
{
WeaponHash.AssaultRifle,
WeaponHash.PumpShotgun,
WeaponHash.CombatPistol
};
public static PedHash[] suspects =
{
PedHash.MerryWeatherCutscene,
PedHash.Armymech01SMY,
PedHash.MerryWeatherCutscene,
PedHash.ChemSec01SMM,
PedHash.Blackops01SMY,
PedHash.CiaSec01SMM,
PedHash.PestContDriver,
PedHash.PestContGunman,
PedHash.TaoCheng,
PedHash.Hunter,
PedHash.EdToh,
PedHash.PrologueMournMale01,
PedHash.PoloGoon01GMY
};
public static IEnumerable<WeaponHash> weapExclusions = new List<WeaponHash>
{
WeaponHash.Ball,
WeaponHash.Bat,
WeaponHash.Snowball,
WeaponHash.RayMinigun,
WeaponHash.RayCarbine,
WeaponHash.BattleAxe,
WeaponHash.Bottle,
WeaponHash.BZGas,
WeaponHash.Crowbar,
WeaponHash.Dagger,
WeaponHash.FireExtinguisher,
WeaponHash.Firework,
WeaponHash.Flare,
WeaponHash.FlareGun,
WeaponHash.Flashlight,
WeaponHash.GolfClub,
WeaponHash.Grenade,
WeaponHash.GrenadeLauncher,
WeaponHash.Gusenberg,
WeaponHash.Hammer,
WeaponHash.Hatchet,
WeaponHash.StoneHatchet,
WeaponHash.StunGun,
WeaponHash.Musket,
WeaponHash.HeavySniper,
WeaponHash.HeavySniperMk2,
WeaponHash.HomingLauncher,
WeaponHash.Knife,
WeaponHash.KnuckleDuster,
WeaponHash.Machete,
WeaponHash.Molotov,
WeaponHash.Nightstick,
WeaponHash.NightVision,
WeaponHash.Parachute,
WeaponHash.PetrolCan,
WeaponHash.PipeBomb,
WeaponHash.PoolCue,
WeaponHash.ProximityMine,
WeaponHash.Railgun,
WeaponHash.RayPistol,
WeaponHash.RPG,
WeaponHash.SmokeGrenade,
WeaponHash.SniperRifle,
WeaponHash.StickyBomb,
WeaponHash.SwitchBlade,
WeaponHash.Unarmed,
WeaponHash.Wrench
};
public static IEnumerable<PedHash> exclusions = new List<PedHash>()
{
PedHash.Acult01AMM,
PedHash.Motox01AMY,
PedHash.Boar,
PedHash.Cat,
PedHash.ChickenHawk,
PedHash.Chimp,
PedHash.Chop,
PedHash.Cormorant,
PedHash.Cow,
PedHash.Coyote,
PedHash.Crow,
PedHash.Deer,
PedHash.Dolphin,
PedHash.Fish,
PedHash.Hen,
PedHash.Humpback,
PedHash.Husky,
PedHash.KillerWhale,
PedHash.MountainLion,
PedHash.Pig,
PedHash.Pigeon,
PedHash.Poodle,
PedHash.Rabbit,
PedHash.Rat,
PedHash.Retriever,
PedHash.Rhesus,
PedHash.Rottweiler,
PedHash.Seagull,
PedHash.HammerShark,
PedHash.TigerShark,
PedHash.Shepherd,
PedHash.Stingray,
PedHash.Westy,
PedHash.BradCadaverCutscene,
PedHash.Orleans,
PedHash.OrleansCutscene,
PedHash.ChiCold01GMM,
PedHash.DeadHooker,
PedHash.Marston01,
PedHash.Niko01,
PedHash.PestContGunman,
PedHash.Pogo01,
PedHash.Ranger01SFY,
PedHash.Ranger01SMY,
PedHash.RsRanger01AMO,
PedHash.Zombie01
};
}
}