#pragma warning disable CS1998 using System; using System.Collections.Generic; using System.Dynamic; using System.Runtime.InteropServices; using System.Threading.Tasks; using CitizenFX.Core; using CitizenFX.Core.Native; using Nexd.ESX.Client; using TaxiJob.Client.Extensions; using TaxiJob.Client.Handler; using TaxiJob.Shared; namespace TaxiJob.Client { public sealed class TaxiJob : BaseScript { private static TaxiJob _instance; public static readonly ClientConfig Config = new ClientConfig(); public static bool InDuty = false; public TaxiJob() { _instance = this; EventHandlers["onClientResourceStart"] += new Action(OnStart); //esx:playerLoaded } public static Task ServerCallback(string name, [Optional] dynamic args) { var source = new TaskCompletionSource(); ESX.TriggerServerCallback(name, new Action(o => { source.TrySetResult((T)o); }), args); return source.Task; } public static Task ServerCallback2Results(string name, [Optional] dynamic args) { var source = new TaskCompletionSource(); ESX.Raw.TriggerServerCallback(name, new Action((o, o1) => { dynamic data = new ExpandoObject(); data.first = o as ExpandoObject; data.second = o1 as ExpandoObject; source.TrySetResult(data); }), args); return source.Task; } public static Task SpawnVehicle(int model, Vector4 coords, bool local = false) { var source = new TaskCompletionSource(); if (local) { ESX.Game.Raw.SpawnLocalVehicle(model, coords.ToVector3(), coords.W, new Action(handle => { source.TrySetResult(new Vehicle(handle)); })); } else { ESX.Game.Raw.SpawnVehicle(model, coords.ToVector3(), coords.W, new Action(handle => { source.TrySetResult(new Vehicle(handle)); })); } return source.Task; } public static async Task GeneratePlate() { var plate = await _instance.Exports["esx_vehicleshop"].GeneratePlate(); return Convert.ToString(plate); } public static void PrintDynamic(dynamic data, string prefix = "") { foreach (var element in (data as IDictionary)) { Debug.WriteLine($"{prefix}{element.Key}: {element.Value}"); if (element.Value.GetType() == typeof(ExpandoObject)) { PrintDynamic(element.Value, prefix + "\t"); } if (element.Value.GetType() == typeof(List)) { Debug.WriteLine(prefix + "\t", string.Join(", ", element.Value)); } } } [Command("taximeter")] private void OnCommand() { Taximeter.Attributes.MeterVisible = !Taximeter.Attributes.MeterVisible; Taximeter.Update(); } private void OnStart(string resourceName) { if (API.GetCurrentResourceName() != resourceName) return; Tick += async () => { if (ESX.GetPlayerData().job.name != "taxi") return; CloakroomHandler.OnTick(); if (!InDuty) return; JobHandler.OnTick(); }; } } }