241 lines
12 KiB
Lua
241 lines
12 KiB
Lua
local selectedDelivery = false
|
||
RegisterNUICallback('getOrder', function(data, cb)
|
||
TriggerServerEvent('codem-vehicleshop:SelectDelivery', data)
|
||
end)
|
||
|
||
function GetVehicleShopById(id)
|
||
for _,v in pairs(Config.VehicleShops) do
|
||
if v.id == id then
|
||
return v
|
||
end
|
||
end
|
||
end
|
||
|
||
RegisterNetEvent('codem-vehicleshop:SelectDelivery')
|
||
AddEventHandler('codem-vehicleshop:SelectDelivery', function(data)
|
||
if vehicleShopData then
|
||
if selectedDelivery then
|
||
print('You already have an active delivery!')
|
||
return
|
||
end
|
||
selectedDelivery = data
|
||
StartDeliveryLoop()
|
||
end
|
||
end)
|
||
|
||
function LoadModel(model, timeout)
|
||
timeout = timeout or 3000
|
||
if type(model) == "string" then
|
||
model = GetHashKey(model)
|
||
end
|
||
|
||
RequestModel(model)
|
||
local deadline = GetGameTimer() + timeout
|
||
|
||
while not HasModelLoaded(model) do
|
||
Wait(10) -- 10 ms bekle
|
||
if GetGameTimer() >= deadline then -- Süre dolduysa çık
|
||
return false
|
||
end
|
||
RequestModel(model) -- İsteği canlı tut
|
||
end
|
||
|
||
return model -- Başarıyla yüklendi
|
||
end
|
||
|
||
function CreateBlip(coords, sprite, color, scale, name, show, isEntity, entity)
|
||
if show then
|
||
local blip
|
||
if isEntity then
|
||
blip = AddBlipForEntity(entity)
|
||
else
|
||
blip = AddBlipForCoord(coords)
|
||
end
|
||
SetBlipSprite(blip, sprite)
|
||
SetBlipColour(blip, color)
|
||
SetBlipScale(blip, scale)
|
||
SetBlipAsShortRange(blip, true)
|
||
BeginTextCommandSetBlipName("STRING")
|
||
AddTextComponentString(name)
|
||
EndTextCommandSetBlipName(blip)
|
||
return blip
|
||
end
|
||
end
|
||
|
||
function StartDeliveryLoop()
|
||
|
||
local vehshop = GetVehicleShopById(vehicleShopData.id)
|
||
if vehshop then
|
||
local model = GetHashKey(vehshop.delivery.truck_model)
|
||
local trailerModel = GetHashKey('tr2')
|
||
LoadModel(model)
|
||
LoadModel(trailerModel)
|
||
|
||
local veh = CreateVehicle(model, vehshop.delivery.truckSpawnLocation.x, vehshop.delivery.truckSpawnLocation.y, vehshop.delivery.truckSpawnLocation.z, true, true)
|
||
SetEntityHeading(veh, vehshop.delivery.truckSpawnLocation.w)
|
||
local vehicleBlip = CreateBlip(false, 477, 3, 0.8, "Truck", true, true, veh)
|
||
Config.GiveVehicleKey(GetVehicleNumberPlateText(veh), GetHashKey(veh), veh)
|
||
CreateNotification(Config.Notifications.vehicle_spawned.message, Config.Notifications.vehicle_spawned.type)
|
||
local trailer = CreateVehicle(trailerModel, vehshop.delivery.trailerSpawnLocation.x, vehshop.delivery.trailerSpawnLocation.y, vehshop.delivery.trailerSpawnLocation.z, true, true)
|
||
SetEntityHeading(trailer, vehshop.delivery.trailerSpawnLocation.w)
|
||
|
||
local trailerBlip = CreateBlip(false, 479, 3, 0.8, "Vehicles Delivery Trailer", true, true, trailer)
|
||
local trailerDestinationBlip = AddBlipForCoord(vehshop.delivery.trailerSpawnLocation.x, vehshop.delivery.trailerSpawnLocation.y, vehshop.delivery.trailerSpawnLocation.z)
|
||
SetBlipColour(trailerDestinationBlip, 5)
|
||
SetBlipRoute(trailerDestinationBlip, true)
|
||
SetBlipRouteColour(trailerDestinationBlip, 5)
|
||
CloseUI()
|
||
|
||
local attach = {
|
||
{
|
||
y = 4.75,
|
||
z = 1.0,
|
||
},
|
||
{
|
||
y = 0.0,
|
||
z = 1.0,
|
||
},
|
||
{
|
||
y = -4.75,
|
||
z = 1.0,
|
||
},
|
||
{
|
||
y = 4.75,
|
||
z = 2.8,
|
||
},
|
||
{
|
||
y = 0.0,
|
||
z = 2.9,
|
||
},
|
||
{
|
||
y = -4.75,
|
||
z = 3.2,
|
||
},
|
||
}
|
||
local deliverVehModel = GetHashKey(selectedDelivery.model)
|
||
LoadModel(deliverVehModel)
|
||
for i=1,selectedDelivery.amount do
|
||
if i <= #attach then
|
||
local deliverVehicle = CreateVehicle(deliverVehModel, vehshop.delivery.trailerSpawnLocation.x, vehshop.delivery.trailerSpawnLocation.y, vehshop.delivery.trailerSpawnLocation.z, true, true)
|
||
SetEntityHeading(deliverVehicle, vehshop.delivery.trailerSpawnLocation.w)
|
||
AttachEntityToEntity(deliverVehicle, trailer, GetEntityBoneIndexByName(trailer, GetHashKey('boot')), 0.0, attach[i].y, attach[i].z, 0.0, 0.0, 0.0, false, false, false, false, 0.0, true)
|
||
end
|
||
end
|
||
hasTrailer, _trailer = GetVehicleTrailerVehicle(veh)
|
||
while _trailer ~= trailer and DoesEntityExist(veh) and selectedDelivery do
|
||
local truckCoords = GetEntityCoords(veh)
|
||
local trailerCoords = GetEntityCoords(trailer)
|
||
local dist = #(truckCoords - trailerCoords)
|
||
local cd = 2000
|
||
if dist < 20.0 then
|
||
cd = 0
|
||
hasTrailer, _trailer = GetVehicleTrailerVehicle(veh)
|
||
DrawMarker(2, trailerCoords.x, trailerCoords.y, trailerCoords.z + 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||
0.5, 0.5, 0.5, 255, 255, 255, 255, true, false, false, true, false, false, false)
|
||
end
|
||
Wait(cd)
|
||
end
|
||
RemoveBlip(trailerBlip)
|
||
RemoveBlip(trailerDestinationBlip)
|
||
CreateNotification(Config.Notifications.return_to_veh.message, Config.Notifications.return_to_veh.type)
|
||
local truckDestinationBlip = AddBlipForCoord(vehshop.delivery.truckSpawnLocation.x, vehshop.delivery.truckSpawnLocation.y, vehshop.delivery.truckSpawnLocation.z)
|
||
SetBlipColour(truckDestinationBlip, 5)
|
||
SetBlipRoute(truckDestinationBlip, true)
|
||
SetBlipRouteColour(truckDestinationBlip, 5)
|
||
local ped = PlayerPedId()
|
||
local isTextUiOpen = false
|
||
local markerData = Config.InteractionHandler.marker
|
||
while selectedDelivery do
|
||
local playerCoords = GetEntityCoords(ped)
|
||
local destinationCoords = vector3(vehshop.delivery.truckSpawnLocation.x, vehshop.delivery.truckSpawnLocation.y, vehshop.delivery.truckSpawnLocation.z)
|
||
local dist = #(playerCoords - destinationCoords)
|
||
local cd = 2000
|
||
if dist < 20.0 then
|
||
cd = 0
|
||
if dist < 4.0 then
|
||
if Config.InteractionHandler.drawtext then
|
||
DrawText3D(vehshop.delivery.truckSpawnLocation.x, vehshop.delivery.truckSpawnLocation.y, vehshop.delivery.truckSpawnLocation.z+0.3, Config.InteractionHandler.deliver_text)
|
||
end
|
||
if Config.InteractionHandler.marker then
|
||
DrawMarker(39, vehshop.delivery.truckSpawnLocation.x, vehshop.delivery.truckSpawnLocation.y, vehshop.delivery.truckSpawnLocation.z-0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.5, 1.5, 1.5, markerData.r, markerData.g, markerData.b, markerData.a, false, false, 0, true, false, false, false)
|
||
end
|
||
if not isTextUiOpen and Config.InteractionHandler.codemtextui.enable then
|
||
isTextUiOpen = true
|
||
exports["codem-textui"]:OpenTextUI(Config.InteractionHandler.deliver_text, Config.InteractionHandler.codemtextui.keytext, Config.InteractionHandler.codemtextui.theme)
|
||
end
|
||
if not isTextUiOpen and Config.InteractionHandler.okoktextui.enable then
|
||
isTextUiOpen = true
|
||
exports['okokTextUI']:Open(Config.InteractionHandler.deliver_text, Config.InteractionHandler.okoktextui.color, Config.InteractionHandler.okoktextui.position)
|
||
end
|
||
if not isTextUiOpen and Config.InteractionHandler.ethTextUI.enable then
|
||
isTextUiOpen = true
|
||
exports['eth-textUi']:Show('', Config.InteractionHandler.deliver_text)
|
||
end
|
||
if not isTextUiOpen and Config.InteractionHandler.qb_textui.enable then
|
||
isTextUiOpen = true
|
||
TriggerEvent('qb-core:client:DrawText', Config.InteractionHandler.deliver_text, 'left')
|
||
end
|
||
if not isTextUiOpen and Config.InteractionHandler.esx_textui.enable then
|
||
isTextUiOpen = true
|
||
TriggerEvent('ESX:TextUI', Config.InteractionHandler.deliver_text)
|
||
end
|
||
if IsControlJustPressed(0, Config.InteractionHandler.openKey) then
|
||
CreateNotification(Config.Notifications.delivered_vehicle.message, Config.Notifications.delivered_vehicle.type)
|
||
TriggerServerEvent('codem-vehicleshop:DeliverOrders', selectedDelivery)
|
||
selectedDelivery = false
|
||
CreateThread(function()
|
||
TaskLeaveAnyVehicle(ped, 0, 0)
|
||
RemoveBlip(truckDestinationBlip)
|
||
RemoveBlip(vehicleBlip)
|
||
if isTextUiOpen and Config.InteractionHandler.codemtextui.enable then
|
||
exports["codem-textui"]:CloseTextUI()
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.okoktextui.enable then
|
||
exports['okokTextUI']:Close()
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.ethTextUI.enable then
|
||
exports['eth-textUi']:Close()
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.esx_textui.enable then
|
||
TriggerEvent('ESX:HideUI')
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.qb_textui.enable then
|
||
TriggerEvent('qb-core:client:HideText')
|
||
isTextUiOpen = false
|
||
end
|
||
Wait(10000)
|
||
DeleteEntity(trailer)
|
||
DeleteEntity(veh)
|
||
end)
|
||
end
|
||
else
|
||
if isTextUiOpen and Config.InteractionHandler.codemtextui.enable then
|
||
exports["codem-textui"]:CloseTextUI()
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.okoktextui.enable then
|
||
exports['okokTextUI']:Close()
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.ethTextUI.enable then
|
||
exports['eth-textUi']:Close()
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.esx_textui.enable then
|
||
TriggerEvent('ESX:HideUI')
|
||
isTextUiOpen = false
|
||
end
|
||
if isTextUiOpen and Config.InteractionHandler.qb_textui.enable then
|
||
TriggerEvent('qb-core:client:HideText')
|
||
isTextUiOpen = false
|
||
end
|
||
end
|
||
end
|
||
Wait(cd)
|
||
end
|
||
end
|
||
end |