Update 07.12.2022
This commit is contained in:
@@ -7,8 +7,15 @@ using TaxiJob.Client.Extensions;
|
||||
|
||||
namespace TaxiJob.Client.Handler {
|
||||
public static class CloakroomHandler {
|
||||
public static Blip JobBlip;
|
||||
|
||||
public static void OnTick() {
|
||||
if (JobBlip == null) {
|
||||
var pos = TaxiJob.Config.Cloakroom.Position;
|
||||
JobBlip = new Blip(API.AddBlipForCoord(pos.X, pos.Y, pos.Y));
|
||||
BaseScript.TriggerEvent("esx_jobs:setBlipStyle", JobBlip.Handle);
|
||||
}
|
||||
|
||||
var dist = World.GetDistance(Game.PlayerPed.Position, TaxiJob.Config.Cloakroom.Position);
|
||||
if (dist >= TaxiJob.Config.DrawDistance) return;
|
||||
|
||||
@@ -47,8 +54,10 @@ namespace TaxiJob.Client.Handler {
|
||||
var menu = new ESX.UI.Menu(dMenu);
|
||||
|
||||
if (data.current.name == "default") {
|
||||
JobHandler.StopJob(false);
|
||||
BaseScript.TriggerEvent("skinchanger:loadSkin", skins.first);
|
||||
TaxiJob.InDuty = false;
|
||||
TaxiJob.SetServiceStatus(false);
|
||||
}
|
||||
|
||||
if (data.current.name == "work") {
|
||||
|
||||
@@ -1,38 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using CitizenFX.Core.UI;
|
||||
using Nexd.ESX.Client;
|
||||
using TaxiJob.Client.Extensions;
|
||||
using TaxiJob.Shared;
|
||||
|
||||
namespace TaxiJob.Client.Handler {
|
||||
public static class JobHandler {
|
||||
private static bool _vehicleSpawned;
|
||||
private static Vehicle _vehicle;
|
||||
private static Blip _vehicleBlip;
|
||||
private static Blip _taskBlip;
|
||||
|
||||
private static int _lastJob;
|
||||
private static bool _inJob;
|
||||
private static bool _isNpcJob;
|
||||
private static bool _arrived;
|
||||
private static bool _lookStarted;
|
||||
private static Ped _npc;
|
||||
private static int _nextSpeech;
|
||||
|
||||
private static int _lastUpdate = 0;
|
||||
private static Vector3 _lastPos = Vector3.Zero;
|
||||
private static int _requestTime = 0;
|
||||
|
||||
public static Vehicle Vehicle;
|
||||
public static bool InJob;
|
||||
public static bool PendingJob;
|
||||
public static bool IsNpcJob;
|
||||
public static Vector3 Destination;
|
||||
public static string JobId;
|
||||
|
||||
public static void RequestJob(Vector3 destination, string jobId) {
|
||||
_requestTime = Game.GameTime;
|
||||
Destination = destination;
|
||||
JobId = jobId;
|
||||
PendingJob = true;
|
||||
TaxiJob.SetServiceStatus(false);
|
||||
}
|
||||
|
||||
public static void OnTick() {
|
||||
HandleVehicleSpawner();
|
||||
HandleVehicleDeleter();
|
||||
HandleVehicleBlip();
|
||||
HandleNpcJob();
|
||||
HandleJob();
|
||||
HandleJobAcception();
|
||||
|
||||
if (!_inJob && _vehicleSpawned && _vehicleBlip == null && Game.GameTime - _lastJob >= TaxiJob.Config.TimeToNpcJob) {
|
||||
StartNpcJob();
|
||||
if (!InJob && _vehicleSpawned && _vehicleBlip == null && Game.GameTime - _lastJob >= TaxiJob.Config.TimeToNpcJob && !PendingJob) {
|
||||
IsNpcJob = true;
|
||||
_requestTime = Game.GameTime;
|
||||
PendingJob = true;
|
||||
TaxiJob.SetServiceStatus(false);
|
||||
Game.PlaySound("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
|
||||
}
|
||||
|
||||
if (Game.PlayerPed.IsDead && _inJob) StopJob();
|
||||
if (Game.PlayerPed.IsDead && InJob) StopJob();
|
||||
}
|
||||
|
||||
private static async void HandleVehicleSpawner() {
|
||||
@@ -45,34 +68,40 @@ namespace TaxiJob.Client.Handler {
|
||||
Screen.DisplayHelpTextThisFrame("Drücke ~INPUT_CONTEXT~ um das Taxi aus der Garage zu holen");
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.Context)) {
|
||||
if (!await TaxiJob.ServerCallback<bool>("esx_license:hasLicense", "drive")) {
|
||||
Notify.Error("Du hast keinen Führerschein!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ESX.Game.IsSpawnPointClear(TaxiJob.Config.VehicleSpawnPoint.ToVector3(), 5.0)) {
|
||||
Notify.Error("Ein Fahrzeug blockiert den Spawnpunkt!");
|
||||
return;
|
||||
}
|
||||
|
||||
_vehicle = await TaxiJob.SpawnVehicle(API.GetHashKey(TaxiJob.Config.VehicleModel), TaxiJob.Config.VehicleSpawnPoint);
|
||||
_vehicle.SetNumberPlateText(await TaxiJob.GeneratePlate());
|
||||
BaseScript.TriggerEvent("craftix:refuelVehicle", _vehicle.Handle);
|
||||
Game.PlayerPed.SetIntoVehicle(_vehicle, VehicleSeat.Driver);
|
||||
Vehicle = await TaxiJob.SpawnVehicle(API.GetHashKey(TaxiJob.Config.VehicleModel), TaxiJob.Config.VehicleSpawnPoint);
|
||||
Vehicle.Mods.LicensePlate = await TaxiJob.GeneratePlate();
|
||||
BaseScript.TriggerEvent("craftix:refuelVehicle", Vehicle.Handle);
|
||||
Game.PlayerPed.SetIntoVehicle(Vehicle, VehicleSeat.Driver);
|
||||
_lastJob = Game.GameTime;
|
||||
_vehicleSpawned = true;
|
||||
TaxiJob.SetServiceStatus(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleVehicleDeleter() {
|
||||
if (_vehicleSpawned) {
|
||||
if (!_vehicle.Exists() || _vehicle.IsDead) {
|
||||
if (!Vehicle.Exists() || Vehicle.IsDead) {
|
||||
_vehicleBlip?.Delete();
|
||||
StopJob();
|
||||
_vehicleSpawned = false;
|
||||
_vehicleBlip = null;
|
||||
_vehicle = null;
|
||||
Vehicle = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_vehicleSpawned || !Game.PlayerPed.IsInVehicle(_vehicle)) return;
|
||||
if (!_vehicleSpawned || !Game.PlayerPed.IsInVehicle(Vehicle)) return;
|
||||
World.DrawMarker(MarkerType.HorizontalCircleSkinny, TaxiJob.Config.VehicleDeleter, Vector3.Zero, Vector3.Zero, new Vector3(3.7f, 3.7f, 0.2f), TaxiJob.Config.VehicleSpawner.Color);
|
||||
|
||||
var dist = World.GetDistance(Game.PlayerPed.Position, TaxiJob.Config.VehicleDeleter);
|
||||
@@ -80,19 +109,21 @@ namespace TaxiJob.Client.Handler {
|
||||
|
||||
Screen.DisplayHelpTextThisFrame("Drücke ~INPUT_CONTEXT~ um das Auto in die Garage zu stellen");
|
||||
if (Game.IsControlJustReleased(0, Control.Context)) {
|
||||
_vehicle?.Delete();
|
||||
Vehicle?.Delete();
|
||||
_vehicleBlip?.Delete();
|
||||
StopJob();
|
||||
_vehicleSpawned = false;
|
||||
_vehicleBlip = null;
|
||||
_vehicle = null;
|
||||
Vehicle = null;
|
||||
Taximeter.Reset();
|
||||
TaxiJob.SetServiceStatus(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleVehicleBlip() {
|
||||
if (!_vehicleSpawned) return;
|
||||
|
||||
var inVehicle = Game.PlayerPed.IsInVehicle(_vehicle);
|
||||
var inVehicle = Game.PlayerPed.IsInVehicle(Vehicle);
|
||||
if (inVehicle && _vehicleBlip != null) {
|
||||
_lastJob = Game.GameTime;
|
||||
_vehicleBlip?.Delete();
|
||||
@@ -106,25 +137,50 @@ namespace TaxiJob.Client.Handler {
|
||||
_vehicleBlip.Name = "Dienstwagen";
|
||||
API.SetBlipDisplay(_vehicleBlip.Handle, 4);
|
||||
}
|
||||
|
||||
if (inVehicle && Game.IsControlJustReleased(0, Control.SelectCharacterFranklin)) {
|
||||
if (TaxiMenuHandler.MenuOpen) TaxiMenuHandler.CloseMenu();
|
||||
else TaxiMenuHandler.OpenMenu();
|
||||
}
|
||||
|
||||
if (inVehicle) HandleTaximeter();
|
||||
}
|
||||
|
||||
private static void HandleJob() {
|
||||
if (!_inJob || _isNpcJob) return;
|
||||
if (!InJob || IsNpcJob) return;
|
||||
|
||||
if (!_arrived) {
|
||||
if (!_arrived && _taskBlip != null) {
|
||||
if (!Game.PlayerPed.IsInVehicle()) return;
|
||||
var dist = World.GetDistance(Game.PlayerPed.Position, _taskBlip.Position);
|
||||
var dist = World.GetDistance(Game.PlayerPed.CurrentVehicle.Position, _taskBlip.Position);
|
||||
|
||||
if (dist <= 30.0 && Game.PlayerPed.CurrentVehicle.Speed <= 1) {
|
||||
_taskBlip.Delete();
|
||||
_taskBlip = null;
|
||||
_arrived = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_arrived && Game.PlayerPed.CurrentVehicle?.PassengerCount != 0) {
|
||||
_arrived = true;
|
||||
Taximeter.ActivateForClient(true);
|
||||
|
||||
_taskBlip?.Delete();
|
||||
_taskBlip = null;
|
||||
|
||||
Taximeter.Attributes.CurrentFare = "000.00";
|
||||
Taximeter.Attributes.DistanceTraveled = 0;
|
||||
Taximeter.Pause(false);
|
||||
}
|
||||
|
||||
if (_arrived && Game.PlayerPed.CurrentVehicle?.PassengerCount == 0) {
|
||||
var price = (int)Math.Round(Convert.ToSingle(Taximeter.Attributes.CurrentFare) + 0.5f);
|
||||
BaseScript.TriggerServerEvent("taxijob:server:bill", price, Taximeter.CurrentClient);
|
||||
BaseScript.TriggerServerEvent("taxijob:server:payout", (int)Math.Floor(price * 0.9f));
|
||||
StopJob();
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleNpcJob() {
|
||||
if (!_inJob || !_isNpcJob) return;
|
||||
if (!InJob || !IsNpcJob) return;
|
||||
|
||||
|
||||
if (!_arrived) {
|
||||
@@ -172,20 +228,68 @@ namespace TaxiJob.Client.Handler {
|
||||
}
|
||||
|
||||
if (dist <= 30.0 && Game.PlayerPed.CurrentVehicle.Speed <= 1) {
|
||||
_inJob = false;
|
||||
InJob = false;
|
||||
_npc.Task.LeaveVehicle(_npc.CurrentVehicle, true);
|
||||
_npc.PlayAmbientSpeech("GENERIC_THANKS");
|
||||
_npc.MarkAsNoLongerNeeded();
|
||||
_npc = null;
|
||||
|
||||
var price = (int)Math.Floor(Convert.ToSingle(Taximeter.Attributes.CurrentFare) * 0.9f);
|
||||
StopJob();
|
||||
Notify.Success("Auftrag beendet!");
|
||||
BaseScript.TriggerServerEvent("taxijob:server:payout", price);
|
||||
Notify.Success($"Auftrag beendet!\nDu hast ${price} bekommen.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleTaximeter() {
|
||||
if (!InJob || Taximeter.Attributes.MeterPause || Taximeter.Attributes.DistanceTraveled >= 15000) return;
|
||||
var current = Game.GameTime;
|
||||
if (current - _lastUpdate < 2000) return;
|
||||
_lastUpdate = current;
|
||||
var pos = Game.PlayerPed.CurrentVehicle.Position;
|
||||
if (_lastPos == Vector3.Zero) _lastPos = pos;
|
||||
Taximeter.CalculatePrice(_lastPos, pos);
|
||||
_lastPos = pos;
|
||||
}
|
||||
|
||||
private static void HandleJobAcception() {
|
||||
if (!PendingJob) return;
|
||||
Screen.DisplayHelpTextThisFrame("Neuer Auftrag!~n~~INPUT_SELECT_WEAPON_UNARMED~ Annehmen~n~~INPUT_SELECT_WEAPON_MELEE~ Ablehnen");
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.SelectWeaponUnarmed)) {
|
||||
if (IsNpcJob) StartNpcJob();
|
||||
else {
|
||||
BaseScript.TriggerServerEvent("taxijob:server:accept", true, JobId);
|
||||
StartJob();
|
||||
}
|
||||
}
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.SelectWeaponMelee) || Game.GameTime - _requestTime > 30000) {
|
||||
BaseScript.TriggerServerEvent("taxijob:server:accept", false, JobId);
|
||||
StopJob();
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartJob() {
|
||||
TaxiMenuHandler.CloseMenu();
|
||||
Taximeter.Reset(Taximeter.Attributes.MeterVisible);
|
||||
var dest = Destination;
|
||||
StopJob(false);
|
||||
TaxiJob.SetServiceStatus(false);
|
||||
|
||||
_taskBlip = new Blip(API.AddBlipForCoord(dest.X, dest.Y, dest.Z));
|
||||
_taskBlip.Name = "Kunde";
|
||||
_taskBlip.ShowRoute = true;
|
||||
|
||||
InJob = true;
|
||||
}
|
||||
|
||||
private static async void StartNpcJob() {
|
||||
Notify.Info("Neuer Auftrag!");
|
||||
StopJob();
|
||||
TaxiMenuHandler.CloseMenu();
|
||||
Taximeter.Reset(Taximeter.Attributes.MeterVisible);
|
||||
StopJob(false);
|
||||
TaxiJob.SetServiceStatus(false);
|
||||
|
||||
var target = TaxiJob.Config.Positions.Random();
|
||||
_taskBlip = new Blip(API.AddBlipForCoord(target.X, target.Y, target.Z));
|
||||
@@ -201,11 +305,13 @@ namespace TaxiJob.Client.Handler {
|
||||
_npc.SetBlockingOfNonTemporaryEvents(true);
|
||||
_npc.IsInvincible = true;
|
||||
_npc.Task.StandStill(int.MaxValue);
|
||||
_isNpcJob = true;
|
||||
_inJob = true;
|
||||
IsNpcJob = true;
|
||||
InJob = true;
|
||||
|
||||
Taximeter.Pause(false);
|
||||
}
|
||||
|
||||
private static void StopJob() {
|
||||
public static void StopJob(bool updateService = true) {
|
||||
_taskBlip?.Delete();
|
||||
_taskBlip = null;
|
||||
|
||||
@@ -213,12 +319,19 @@ namespace TaxiJob.Client.Handler {
|
||||
_npc?.MarkAsNoLongerNeeded();
|
||||
_npc = null;
|
||||
|
||||
_inJob = false;
|
||||
_isNpcJob = false;
|
||||
InJob = false;
|
||||
IsNpcJob = false;
|
||||
_arrived = false;
|
||||
_lookStarted = false;
|
||||
_lastJob = Game.GameTime;
|
||||
PendingJob = false;
|
||||
Destination = Vector3.Zero;
|
||||
JobId = null;
|
||||
|
||||
Taximeter.Pause(true);
|
||||
if (updateService) TaxiJob.SetServiceStatus(true);
|
||||
Taximeter.ActivateForClient(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
146
C#/FiveM/TaxiJob/TaxiJob.Client/Handler/NpcTaxiHandler.cs
Normal file
146
C#/FiveM/TaxiJob/TaxiJob.Client/Handler/NpcTaxiHandler.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using CitizenFX.Core.UI;
|
||||
using TaxiJob.Client.Extensions;
|
||||
|
||||
namespace TaxiJob.Client.Handler {
|
||||
public static class NpcTaxiHandler {
|
||||
public static bool IsCustomer;
|
||||
private static Vehicle _taxi;
|
||||
private static Blip _blip;
|
||||
private static Ped _driver;
|
||||
|
||||
private static bool _arrived;
|
||||
private static bool _hasDestination;
|
||||
private static Vector3 _destination;
|
||||
private static bool _atDestination;
|
||||
private static int _lastUpdate;
|
||||
private static Vector3 _lastPosition;
|
||||
private static bool _pause;
|
||||
|
||||
public static async void StartNpcJob() {
|
||||
if (IsCustomer) return;
|
||||
await BaseScript.Delay(5000);
|
||||
Notify.Info("Ein Taxi ist auf dem Weg zu ihnen!");
|
||||
var spawn = GetDistantSpawn(700);
|
||||
|
||||
// Spawn Taxi
|
||||
var model = (Model)VehicleHash.Taxi;
|
||||
await model.Load();
|
||||
_taxi = await World.CreateVehicle(model, spawn.ToVector3(), spawn.W);
|
||||
_taxi.Mods.LicensePlate = await TaxiJob.GeneratePlate();
|
||||
_taxi.AsMissionEntry();
|
||||
TaxiJob.SetFuel(_taxi, 100.0f);
|
||||
|
||||
// Blip
|
||||
_blip = new Blip(API.AddBlipForEntity(_taxi.Handle));
|
||||
_blip.Sprite = (BlipSprite)198;
|
||||
_blip.Color = BlipColor.Yellow;
|
||||
_blip.Name = "Taxi";
|
||||
|
||||
// Driver
|
||||
model = new Model(-573920724);
|
||||
await model.Load();
|
||||
_driver = await World.CreatePed(model, spawn.ToVector3());
|
||||
_driver.SetIntoVehicle(_taxi, VehicleSeat.Driver);
|
||||
_driver.CanBeTargetted = false;
|
||||
_driver.AsMissionEntry();
|
||||
|
||||
// Drive to Player
|
||||
_driver.Task.DriveTo(_taxi, World.GetNextPositionOnStreet(Game.PlayerPed.Position), 10f, 20f, 262975);
|
||||
Taximeter.Reset();
|
||||
_lastPosition = _taxi.Position;
|
||||
Taximeter.Pause(false);
|
||||
_arrived = false;
|
||||
_pause = false;
|
||||
IsCustomer = true;
|
||||
}
|
||||
|
||||
public static void OnTick() {
|
||||
if (!_driver.IsInVehicle(_taxi)) {
|
||||
TaxiJob.SetFuel(_taxi, 0.0f);
|
||||
IsCustomer = false;
|
||||
_blip?.Delete();
|
||||
_blip = null;
|
||||
Taximeter.Reset();
|
||||
}
|
||||
|
||||
if (!_arrived && Game.PlayerPed.IsInVehicle(_taxi)) {
|
||||
_arrived = true;
|
||||
_atDestination = false;
|
||||
_hasDestination = false;
|
||||
_driver.PlayAmbientSpeech("GENERIC_HI");
|
||||
_blip?.Delete();
|
||||
_blip = null;
|
||||
Taximeter.SetVisible(true);
|
||||
}
|
||||
|
||||
if (_arrived && !_hasDestination && World.WaypointPosition != Vector3.Zero) {
|
||||
_hasDestination = true;
|
||||
_destination = World.GetNextPositionOnStreet(World.WaypointPosition);
|
||||
_driver.Task.DriveTo(_taxi, _destination, 10f, 20f, 262975);
|
||||
}
|
||||
|
||||
if (_hasDestination && !_atDestination && World.GetDistance(_taxi.Position, _destination) <= 10.5f && !Game.PlayerPed.IsInVehicle(_taxi)) {
|
||||
_atDestination = true;
|
||||
|
||||
var price = (int)Math.Round(Convert.ToSingle(Taximeter.Attributes.CurrentFare) + 0.5f);
|
||||
BaseScript.TriggerServerEvent("taxijob:server:bill", price, Game.Player.ServerId);
|
||||
|
||||
Taximeter.Reset();
|
||||
}
|
||||
|
||||
if (_atDestination && World.GetDistance(_taxi.Position, Game.PlayerPed.Position) >= 5) {
|
||||
_taxi.MarkAsNoLongerNeeded();
|
||||
_driver.MarkAsNoLongerNeeded();
|
||||
|
||||
_hasDestination = false;
|
||||
_destination = Vector3.Zero;
|
||||
_atDestination = false;
|
||||
_taxi = null;
|
||||
_driver = null;
|
||||
IsCustomer = false;
|
||||
}
|
||||
|
||||
var current = Game.GameTime;
|
||||
if (current - _lastUpdate >= 2000) {
|
||||
_lastUpdate = current;
|
||||
Taximeter.CalculatePrice(_lastPosition, _taxi.Position);
|
||||
_lastPosition = _taxi.Position;
|
||||
}
|
||||
|
||||
if (!(_hasDestination && !_atDestination)) return;
|
||||
|
||||
Screen.DisplayHelpTextThisFrame("Drücke ~INPUT_VEH_SHUFFLE~ um die Fahrt " + (_pause ? "fortzusetzen" : "zu pausieren"));
|
||||
if (Game.IsControlJustReleased(0, Control.VehicleShuffle)) {
|
||||
if (_pause) {
|
||||
if (World.WaypointPosition != Vector3.Zero) _destination = World.GetNextPositionOnStreet(World.WaypointPosition);
|
||||
_driver?.Task.DriveTo(_taxi, _destination, 10f, 20f, 262975);
|
||||
}
|
||||
else {
|
||||
_driver?.Task.DriveTo(_taxi, _taxi.Position + (_taxi.ForwardVector * 20f), 10f, 5f, 262975);
|
||||
}
|
||||
_pause = !_pause;
|
||||
}
|
||||
|
||||
if (!Game.PlayerPed.IsInVehicle(_taxi)) {
|
||||
_atDestination = true;
|
||||
|
||||
var price = (int)Math.Round(Convert.ToSingle(Taximeter.Attributes.CurrentFare) + 0.5f);
|
||||
BaseScript.TriggerServerEvent("taxijob:server:bill", price, Game.Player.ServerId);
|
||||
|
||||
Taximeter.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector4 GetDistantSpawn(int distance) {
|
||||
Vector3 player = Game.PlayerPed.Position;
|
||||
Vector3 location = Vector3.Zero;
|
||||
float heading = 0f;
|
||||
int unused = 0;
|
||||
API.GetNthClosestVehicleNodeWithHeading(player.X, player.Y, player.Z, distance, ref location, ref heading, ref unused, 9, 3.0f, 2.5f);
|
||||
return new Vector4(location, heading);
|
||||
}
|
||||
}
|
||||
}
|
||||
129
C#/FiveM/TaxiJob/TaxiJob.Client/Handler/TaxiMenuHandler.cs
Normal file
129
C#/FiveM/TaxiJob/TaxiJob.Client/Handler/TaxiMenuHandler.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace TaxiJob.Client.Handler {
|
||||
public class TaxiMenuHandler {
|
||||
public static bool MenuOpen = false;
|
||||
private static ESX.UI.Menu _currentMenu;
|
||||
|
||||
public static void OpenMenu() {
|
||||
var elements = new List<ESX.UI.MenuElement>();
|
||||
|
||||
if (JobHandler.InJob) {
|
||||
elements.Add(new ESX.UI.MenuElement {
|
||||
label = "Auftrag beenden",
|
||||
name = "cancel_job"
|
||||
});
|
||||
} else if (Game.PlayerPed.CurrentVehicle?.PassengerCount > 0) {
|
||||
elements.Add(new ESX.UI.MenuElement {
|
||||
label = "Auftrag starten",
|
||||
name = "start_job"
|
||||
});
|
||||
}
|
||||
|
||||
elements.Add(new ESX.UI.MenuElement {
|
||||
label = Taximeter.Attributes.MeterVisible ? "Taximeter aus" : " Taximeter an",
|
||||
name = "toggle_taximeter"
|
||||
});
|
||||
|
||||
if (Taximeter.Attributes.MeterVisible) {
|
||||
elements.AddRange(new [] {
|
||||
new ESX.UI.MenuElement {
|
||||
label = Taximeter.Attributes.MeterPause ? "Taximeter fortsetzen" : "Taximeter anhalten",
|
||||
name = "pause_taximeter"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Taximeter zurücksetzen",
|
||||
name = "reset_taximeter"
|
||||
}
|
||||
});
|
||||
|
||||
if (!JobHandler.IsNpcJob) {
|
||||
elements.Add(new ESX.UI.MenuElement {
|
||||
label = "Tarif ändern",
|
||||
name = "change_rate"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var menuData = new ESX.UI.MenuData {
|
||||
align = "top-left",
|
||||
title = "Taxi",
|
||||
elements = elements
|
||||
};
|
||||
|
||||
ESX.UI.Menu.CloseAll();
|
||||
_currentMenu = ESX.UI.Menu.Open("default", API.GetCurrentResourceName(), "taxi_menu", menuData, (dData, dMenu) => {
|
||||
var data = new ESX.UI.MenuData(dData);
|
||||
var menu = new ESX.UI.Menu(dMenu);
|
||||
|
||||
if (data.current.name == "cancel_job") {
|
||||
JobHandler.StopJob();
|
||||
menu.Close();
|
||||
}
|
||||
|
||||
if (data.current.name == "start_job") {
|
||||
if (!Game.PlayerPed.IsInVehicle(JobHandler.Vehicle)) return;
|
||||
var passanger = JobHandler.Vehicle.Passengers.First(ped => ped?.Handle != 0);
|
||||
Taximeter.CurrentClient = API.GetPlayerServerId(API.NetworkGetPlayerIndexFromPed(passanger.Handle));
|
||||
JobHandler.StartJob();
|
||||
}
|
||||
|
||||
if (data.current.name == "toggle_taximeter") {
|
||||
Taximeter.Toggle();
|
||||
OpenMenu();
|
||||
}
|
||||
|
||||
if (data.current.name == "pause_taximeter") {
|
||||
Taximeter.Pause();
|
||||
OpenMenu();
|
||||
}
|
||||
|
||||
if (data.current.name == "reset_taximeter") {
|
||||
Taximeter.Reset(Taximeter.Attributes.MeterVisible);
|
||||
}
|
||||
|
||||
if (data.current.name == "change_rate") {
|
||||
OpenRateMenu();
|
||||
}
|
||||
|
||||
}, (dData, dMenu) => {
|
||||
new ESX.UI.Menu(dMenu).Close();
|
||||
MenuOpen = false;
|
||||
});
|
||||
|
||||
MenuOpen = true;
|
||||
}
|
||||
|
||||
public static void CloseMenu() {
|
||||
if (!MenuOpen) return;
|
||||
_currentMenu.Close();
|
||||
MenuOpen = false;
|
||||
}
|
||||
|
||||
public static void OpenRateMenu() {
|
||||
var rates = new [] { 10, 15, 20 };
|
||||
|
||||
var menuData = new ESX.UI.MenuData {
|
||||
align = "top-left",
|
||||
title = "Taxi - Tarif",
|
||||
elements = rates.Select(rate => new ESX.UI.MenuElement {
|
||||
label = rate + "$",
|
||||
name = rate
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
ESX.UI.Menu.Open("default", API.GetCurrentResourceName(), "taxi_rate_menu", menuData, (dData, dMenu) => {
|
||||
Taximeter.Attributes.RateAmount = (int)dData.current.name;
|
||||
Taximeter.Update();
|
||||
new ESX.UI.Menu(dMenu).Close();
|
||||
}, (dData, dMenu) => {
|
||||
new ESX.UI.Menu(dMenu).Close();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,100 @@
|
||||
using CitizenFX.Core;
|
||||
using System.Dynamic;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
|
||||
namespace TaxiJob.Client.Handler {
|
||||
public static class Taximeter {
|
||||
public static TaximeeterAttributes Attributes { get; private set; } = new TaximeeterAttributes();
|
||||
public static TaximeterAttributes Attributes { get; private set; } = new TaximeterAttributes();
|
||||
public static int CurrentClient;
|
||||
private static bool _forClient;
|
||||
|
||||
public static void Open() {
|
||||
Attributes.MeterVisible = true;
|
||||
public static void Toggle() {
|
||||
Attributes.MeterVisible = !Attributes.MeterVisible;
|
||||
Update();
|
||||
}
|
||||
|
||||
public static void Close() {
|
||||
Attributes.MeterVisible = false;
|
||||
public static void SetVisible(bool visible) {
|
||||
Attributes.MeterVisible = visible;
|
||||
Update();
|
||||
}
|
||||
|
||||
public static void Pause(bool pause) {
|
||||
Attributes.MeterPause = pause;
|
||||
Update();
|
||||
}
|
||||
|
||||
public static void Pause() {
|
||||
Pause(!Attributes.MeterPause);
|
||||
}
|
||||
|
||||
public static void Update() {
|
||||
BaseScript.TriggerEvent("taxijob:client:nuimessage", Attributes.ToString());
|
||||
|
||||
if (CurrentClient != 0) BaseScript.TriggerServerEvent("taxijob:server:sync_meter", Attributes, CurrentClient, _forClient);
|
||||
}
|
||||
|
||||
public static void Reset() {
|
||||
Attributes = new TaximeeterAttributes();
|
||||
public static void Reset(bool visible = false) {
|
||||
Attributes = new TaximeterAttributes();
|
||||
Attributes.MeterVisible = visible;
|
||||
Update();
|
||||
}
|
||||
|
||||
public static void ActivateForClient(bool activate) {
|
||||
if (CurrentClient == 0) return;
|
||||
|
||||
_forClient = activate;
|
||||
BaseScript.TriggerServerEvent("taxijob:server:sync_meter", Attributes, CurrentClient, _forClient);
|
||||
}
|
||||
|
||||
public static void Sync(ExpandoObject attributes, bool active) {
|
||||
Attributes = new TaximeterAttributes(attributes);
|
||||
Attributes.MeterVisible = active;
|
||||
Update();
|
||||
}
|
||||
|
||||
public static void CalculatePrice(Vector3 start, Vector3 end) {
|
||||
if (Attributes.RateType != "distance" || Attributes.RateAmount == 0) return;
|
||||
|
||||
float dist = API.CalculateTravelDistanceBetweenPoints(start.X, start.Y, start.Z, end.X, end.Y, end.Z);
|
||||
Attributes.DistanceTraveled += dist;
|
||||
|
||||
float fare = Attributes.FareOnStop + (Attributes.DistanceTraveled / 1609.34f) * Attributes.RateAmount;
|
||||
Attributes.CurrentFare = (fare < 99.99f ? "0" : "") + (fare < 9.99f ? "0" : "") + fare.ToString("N2");
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class TaximeeterAttributes {
|
||||
|
||||
public sealed class TaximeterAttributes {
|
||||
public bool MeterVisible { get; set; } = false;
|
||||
public string RateType { get; set; } = "distance";
|
||||
public int RateAmount { get; set; } = 5;
|
||||
public float RateAmount { get; set; } = 10;
|
||||
public string CurrencyPrefix { get; set; } = "$";
|
||||
public string RateSuffix { get; set; } = "/km";
|
||||
public float CurrentFare { get; set; } = 0.0f;
|
||||
public int DistanceTraveled { get; set; } = 0;
|
||||
public int FareOnStop { get; set; } = 0;
|
||||
public string RateSuffix { get; set; } = "/mi";
|
||||
public string CurrentFare { get; set; } = "000.00";
|
||||
public float DistanceTraveled { get; set; } = 0;
|
||||
public float FareOnStop { get; set; } = 0;
|
||||
public bool MeterPause { get; set; } = true;
|
||||
public bool IsMoving { get; set; } = true;
|
||||
|
||||
public override string ToString() {
|
||||
return $"{{\"meterVisible\": {MeterVisible.ToString().ToLower()}, \"rateType\": \"{RateType}\", \"rateAmount\": {RateAmount}, \"currencyPrefix\": \"{CurrencyPrefix}\", \"rateSuffix\": \"{RateSuffix}\", \"currentFare\": \"{CurrentFare}\", \"distanceTraveled\": {DistanceTraveled}, \"fareOnStop\": {FareOnStop}, \"meterPause\": {MeterPause.ToString().ToLower()}, \"isMoving\": {IsMoving.ToString().ToLower()} }}";
|
||||
}
|
||||
|
||||
public TaximeterAttributes() {}
|
||||
|
||||
public TaximeterAttributes(dynamic data) {
|
||||
MeterVisible = data.MeterVisible;
|
||||
RateType = data.RateType;
|
||||
RateAmount = data.RateAmount;
|
||||
CurrencyPrefix = data.CurrencyPrefix;
|
||||
RateSuffix = data.RateSuffix;
|
||||
CurrentFare = data.CurrentFare;
|
||||
DistanceTraveled = data.DistanceTraveled;
|
||||
FareOnStop = data.FareOnStop;
|
||||
MeterPause = data.MeterPause;
|
||||
IsMoving = data.IsMoving;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user