From 221378f1d1b9bbc437a6d60ca51ba8fddf0aae6e Mon Sep 17 00:00:00 2001 From: KDani-99 Date: Mon, 14 Dec 2020 17:02:18 +0100 Subject: [PATCH] refactor: added dedicated method for ped/vehicle spawning --- Source/Callout.cs | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/Source/Callout.cs b/Source/Callout.cs index 173ea77..c0623d5 100644 --- a/Source/Callout.cs +++ b/Source/Callout.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using CitizenFX.Core; -using static CitizenFX.Core.Native.API; using FivePD.API.Utils; namespace FivePD.API @@ -81,22 +80,7 @@ public Callout() { } /// The location of the ped. /// Which direction the ped is facing. /// - protected async Task SpawnPed(PedHash pedHash, Vector3 location, float heading = 0f) - { - Model model = new Model(pedHash); - - model.Request(); - while (!model.IsLoaded) - { - model.Request(); - await BaseScript.Delay(0); - } - - Ped ped = (Ped)Entity.FromHandle(CreatePed(0, (uint)model.Hash, location.X, location.Y, location.Z, heading, true, true)); - ped.IsPersistent = true; - - return ped; - } + protected async Task SpawnPed(PedHash pedHash, Vector3 location, float heading = 0f) => await Utilities.SpawnPed(new Model(pedHash), location, heading); /// /// Spawn a properly networked vehicle that is also marked as mission entity. Since this method will also load in the model, this call must be awaited. @@ -105,25 +89,10 @@ protected async Task SpawnPed(PedHash pedHash, Vector3 location, float head /// The location of the vehicle. /// Which direction the vehicle is facing. /// The vehicle you spawned - protected async Task SpawnVehicle(VehicleHash vehicleHash, Vector3 location, float heading = 0f) - { - Model model = new Model(vehicleHash); + protected async Task SpawnVehicle(VehicleHash vehicleHash, Vector3 location, float heading = 0f) => await Utilities.SpawnVehicle(new Model(vehicleHash), location, heading); - model.Request(); - while (!model.IsLoaded) - { - model.Request(); - await BaseScript.Delay(0); - } - - Vehicle vehicle = (Vehicle)Entity.FromHandle(CreateVehicle((uint)model.Hash, location.X, location.Y, location.Z, heading, true, true)); - vehicle.IsPersistent = true; - - return vehicle; - } - /// - /// DO NOT USE. Only here for backwards compatibility with callouts that use the older API.

- /// See for the alternative implementations. + /// + /// Select a random . /// /// [Obsolete("Please use RandomUtils.GetRandomPed, this method will be removed in a future version.", true)] @@ -258,7 +227,8 @@ public virtual void OnCancelAfter() { } /// public async Task ReceiveTick() { - if (Tick != null) await Tick.Invoke(); + if (Tick != null) + await Tick.Invoke(); } ///