1
0
Fork 0
forked from Simnation/Main
Main/resources/[phone]/roadphone/client/valet.lua
2025-06-12 01:28:39 +02:00

229 lines
7.2 KiB
Lua

local inVehicle = false
local fizzPed = nil
local spawnRadius = Config.ValetRadius
local mechBlip = nil
RegisterNUICallback('searchCar', function(data, cb)
QBCore.Functions.TriggerCallback("roadphone:valet:loadVehicle", function(vehicle, coords)
if not vehicle and not coords then
return
end
if vehicle == false then
if coords then
SetNewWaypoint(coords.x, coords.y)
TriggerEvent("roadphone:sendNotification", {
apptitle = 'APP_VALET_NAME',
title = 'APP_VALET_TITLE_WAYPOINT',
img = "/public/img/Apps/valet.jpg"
})
end
return;
end
local plate = vehicle[1].plate
local gameVehicles = GetGamePool('CVehicle')
for i = 1, #gameVehicles do
local vehicle = gameVehicles[i]
if DoesEntityExist(vehicle) then
if GetVehicleNumberPlateText(vehicle) == plate then
local vehicleCoords = GetEntityCoords(vehicle)
SetNewWaypoint(vehicleCoords.x, vehicleCoords.y)
TriggerEvent("roadphone:sendNotification", {
apptitle = "APP_VALET_NAME",
title = "APP_VALET_TITLE_WAYPOINT",
img = "/public/img/Apps/valet.jpg"
})
cb('ok')
return
end
end
end
TriggerEvent("roadphone:sendNotification", {
apptitle = "APP_VALET_NAME",
title = "APP_VALET_TITLE_CARNOTOUT",
img = "/public/img/Apps/valet.jpg"
})
end, data.plate)
cb('ok')
end)
-- RegisterNUICallback("deliverormarkcar", function(data, cb)
-- QBCore.Functions.TriggerCallback("roadphone:valet:loadVehicle", function(vehicle, coords)
-- if not vehicle and not coords then
-- return
-- end
-- if vehicle == false then
-- if coords then
-- SetNewWaypoint(coords.x, coords.y)
-- TriggerEvent("roadphone:sendNotification", {
-- apptitle = 'APP_VALET_NAME',
-- title = 'APP_VALET_TITLE_WAYPOINT',
-- img = "/public/img/Apps/valet.jpg"
-- })
-- end
-- return;
-- end
-- local plate = vehicle[1].plate
-- local gameVehicles = GetGamePool('CVehicle')
-- for i = 1, #gameVehicles do
-- local vehicle = gameVehicles[i]
-- if DoesEntityExist(vehicle) then
-- if GetVehicleNumberPlateText(vehicle) == plate then
-- local vehicleCoords = GetEntityCoords(vehicle)
-- SetNewWaypoint(vehicleCoords.x, vehicleCoords.y)
-- TriggerEvent("roadphone:sendNotification", {
-- apptitle = 'APP_VALET_NAME',
-- title = 'APP_VALET_TITLE_WAYPOINT',
-- img = "/public/img/Apps/valet.jpg"
-- })
-- cb('ok')
-- return
-- end
-- end
-- end
-- QBCore.Functions.TriggerCallback("roadphone:valet:checkMoney", function(cb)
-- if cb then
-- SpawnVehicle(vehicle[1].vehicle, plate, json.decode(vehicle[1].mods))
-- end
-- end)
-- end, data.plate)
-- cb('ok')
-- end)
function SpawnVehicle(vehicle, plate, mods)
print("RoadPhone Valet: "..plate)
local player = PlayerPedId()
local playerPos = GetEntityCoords(player)
local found, spawnPos, spawnHeading = GetClosestVehicleNodeWithHeading(playerPos.x + math.random(-100, 100),
playerPos.y + math.random(-100, 100), playerPos.z, 0, 3, 0)
local driverhash = GetHashKey(Config.ValetPedModel)
local vehhash = GetHashKey(vehicle)
while not HasModelLoaded(driverhash) and RequestModel(driverhash) or not HasModelLoaded(vehhash) and
RequestModel(vehhash) do
RequestModel(driverhash)
RequestModel(vehhash)
Wait(0)
end
Wait(500)
QBCore.Functions.SpawnVehicle(vehicle, function(callback_vehicle)
QBCore.Functions.SetVehicleProperties(callback_vehicle, mods)
SetVehicleEngineOn(callback_vehicle, true)
fizzPed = CreatePedInsideVehicle(callback_vehicle, 26, driverhash, -1, true, false)
mechBlip = AddBlipForEntity(callback_vehicle)
SetBlipSprite(mechBlip, 225) -- Blip Spawning.
SetBlipFlashes(mechBlip, true)
SetBlipColour(mechBlip, 0)
SetBlipFlashes(mechBlip, false)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(plate)
EndTextCommandSetBlipName(mechBlip)
inVehicle = true
GiveCarKeys(GetVehicleNumberPlateText(callback_vehicle), vehicle.model)
TriggerServerEvent("roadphone:valetCarSetOutside", plate, vehicle)
TaskVehicle(callback_vehicle)
end, spawnPos, true)
end
function TaskVehicle(vehicle)
while inVehicle do
Wait(750)
local pedcoords = GetEntityCoords(PlayerPedId())
local plycoords = GetEntityCoords(fizzPed)
local dist = GetDistanceBetweenCoords(plycoords, pedcoords.x, pedcoords.y, pedcoords.z, false)
if dist <= 25.0 then
TaskVehicleDriveToCoord(fizzPed, vehicle, pedcoords.x, pedcoords.y, pedcoords.z, 10.0, 1, vehhash, 786475,
5.0, 1)
SetVehicleFixed(vehicle)
if dist <= 7.5 then
LeaveIt(vehicle)
break
else
Wait(500)
end
else
TaskVehicleDriveToCoord(fizzPed, vehicle, pedcoords.x, pedcoords.y, pedcoords.z, 15.0, 1, vehhash, 786475,
5.0, 1)
Wait(500)
end
end
end
function LeaveIt(vehicle)
TaskLeaveVehicle(fizzPed, vehicle, 14)
inVehicle = false
while IsPedInAnyVehicle(fizzPed, false) do
Wait(0)
end
Wait(500)
TaskWanderStandard(fizzPed, 10.0, 10)
Wait(10000)
DeleteEntity(fizzPed)
RemoveBlip(mechBlip)
mechBlip = nil
fizzPed = nil
end
RegisterNUICallback("getCars", function(data, cb)
QBCore.Functions.TriggerCallback("roadphone:valet:getCars", function(data)
for i = 1, #data do
if(data[i]) then
local vehiclename = data[i].vehicle
data[i].vehicle = {}
data[i].vehicle.model = vehiclename
end
end
SendNUIMessage({
event = "setValetCars",
cars = data
})
end)
cb('ok')
end)
if Config.CarDebug then
CreateThread(function()
while true do
Wait(8000)
if IsPedInAnyVehicle(PlayerPedId(), false) then
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
print("[DEBUG] Car Name: " .. GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)))
end
end
end)
end