1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-26 02:34:34 +02:00
parent 3667e4358b
commit 272a450250
2 changed files with 116 additions and 8 deletions

View file

@ -131,24 +131,117 @@ function spawnRentalVehicle(model, spawnPoint, plate)
SetModelAsNoLongerNeeded(model)
end
-- Fahrzeug zurückgeben
-- Fahrzeug zurückgeben (GEÄNDERT - ohne im Auto zu sitzen)
RegisterNetEvent('vehiclerental:client:returnVehicle', function(data)
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)
-- Hole alle aktiven Mietverhältnisse des Spielers
QBCore.Functions.TriggerCallback('vehiclerental:server:getPlayerRentals', function(rentals)
if not rentals or #rentals == 0 then
QBCore.Functions.Notify('Du hast keine aktiven Mietverhältnisse!', 'error')
return
end
-- Erstelle Menü mit allen gemieteten Fahrzeugen
local options = {}
for i = 1, #rentals do
local rental = rentals[i]
local timeLeft = rental.end_time - os.time()
local timeText = ""
if timeLeft < 0 then
local hoursOverdue = math.ceil(math.abs(timeLeft) / 3600)
timeText = " (Überfällig um " .. hoursOverdue .. "h)"
else
local hoursLeft = math.floor(timeLeft / 3600)
local minutesLeft = math.floor((timeLeft % 3600) / 60)
timeText = " (" .. hoursLeft .. "h " .. minutesLeft .. "m verbleibend)"
end
table.insert(options, {
title = rental.vehicle_model .. " - " .. rental.vehicle_plate,
description = "Zurückgeben" .. timeText,
icon = 'car',
onSelect = function()
returnSpecificVehicle(rental.vehicle_plate, data.locationId)
end
})
end
lib.registerContext({
id = 'return_vehicle_menu',
title = 'Fahrzeug zurückgeben',
options = options
})
lib.showContext('return_vehicle_menu')
end)
end)
-- Spezifisches Fahrzeug zurückgeben
function returnSpecificVehicle(plate, locationId)
-- Finde das Fahrzeug in der Nähe
local playerPos = GetEntityCoords(PlayerPedId())
local vehicle = nil
local closestDistance = 50.0 -- Maximale Entfernung
if vehicle == 0 then
QBCore.Functions.Notify('Du musst in einem Fahrzeug sitzen!', 'error')
-- Suche nach dem Fahrzeug mit dem Kennzeichen
for veh in EnumerateVehicles() do
local vehPlate = GetVehicleNumberPlateText(veh)
if string.gsub(vehPlate, "%s+", "") == string.gsub(plate, "%s+", "") then
local vehPos = GetEntityCoords(veh)
local distance = #(playerPos - vehPos)
if distance < closestDistance then
vehicle = veh
closestDistance = distance
end
end
end
if not vehicle then
QBCore.Functions.Notify('Fahrzeug nicht in der Nähe gefunden! Bringe es zum Mietort zurück.', 'error')
return
end
local plate = GetVehicleNumberPlateText(vehicle)
-- Prüfe ob das Fahrzeug am richtigen Ort ist
local location = nil
for i = 1, #Config.RentalLocations do
if Config.RentalLocations[i].id == locationId then
location = Config.RentalLocations[i]
break
end
end
if location then
local returnPos = vector3(location.returnPoint.x, location.returnPoint.y, location.returnPoint.z)
local vehPos = GetEntityCoords(vehicle)
local distance = #(returnPos - vehPos)
if distance > 10.0 then
QBCore.Functions.Notify('Bringe das Fahrzeug näher zum Rückgabeort!', 'error')
return
end
end
-- Fahrzeug zurückgeben
QBCore.Functions.TriggerCallback('vehiclerental:server:returnVehicle', function(success)
if success then
DeleteVehicle(vehicle)
end
end, plate)
end)
end
-- Fahrzeug-Enumerator
function EnumerateVehicles()
return coroutine.wrap(function()
local handle, vehicle = FindFirstVehicle()
local success
repeat
coroutine.yield(vehicle)
success, vehicle = FindNextVehicle(handle)
until not success
EndFindVehicle(handle)
end)
end
-- Kennzeichen generieren
function GeneratePlate()

View file

@ -183,3 +183,18 @@ QBCore.Commands.Add('mietzeit', 'Zeige deine aktuelle Mietzeit an', {}, false, f
end
end)
end)
-- Spieler Mietverhältnisse abrufen (NEUER CALLBACK)
QBCore.Functions.CreateCallback('vehiclerental:server:getPlayerRentals', function(source, cb)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return cb(nil) end
MySQL.Async.fetchAll('SELECT * FROM vehicle_rentals WHERE citizenid = ? AND returned = FALSE', {
Player.PlayerData.citizenid
}, function(result)
if not result or #result == 0 then
return cb(nil)
end
cb(result)
end)
end)