forked from Simnation/Main
188 lines
6.1 KiB
Lua
188 lines
6.1 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
local rueckgabeMarkerActive = false
|
|
local mietFahrzeug = nil
|
|
|
|
-- Draw target zone
|
|
CreateThread(function()
|
|
exports['qb-target']:AddBoxZone("kartverleih_start", Config.MietStation.npc.spawn, 2.0, 2.0, {
|
|
name = "kartverleih_start",
|
|
heading = Config.MietStation.heading or 0.0,
|
|
debugPoly = false,
|
|
minZ = Config.MietStation.coords.z - 1.0,
|
|
maxZ = Config.MietStation.coords.z + 1.0,
|
|
}, {
|
|
options = {
|
|
{
|
|
type = "client",
|
|
event = "kartverleih:client:openMietMenu",
|
|
icon = "fa-solid fa-flag-checkered",
|
|
label = "Kart mieten"
|
|
}
|
|
},
|
|
distance = 2.5
|
|
})
|
|
end)
|
|
|
|
CreateThread(function()
|
|
while true do
|
|
Wait(0)
|
|
local ped = PlayerPedId()
|
|
local veh = GetVehiclePedIsIn(ped, false)
|
|
local pos = GetEntityCoords(ped)
|
|
local dist = #(pos - Config.MietStation.giveback)
|
|
|
|
if dist <= 2.0 and rueckgabeMarkerActive then
|
|
if veh ~= 0 and veh == mietFahrzeug then
|
|
rueckgabeMarkerActive = false
|
|
TriggerServerEvent("kartverleih:stopMiete")
|
|
Wait(5000) -- Cooldown, damit es nicht mehrfach auslöst
|
|
end
|
|
end
|
|
|
|
if dist <= 15.0 and rueckgabeMarkerActive then
|
|
DrawMarker(1, Config.MietStation.giveback.x, Config.MietStation.giveback.y, Config.MietStation.giveback.z - 1.0, 0, 0, 0, 0, 0, 0, 2.0, 2.0, 1.0, 0, 200, 100, 150, false, true, 2, false, nil, nil, false)
|
|
end
|
|
end
|
|
end)
|
|
|
|
|
|
function openMietMenu()
|
|
local options = {}
|
|
for i, fahrzeug in ipairs(Config.Fahrzeuge) do
|
|
table.insert(options, {
|
|
title = fahrzeug.label .. " - $" .. fahrzeug.price .. " / 3 Min",
|
|
description = "Modell: " .. fahrzeug.model,
|
|
onSelect = function()
|
|
askForBudget(fahrzeug)
|
|
end
|
|
})
|
|
end
|
|
lib.registerContext({
|
|
id = 'kart_menu',
|
|
title = 'Kart Verleih',
|
|
options = options
|
|
})
|
|
lib.showContext('kart_menu')
|
|
end
|
|
|
|
RegisterNetEvent("kartverleih:client:openMietMenu", function()
|
|
if rueckgabeMarkerActive then
|
|
lib.alertDialog({
|
|
header = 'Hallo USER',
|
|
content = 'Du hast bereits ein Mietvertrag am Laufen.\nEin zweiten kannst du nicht generieren.',
|
|
centered = true,
|
|
cancel = true
|
|
})
|
|
else
|
|
openMietMenu()
|
|
end
|
|
end)
|
|
|
|
|
|
function askForBudget(fahrzeug)
|
|
local input = lib.inputDialog('Zahlungsdaten', {
|
|
{ type = 'number', label = 'Maximalbetrag ($)', required = true },
|
|
{
|
|
type = 'select',
|
|
label = 'Zahlungsmethode',
|
|
options = {
|
|
{ value = 'cash', label = 'Bar' },
|
|
{ value = 'bank', label = 'Bank' }
|
|
}
|
|
}
|
|
})
|
|
|
|
if not input then return end
|
|
|
|
local maxAmount = tonumber(input[1])
|
|
local method = input[2]
|
|
|
|
TriggerServerEvent("kartverleih:startMiete", fahrzeug.model, fahrzeug.price, maxAmount, method)
|
|
end
|
|
|
|
-- Fahrzeug spawnen mit MrNewbVehicleKeys Integration
|
|
RegisterNetEvent("kartverleih:spawnVeh", function(model)
|
|
local playerPed = PlayerPedId()
|
|
local coords = GetEntityCoords(playerPed)
|
|
|
|
QBCore.Functions.SpawnVehicle(model, function(veh)
|
|
mietFahrzeug = veh
|
|
SetVehicleFuelLevel(veh, 100.0)
|
|
exports['lc_fuel']:SetFuel(veh, 100.0)
|
|
|
|
local plate = "KART" .. math.random(100, 999)
|
|
SetVehicleNumberPlateText(veh, plate)
|
|
|
|
-- Add keys using MrNewbVehicleKeys
|
|
local netId = NetworkGetNetworkIdFromEntity(veh)
|
|
TriggerServerEvent("kartverleih:giveVehicleKeys", netId, plate)
|
|
|
|
TaskWarpPedIntoVehicle(playerPed, veh, -1)
|
|
rueckgabeMarkerActive = true
|
|
end, Config.MietStation.coords, true)
|
|
end)
|
|
|
|
-- Fahrzeug despawnen mit MrNewbVehicleKeys Integration
|
|
RegisterNetEvent("kartverleih:despawnVeh", function()
|
|
if mietFahrzeug and DoesEntityExist(mietFahrzeug) then
|
|
-- Remove keys before deleting the vehicle
|
|
local plate = GetVehicleNumberPlateText(mietFahrzeug)
|
|
TriggerServerEvent("kartverleih:removeVehicleKeys", plate)
|
|
|
|
DeleteVehicle(mietFahrzeug)
|
|
mietFahrzeug = nil
|
|
end
|
|
end)
|
|
|
|
-- Mietende mit MrNewbVehicleKeys Integration
|
|
AddEventHandler('baseevents:onPlayerDied', function()
|
|
if mietFahrzeug and DoesEntityExist(mietFahrzeug) then
|
|
-- Remove keys before deleting the vehicle
|
|
local plate = GetVehicleNumberPlateText(mietFahrzeug)
|
|
TriggerServerEvent("kartverleih:removeVehicleKeys", plate)
|
|
|
|
DeleteVehicle(mietFahrzeug)
|
|
mietFahrzeug = nil
|
|
end
|
|
TriggerServerEvent("kartverleih:stopMiete")
|
|
end)
|
|
|
|
RegisterNetEvent("kartverleih:stopClientMiete", function()
|
|
if mietFahrzeug and DoesEntityExist(mietFahrzeug) then
|
|
-- Remove keys before deleting the vehicle
|
|
local plate = GetVehicleNumberPlateText(mietFahrzeug)
|
|
TriggerServerEvent("kartverleih:removeVehicleKeys", plate)
|
|
|
|
DeleteVehicle(mietFahrzeug)
|
|
mietFahrzeug = nil
|
|
end
|
|
end)
|
|
|
|
-- NPC + Blip spawnen
|
|
CreateThread(function()
|
|
local npcCfg = Config.MietStation.npc
|
|
|
|
if npcCfg and npcCfg.model then
|
|
RequestModel(npcCfg.model)
|
|
while not HasModelLoaded(npcCfg.model) do Wait(0) end
|
|
|
|
local ped = CreatePed(0, npcCfg.model, npcCfg.spawn.xyz, npcCfg.spawn.w, false, true)
|
|
SetEntityInvincible(ped, true)
|
|
SetBlockingOfNonTemporaryEvents(ped, true)
|
|
FreezeEntityPosition(ped, true)
|
|
if npcCfg.scenario then
|
|
TaskStartScenarioInPlace(ped, npcCfg.scenario, 0, true)
|
|
end
|
|
end
|
|
|
|
if Config.MietStation.blip.enabled then
|
|
local blip = AddBlipForCoord(Config.MietStation.coords)
|
|
SetBlipSprite(blip, Config.MietStation.blip.sprite)
|
|
SetBlipColour(blip, Config.MietStation.blip.colour)
|
|
SetBlipScale(blip, Config.MietStation.blip.scale)
|
|
SetBlipAsShortRange(blip, true)
|
|
BeginTextCommandSetBlipName("STRING")
|
|
AddTextComponentString(Config.MietStation.blip.label)
|
|
EndTextCommandSetBlipName(blip)
|
|
end
|
|
end)
|