diff --git a/resources/[carscripts]/mh_garage/client/main.lua b/resources/[carscripts]/mh_garage/client/main.lua index 0355844ec..11b2ab6fe 100644 --- a/resources/[carscripts]/mh_garage/client/main.lua +++ b/resources/[carscripts]/mh_garage/client/main.lua @@ -94,8 +94,51 @@ function AddTargetOptions(zone) icon = "fas fa-car", label = "Fahrzeug ausparken", args = zone - } + }, + if Config.Verwaltung then + { + type = "client", + event = "mh_garage:verwaltungVeh", + icon = "", + label = "Fahrzeuge Verwalten", + } + end }, distance = 2.5 }) +end + +function Notification(text, type, zone) + lib.notify({ + title = "Garage - "..zone, + description = text, + type = type, + position = 'top', + }) +end + +---------------------------- NetEvents +RegisterNetEvent('mh_jobgarage:notify') +AddEventHandler('mh_jobgarage:notify', function(title, text, type) + Notification(text, type) +end) + +function GetVehicleDamagePercentage(vehicle) + if not vehicle then return 0 end + + -- Hole die verschiedenen Gesundheitswerte + local engineHealth = GetVehicleEngineHealth(vehicle) + local bodyHealth = GetVehicleBodyHealth(vehicle) + local tankHealth = GetVehiclePetrolTankHealth(vehicle) + + -- Normalisiere die Werte (Standard-Maximalwerte: 1000.0) + local enginePercent = (engineHealth / 1000.0) * 100 + local bodyPercent = (bodyHealth / 1000.0) * 100 + local tankPercent = (tankHealth / 1000.0) * 100 + + -- Berechne Durchschnitt als Gesamtzustand + local totalHealth = (enginePercent + bodyPercent + tankPercent) / 3 + + -- Runde auf ganze Zahlen + return math.floor(totalHealth) end \ No newline at end of file diff --git a/resources/[carscripts]/mh_garage/client/retrieve.lua b/resources/[carscripts]/mh_garage/client/retrieve.lua index fd8246246..ce4cf2e73 100644 --- a/resources/[carscripts]/mh_garage/client/retrieve.lua +++ b/resources/[carscripts]/mh_garage/client/retrieve.lua @@ -1,3 +1,29 @@ RegisterNetEvent('mh_garage:retrieveVehicle') -AddEventHandler('mh_garage:retrieveVehicle', function() +AddEventHandler('mh_garage:retrieveVehicle', function(zone) + local ped = PlayerPedId() + local coords = GetEntityCoords(ped) + local random = SelectName() + + local opt = {} + + QBCore.Functions.TriggerCallback('mh_garage:CallVehicles', function(cb) + for i = 1, #cb, 1 do + table.insert(opt, { + title = cb[i].name + description = "Kennzeichen: "..cb[i].plate.."\nTankinhalt: "..cb[i].mods.fuelLevel.."%", + icon = "car", + onSelect = function() + SpawnThisVehicle(cb[i]) + end + }) + end + + lib.registerContext({ + id = "retrieveVehicle", + title = random.name, + options = opt + }) + + lib.showContext("retrieveVehicle") + end, zone.name) end) \ No newline at end of file diff --git a/resources/[carscripts]/mh_garage/client/stored.lua b/resources/[carscripts]/mh_garage/client/stored.lua index 5c3cd79f3..5aaf6f973 100644 --- a/resources/[carscripts]/mh_garage/client/stored.lua +++ b/resources/[carscripts]/mh_garage/client/stored.lua @@ -1,8 +1,7 @@ RegisterNetEvent('mh_garage:storeVehicle') AddEventHandler('mh_garage:storeVehicle', function(zone) - print("Trigger Stored Vehicle...") - print(json.encode(zone)) - local coords = GetEntityCoords(PlayerPedId()) + local ped = PlayerPedId() + local coords = GetEntityCoords(ped) local vehicles = GetGamePool('CVehicle') local random = SelectName() @@ -17,7 +16,8 @@ AddEventHandler('mh_garage:storeVehicle', function(zone) description = GetRandomCarDescription(), icon = "car", onSelect = function() - if zone.price ~= nil then + print(zone.price) + if zone.price ~= false then lib.hideContext("StoredVehicles") lib.registerContext({ @@ -30,8 +30,18 @@ AddEventHandler('mh_garage:storeVehicle', function(zone) title = "Akzeptieren", description = "Geld wird vom Bankkonto abgebucht!", onSelect = function() - lib.hideContext("thisVehicle") - StoredVehicle(vehicles[i], zone) + lib.hideContext("thisVehicle") + QBCore.Functions.TriggerCallback('mh_garage:storedVehicle', function(cb) + if cb.status then + DeleteVehicle(vehicles[i]) + Notification(cb.text, cb.type, zone.name) + else + if cb.police and Config.EnabledPolice then + exports["roadphone"]:sendDispatch("Hier hat grade jemand versucht, ein Fahrzeug einzuparken.\nDas Zündschloss sah Beschädigt aus.\nKennzeichen: "..veh.plate, 'police', nil) + end + Notification(cb.text, cb.type) + end + end, veh, zone) end }, { @@ -61,10 +71,6 @@ AddEventHandler('mh_garage:storeVehicle', function(zone) end end) -function StoredVehicle(veh, zone) - -end - function SelectName() local names = { {name = "Garagen-Guru", diff --git a/resources/[carscripts]/mh_garage/client/verwaltung.lua b/resources/[carscripts]/mh_garage/client/verwaltung.lua new file mode 100644 index 000000000..14fe3f8ac --- /dev/null +++ b/resources/[carscripts]/mh_garage/client/verwaltung.lua @@ -0,0 +1,74 @@ +RegisterNetEvent('mh_garage:verwaltungVeh') +AddEventHandler('mh_garage:verwaltungVeh', function() + QBCore.TriggerCallback('mh_garage:verwaltung', function(cb) + if cb[1] ~= nil then + local opt = {} + + for i = 1, #cb, 1 do + + local isingarage = cb[i].current_in_garage + local des = "" + + if isingarage then + des = "Bearbeite das Fahrzeug\nKennzeichen: "..cb[i].current_plate.."\nGarage: "..cb[i].current_garage, + else + des = "Bearbeite das Fahrzeug\nKennzeichen: "..cb[i].current_plate.."\nLetzte bekannte Garage: "..cb[i].current_garage, + end + + table.insert(opt, { + title = cb[i].current_name + description = des, + icon = "car", + onSelect = function() + OpenVerwaltung(cb[i]) + end + }) + end + else + lib.notify({ + title = "Fahrzeug Verwaltung", + description = "Du bist nicht im Besitz eines Fahrzeuges!", + type = "inform" + }) + end + end) +end) + +function OpenVerwaltung(vehicleInfos) + local garages = {} + for k, v in pairs(Config.Zonen) do + table.insert(garages, v.name) + end + lib.registerMenu({ + id = 'some_menu_id', + title = 'Menu title', + position = 'top-right', + onSideScroll = function(selected, scrollIndex, args) + print("Scroll: ", selected, scrollIndex, args) + end, + onSelected = function(selected, secondary, args) + if not secondary then + print("Normal button") + else + if args.isCheck then + print("Check button") + end + + if args.isScroll then + print("Scroll button") + end + end + print(selected, secondary, json.encode(args, {indent=true})) + end, + options = { + {label = "Name ändern", icon = "paper", } + {label = 'Transport to:', icon = 'arrows-up-down-left-right', values=garages}, + } + }, function(selected, scrollIndex, args) + print(selected, scrollIndex, args) + end) + + RegisterCommand('testmenu', function() + lib.showMenu('some_menu_id') + end) +end \ No newline at end of file diff --git a/resources/[carscripts]/mh_garage/config/config.lua b/resources/[carscripts]/mh_garage/config/config.lua index a734f8cd4..738a6cc38 100644 --- a/resources/[carscripts]/mh_garage/config/config.lua +++ b/resources/[carscripts]/mh_garage/config/config.lua @@ -1,7 +1,25 @@ Config = {} Config.Debug = true + Config.PriceModel = false + +Config.CallKeyVehicles = true + +Config.Verwaltung = { + garage = true, + garage_change = 1000 -- Kosten um das Fahrzeug in einer anderen Garage zu versetzen. + garage_time = 10 -- Zeit in Minuten bis das Fahrzeug in der neuen Garage ist! + + repair = false + repair_car = 600 -- Kosten wenn das Fahrzeug Repariert werden soll + repair_time = 10 --Zeit in Minuten bis das Fahrzeug Repariert ist! + + tank = false + tank_car = 300 -- Kosten wenn das Fahrzeug getankt werden soll + tank_time = 3 -- Zeit in Minuten bis das Fahrzeug voll getankt ist +} + Config.Zonen = { { name = "Meetingpoint", @@ -23,12 +41,12 @@ Config.Zonen = { Config.Log = { Webhook = "https://discord.com/api/webhooks/1366812966049288192/9ZjJC9_gLX6Fk-acf0YSW_haGWpCqG9zRGWaj0wCKLZefp8FX-GwNZBP77H6K93KfIw3", Color = { - green = 56108, - grey = 8421504, - red = 16711680, - orange = 16744192, - blue = 2061822, - purple = 11750815, + green = 56108, + grey = 8421504, + red = 16711680, + orange = 16744192, + blue = 2061822, + purple = 11750815, }, SystemName = "Evolution_State_life Log [Garage]", diff --git a/resources/[carscripts]/mh_garage/server/server.lua b/resources/[carscripts]/mh_garage/server/server.lua index e69de29bb..a3affd308 100644 --- a/resources/[carscripts]/mh_garage/server/server.lua +++ b/resources/[carscripts]/mh_garage/server/server.lua @@ -0,0 +1,118 @@ +QBCore = exports['qb-core']:GetCoreObject() + +QBCore.Functions.CreateCallback('mh_garage:storedVehicle', function(source, cb, veh, zone) + local Player = QBCore.Functions.GetPlayer(source) + + if Player ~= nil then + if Player.Functions.GetMoney('bank', zone.price) then + MySQL.query("SELECT * FROM player_vehicles WHERE citizenid = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs) + if rs[1] ~= nil then + MySQL.query("UPDATE player_vehicles SET garage = ? AND parking = ? WHERE plate = ?", {zone.name, true, veh.plate}) + DelVehParking(veh.plate) + cb({ + status = true, + text = "Fahrzeug erfolgreich eingeparkt!", + type = "success", + other = false, + police = false + }) + else + MySQL.query("SELECT * FROM vehicle_keys WHERE owner = ? AND plate = ?", {Player.PlayerData.citizenid, veh.plate}, function(rs) + if rs[1] ~= nil then + MySQL.query("UPDATE player_vehicles SET garage = ? AND parking = ? WHERE plate = ?", {zone.name, true, veh.plate}) + DelVehParking(veh.plate) + cb({ + status = true, + text = "Fahrzeug erfolgreich eingeparkt!", + type = "success", + other = true, + police = false + }) + else + cb({ + status = false, + text = "Du besitzt kein Schlüssel für dieses Fahrzeug.", + type = "warning", + other = false, + police = true + }) + end + end) + end + end) + end + end +end) + +function DelVehParking(plate) + MySQL.query("SELECT * FROM vehicle_parking WHERE plate = ?", {plate}, function(rs) + if rs[1] ~= nil then + MySQL.query("DELETE FROM vehicle_parking WHERE plate = ?", {plate}) + end + end) +end + +QBCore.Functions.CreateCallback('mh_garage:CallVehicles', function(source, cb, zone) + local _source = source + local Player = QBCore.Functions.GetPlayer(_source) + local vehicles = {} + local vehicle_keys = {} + + if Config.CallKeyVehicles then + MySQL.query("SELECT plate FROM vehicle_keys WHERE owner = ?", {Player.PlayerData.citizenid}, function(rs) + if rs[1] ~= nil then + for k, v in pairs(rs) do + table.insert(vehicle_keys, {v}) + end + end + end) + + Wait(100) + if vehicle_keys[1] ~= nil then + for k, v in pairs(vehicle_keys) do + MySQL.query("SELECT vehicle, plate, mods, name FROM player_vehicles WHERE plate = ?", {v}, function(rs) + table.insert(vehicles, { + vehicle = rs[1].vehicle, + mods = rs[1].mods, + plate = rs[1].plate, + name = rs[1].name + }) + end) + end + end + end + + MySQL.query("SELECT vehicle, plate, mods FROM player_vehicles WHERE citizenid = ? AND garage = ?", {Player.PlayerData.citizenid, zone}, function(rs) + if rs[1] ~= nil then + for k, v in pairs(rs) do + table.insert(vehicles, { + vehicle = v.vehicle, + mods = v.mods, + plate = v.plate, + name = v.name + }) + end + end + end) + + Wait(100) + cb(vehicles) +end) + +QBCore.Functions.CreateCallback('mh_garage:verwaltung', function(source, cb) + local Player = QBCore.Functions.GetPlayer(source) + local vehicles = {} + MySQL.query("SELECT * FROM player_vehicles WHERE citizenid = ?", {Player.PlayerData.citizenid}, function(rs) + if rs[1] ~= nil then + for k, v in pairs(rs) do + table.insert(vehicles, { + current_garage = v.garage, + current_in_garage = v.parking, + current_name = v.name, + current_plate = v.plate, + }) + end + end + end) + return vehicles +end) \ No newline at end of file