214 lines
11 KiB
C#
214 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using CitizenFX.Core;
|
|
using static CitizenFX.Core.Native.API;
|
|
using Nexd.ESX.Client;
|
|
|
|
namespace CardealerClient.Exhibits {
|
|
public class DigitalExhibit {
|
|
public static int DigitalCam;
|
|
public static ExhibitCar CurrentDigitalCar;
|
|
public static ExhibitCar[] DigitalExhibitCars;
|
|
|
|
public static async void HandleDigitalExhibit() {
|
|
if (CarDealer.DigitalMenuOpen) return;
|
|
CarDealer.SendNotification("Lade Katalog...");
|
|
CarDealer.DigitalMenuOpen = true;
|
|
dynamic carData = await CarDealer.ServerCallback("cardealer:getDigitals");
|
|
dynamic[] models = new dynamic[carData.Count];
|
|
DigitalExhibitCars = new ExhibitCar[carData.Count];
|
|
for (int i = 0; i < carData.Count; i++) {
|
|
models[i] = carData[i].vehicle.model;
|
|
DigitalExhibitCars[i] = new ExhibitCar(carData[i]);
|
|
}
|
|
|
|
List<string> cars = await CarDealer.GetVehicleNames(models);
|
|
if (cars.Count == 0) {
|
|
CarDealer.Notify("Es gibt zur Zeit keine Autos im Katalog!", "error");
|
|
CarDealer.DigitalMenuOpen = false;
|
|
return;
|
|
}
|
|
|
|
ESX.UI.Menu.CloseAll();
|
|
FreezeEntityPosition(GetPlayerPed(-1), true);
|
|
Vector4 loc = Config.CarSlots[0].Location;
|
|
DigitalCam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", Config.DigitalCamera.X, Config.DigitalCamera.Y,
|
|
Config.DigitalCamera.Z, 0.0f, 0.0f, Config.DigitalCamera.W, GetGameplayCamFov(), false, 0);
|
|
PointCamAtCoord(DigitalCam, loc.X, loc.Y, loc.Z + 1f);
|
|
SetCamActive(DigitalCam, true);
|
|
RenderScriptCams(true, false, 1, true, true);
|
|
ESX.UI.Menu.Raw.Open("default", GetCurrentResourceName(), "cardealer_menu",
|
|
MenuElements.GetMenu_DigitalExhibit(cars.ToArray()), new Action<dynamic, dynamic>((data, menu) => {
|
|
if (data.current.name == "car") {
|
|
ESX.Game.DeleteVehicle(CurrentDigitalCar.Vehicle.ToString());
|
|
SpawnDigitalExhibt(data.current.value);
|
|
}
|
|
|
|
if (data.current.name == "testdrive") {
|
|
DigitalTestDrive();
|
|
}
|
|
|
|
if (data.current.name == "buy") {
|
|
BuyDigitalCar();
|
|
}
|
|
}), new Action<dynamic, dynamic>((o, o1) => {
|
|
ESX.Game.DeleteVehicle(CurrentDigitalCar.Vehicle.ToString());
|
|
|
|
CurrentDigitalCar = null;
|
|
|
|
ESX.UI.Menu.Close(new ESX.UI.Menu(o1));
|
|
RenderScriptCams(false, false, 1, true, true);
|
|
SetCamActive(DigitalCam, false);
|
|
DestroyCam(DigitalCam, true);
|
|
FreezeEntityPosition(GetPlayerPed(-1), false);
|
|
CarDealer.DigitalMenuOpen = false;
|
|
}), new Action<dynamic, dynamic>((data, menu) => {
|
|
if (data.current.name == "car") {
|
|
ESX.Game.DeleteVehicle(CurrentDigitalCar.Vehicle.ToString());
|
|
SpawnDigitalExhibt(data.current.value);
|
|
menu.refresh();
|
|
}
|
|
}));
|
|
SpawnDigitalExhibt(0);
|
|
}
|
|
|
|
public static async void BuyDigitalCar() {
|
|
if (!await CarDealer.DisplayConfirmationDialog("Möchtest du dieses Fahrzeug wirklich kaufen?")) return;
|
|
|
|
bool permitted = await CarDealer.ServerCallback("cardealer:checkMoney", CurrentDigitalCar.Data.Price);
|
|
if (!permitted) {
|
|
CarDealer.SendNotification("~r~Du hast nicht genügend Geld!");
|
|
return;
|
|
}
|
|
|
|
ESX.Game.DeleteVehicle(CurrentDigitalCar.Vehicle.ToString());
|
|
ESX.UI.Menu.CloseAll();
|
|
RenderScriptCams(false, false, 1, true, true);
|
|
SetCamActive(DigitalCam, false);
|
|
DestroyCam(DigitalCam, true);
|
|
FreezeEntityPosition(GetPlayerPed(-1), false);
|
|
CarDealer.DigitalMenuOpen = false;
|
|
BaseScript.TriggerServerEvent("cardealer:transaction", CurrentDigitalCar.Data.Owner, CurrentDigitalCar.Data.Price);
|
|
BaseScript.TriggerServerEvent("cardealer:buyDigitalCar", CurrentDigitalCar.Data.Properties.Raw);
|
|
|
|
int vehicle = await CarDealer.SpawnVehicle(CurrentDigitalCar.Data.Properties.Raw.model, Config.ToVector(Config.SpawnLocation), Config.SpawnLocation.W);
|
|
ESX.Game.SetVehicleProperties(new Vehicle(vehicle), CurrentDigitalCar.Data.Properties);
|
|
SetVehicleNumberPlateText(vehicle, CurrentDigitalCar.Data.Properties.plate);
|
|
SetVehicleEngineHealth(vehicle, 1000);
|
|
SetVehicleFixed(vehicle);
|
|
SetVehicleDirtLevel(vehicle, 0);
|
|
TaskWarpPedIntoVehicle(GetPlayerPed(-1), vehicle, -1);
|
|
BaseScript.TriggerEvent("craftix:refuelVehicle", vehicle);
|
|
BaseScript.TriggerServerEvent("esx_vehicleshop:setVehicleOwned", ESX.Game.Raw.GetVehicleProperties(vehicle));
|
|
CurrentDigitalCar = null;
|
|
}
|
|
|
|
public static async void DigitalTestDrive() {
|
|
Vector3 lastPosition = GetEntityCoords(GetPlayerPed(-1), IsDecalAlive(GetPlayerPed(-1)));
|
|
Vector3 spawnCoords = Config.ToVector(Config.TestDriveLocation);
|
|
bool testDrive = true;
|
|
|
|
ESX.UI.Menu.CloseAll();
|
|
RenderScriptCams(false, false, 1, true, true);
|
|
SetCamActive(DigitalCam, false);
|
|
DestroyCam(DigitalCam, true);
|
|
FreezeEntityPosition(GetPlayerPed(-1), false);
|
|
CarDealer.DigitalMenuOpen = false;
|
|
|
|
int vehicle = await CarDealer.SpawnVehicle(CurrentDigitalCar.Data.Properties.Raw.model, spawnCoords, Config.TestDriveLocation.W);
|
|
ESX.Game.SetVehicleProperties(new Vehicle(vehicle), CurrentDigitalCar.Data.Properties);
|
|
SetVehicleOnGroundProperly(vehicle);
|
|
SetVehicleEngineHealth(vehicle, 1000);
|
|
SetVehicleFixed(vehicle);
|
|
SetVehicleDirtLevel(vehicle, 0);
|
|
SetVehicleDoorsLocked(vehicle, 1);
|
|
TaskWarpPedIntoVehicle(GetPlayerPed(-1), vehicle, -1);
|
|
SetPlayerCanDoDriveBy(PlayerId(), false);
|
|
BaseScript.TriggerEvent("craftix:refuelVehicle", vehicle);
|
|
BaseScript.TriggerEvent("crafix:dontCheckVehicle", vehicle);
|
|
CurrentDigitalCar = null;
|
|
|
|
Func<Task> handler = async () => {
|
|
if (!testDrive) return;
|
|
|
|
if (IsControlJustReleased(0, 75)) {
|
|
testDrive = false;
|
|
SetPlayerCanDoDriveBy(PlayerId(), true);
|
|
ESX.Game.DeleteVehicle(vehicle.ToString());
|
|
SetEntityCoords(GetPlayerPed(-1), lastPosition.X, lastPosition.Y, lastPosition.Z, true, false, false, false);
|
|
}
|
|
};
|
|
CarDealer.AddTickHandler(handler);
|
|
|
|
await BaseScript.Delay(Config.TestDriveTime);
|
|
CarDealer.RemoveTickHandler(handler);
|
|
if (testDrive) {
|
|
testDrive = false;
|
|
SetPlayerCanDoDriveBy(PlayerId(), true);
|
|
ESX.Game.DeleteVehicle(vehicle.ToString());
|
|
SetEntityCoords(GetPlayerPed(-1), lastPosition.X, lastPosition.Y, lastPosition.Z, true, false, false, false);
|
|
}
|
|
}
|
|
|
|
public static async void SpawnDigitalExhibt(int index) {
|
|
ExhibitCar car = DigitalExhibitCars[index];
|
|
VehicleData data = car.Data;
|
|
Exhibit exhibit = car.Exhibit;
|
|
|
|
int vehicle = await CarDealer.SpawnVehicle(data.Properties.Raw.model, Config.ToVector(exhibit.Location), exhibit.Location.W, true);
|
|
Vehicle veh = new Vehicle(vehicle);
|
|
ESX.Game.SetVehicleProperties(veh, data.Properties);
|
|
SetVehicleNumberPlateText(vehicle, data.Properties.plate);
|
|
SetEntityInvincible(vehicle, true);
|
|
SetVehicleDoorsLocked(vehicle, 2);
|
|
FreezeEntityPosition(vehicle, true);
|
|
SetVehicleOnGroundProperly(vehicle);
|
|
BaseScript.TriggerServerEvent("ls:mainCheck", data.Properties.plate, vehicle, true);
|
|
|
|
DigitalExhibitCars[index].Vehicle = vehicle;
|
|
CurrentDigitalCar = DigitalExhibitCars[index];
|
|
|
|
/*ESX.Game.Raw.SpawnLocalVehicle(data.Properties.Raw.model,
|
|
Config.ToVector(exhibit.Location), exhibit.Location.W,
|
|
new Action<int>(vehicle => {
|
|
Vehicle veh = new Vehicle(vehicle);
|
|
ESX.Game.SetVehicleProperties(veh, data.Properties);
|
|
SetVehicleNumberPlateText(vehicle, data.Properties.plate);
|
|
SetEntityInvincible(vehicle, true);
|
|
SetVehicleDoorsLocked(vehicle, 2);
|
|
FreezeEntityPosition(vehicle, true);
|
|
SetVehicleOnGroundProperly(vehicle);
|
|
CarDealer.TriggerServerEvent("ls:mainCheck", data.Properties.plate, vehicle, true);
|
|
|
|
DigitalExhibitCars[index].Vehicle = vehicle;
|
|
CurrentDigitalCar = DigitalExhibitCars[index];
|
|
})
|
|
);*/
|
|
}
|
|
|
|
public static void ShowDigitalText() {
|
|
if (CurrentDigitalCar == null) return;
|
|
|
|
float scale = 2.0f;
|
|
Exhibit exhibit = CurrentDigitalCar.Exhibit;
|
|
float x = exhibit.Location.X;
|
|
float y = exhibit.Location.Y;
|
|
float z = exhibit.Location.Z;
|
|
|
|
VehicleData data = CurrentDigitalCar.Data;
|
|
string turbo = "~r~Nein";
|
|
if (Convert.ToBoolean(data.Properties.Raw.modTurbo)) turbo = "~g~Ja";
|
|
|
|
string line2 = "[Turbo : " + turbo + "~s~] [Motor : ~r~" + data.Properties.modEngine + "~s~] [Getriebe : ~r~" + data.Properties.modTransmission + "~s~]";
|
|
string line3 = "[Federung : ~r~" + data.Properties.modSuspension + "~s~] [Panzerung : ~r~" + data.Properties.modArmor + "~s~] [Bremsen : ~r~" + data.Properties.modBrakes + "~s~]";
|
|
string line4 = "[Beschreibung : ~r~" + data.Description + "~s~]";
|
|
string line5 = "[$~r~" + data.Price + "~s~]";
|
|
|
|
CarDealer.DrawText3D(new Vector3(x, y, z + 3.5f), line5, scale, false);
|
|
CarDealer.DrawText3D(new Vector3(x, y, z + 3.2f), line4, scale, false);
|
|
CarDealer.DrawText3D(new Vector3(x, y, z + 2.9f), line3, scale, false);
|
|
CarDealer.DrawText3D(new Vector3(x, y, z + 2.5f), line2, scale, false);
|
|
}
|
|
}
|
|
} |