diff --git a/README.md b/README.md index 7f01f01..b1dba3d 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,8 @@ The basic commands present are : - Detach the vehicle from the trailer - Open and close the access ramp to the Tr2 (one large tow truck for several vehicles) - Slide the ramp to access the second floor of the Tr2 -- Install and remove a ramp for easier access to the vehicle \ No newline at end of file +- Install and remove a ramp for easier access to the vehicle + +# Update +- Global redesign for a better optimization +- Addition of a return of the trailers \ No newline at end of file diff --git a/client/FRAMEWORK/loader.lua b/client/FRAMEWORK/loader.lua deleted file mode 100644 index 8ef98a3..0000000 --- a/client/FRAMEWORK/loader.lua +++ /dev/null @@ -1,41 +0,0 @@ -if Config.UseESX then - ESX = nil -- Global ESX object - - Citizen.CreateThread(function() - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) - ESX = obj - end) - Citizen.Wait(500) - end - - while ESX.GetPlayerData().job == nil do - Citizen.Wait(100) - end - - ESX.PlayerData.job = ESX.GetPlayerData().job - end) - - RegisterNetEvent('esx:playerLoaded') - AddEventHandler('esx:playerLoaded', function(xPlayer) - ESX.PlayerData = xPlayer - end) - - RegisterNetEvent('esx:setJob') - AddEventHandler('esx:setJob', function(job) - ESX.PlayerData.job = job - end) -elseif Config.UseQBCore then - PlayerJob = {} - QBCore = exports['qb-core']:GetCoreObject() - - RegisterNetEvent('QBCore:Client:OnPlayerLoaded') - AddEventHandler('QBCore:Client:OnPlayerLoaded', function() - PlayerJob = QBCore.Functions.GetPlayerData().job - end) - - RegisterNetEvent('QBCore:Client:OnJobUpdate') - AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo) - PlayerJob = JobInfo - end) -end diff --git a/client/cl_main.lua b/client/cl_main.lua index 65f5088..9df9fa0 100644 --- a/client/cl_main.lua +++ b/client/cl_main.lua @@ -1,258 +1,196 @@ +local notfindtrailer = true +local globalSearch = function() + return GetVehicleInDirection(GetEntityCoords(PlayerPedId()), GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 20.0, 0.0)) +end +local TrailerBuy = {} TRAIL = {} TRAIL.Menu = {} -TRAIL.Menu.IsInService = false -TRAIL.Menu.IsOpen = false -TRAIL.Menu.Main = RageUI.CreateMenu("", "Magasin", nil, nil, "root_cause", "shopui_title_elitastravel") - -TRAIL.Menu.Main.Closed = function() - TRAIL.Menu.Close() -end +TRAIL.Menu.Main = RageUI.CreateMenu("", "Trailer Shop", nil, nil, "root_cause", "shopui_title_elitastravel") +TRAIL.Menu.RefoundTrailer = RageUI.CreateMenu("", "Refound Trailer", nil, nil, "root_cause", "shopui_title_elitastravel") -function TRAIL.Menu.Close() - TRAIL.Menu.IsOpen = false - RageUI.CloseAll() - RageUI.Visible(TRAIL.Menu.Main, false) +if Config.FrameWork == "ESX" then + ESX = nil + Citizen.CreateThread(function() + while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(500) end + ESX.PlayerData.job = ESX.GetPlayerData().job + end) + RegisterNetEvent('esx:playerLoaded') + AddEventHandler('esx:playerLoaded', function(xPlayer) + ESX.PlayerData = xPlayer + end) + RegisterNetEvent('esx:setJob') + AddEventHandler('esx:setJob', function(job) + ESX.PlayerData.job = job + end) +elseif Config.FrameWork == "QBCore" then + PlayerJob = {} + QBCore = exports['qb-core']:GetCoreObject() + RegisterNetEvent('QBCore:Client:OnPlayerLoaded') + AddEventHandler('QBCore:Client:OnPlayerLoaded', function() + PlayerJob = QBCore.Functions.GetPlayerData().job + end) + RegisterNetEvent('QBCore:Client:OnJobUpdate') + AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo) + PlayerJob = JobInfo + end) end Citizen.CreateThread(function() for k, v in pairs (Config.TrailerShop) do - local blip = AddBlipForCoord(v.npccoords.x, v.npccoords.y, v.npccoords.z) SetBlipSprite (blip, 479) SetBlipDisplay(blip, 4) SetBlipScale(blip, 0.75) SetBlipColour (blip, 45) SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName("STRING") AddTextComponentString(Config.Lang["Blip"]) EndTextCommandSetBlipName(blip) end end) +function OpenMenuTrailer(index) + RageUI.Visible(TRAIL.Menu.Main, not RageUI.Visible(TRAIL.Menu.Main)) + while RageUI.Visible(TRAIL.Menu.Main) do + RageUI.IsVisible(TRAIL.Menu.Main, function() + for k, v in pairs(Config.TrailerShop[index].trailertobuy) do + RageUI.Button(Config.Lang["BuyFor"] .. v.price.. ' $ '.. v.label, nil, {}, true, { + onSelected = function() + RageUI.Visible(TRAIL.Menu.Main, not RageUI.Visible(TRAIL.Menu.Main)) + SpawnRemorque(v.label, v.name, v.coordsspawn, v.heading, v.price) + end, + }) + end + if #TrailerBuy > 0 then + RageUI.Button(Config.Lang["refoundTrailer"], "", {}, true, { + onSelected = function() + RageUI.Visible(TRAIL.Menu.Main, not RageUI.Visible(TRAIL.Menu.Main)) + RefoundTrailer() + end + }) + end + end) + Citizen.Wait(0) + end +end -function TRAIL.Menu.Open(index) - Citizen.CreateThread(function() - while TRAIL.Menu.IsOpen do - RageUI.IsVisible(TRAIL.Menu.Main, function() - for k, v in pairs(Config.TrailerShop[index].trailertobuy) do - RageUI.Button(Config.Lang["BuyFor"] .. v.price.. ' $ '.. v.label, nil, {}, true, { - onSelected = function() - SpawnRemorque(v.label, v.name, v.coordsspawn, v.heading, v.price) - RageUI.CloseAll() - end, - }) +function RefoundTrailer() + TrailerFound = {} + for k, v in pairs(GetGamePool("CVehicle")) do + for x, w in pairs(TrailerBuy) do + if w == v then + local distanceToVehicle = GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), GetEntityCoords(v), true) + if distanceToVehicle < 20 then + table.insert(TrailerFound, v) end - end) - Citizen.Wait(1) + end end - end) + end + RageUI.Visible(TRAIL.Menu.RefoundTrailer, not RageUI.Visible(TRAIL.Menu.RefoundTrailer)) + while RageUI.Visible(TRAIL.Menu.RefoundTrailer) do + RageUI.IsVisible(TRAIL.Menu.RefoundTrailer, function() + for k, v in pairs(TrailerFound) do + RageUI.Button("Retourn ["..v.."]", nil, {}, true, { + onSelected = function() + RageUI.Visible(TRAIL.Menu.RefoundTrailer, not RageUI.Visible(TRAIL.Menu.RefoundTrailer)) + DeleteEntity(v) + TriggerServerEvent("az_trailer:refound") + end, + onActive = function() + local entcoords = GetEntityCoords(v) + DrawMarker(20, entcoords.x, entcoords.y, entcoords.z + 1.1, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.3, 0., 0.3, 255, 255, 255, 200, 1, true, 2, 0, nil, nil, 0) + end + }) + end + end) + Citizen.Wait(0) + end end function SpawnRemorque(label, spawnname, coords, heading, price) - if Config.UseESX then + if Config.FrameWork == "ESX" then ESX.TriggerServerCallback('az_trail:buyTrailer', function(canbuy) if canbuy then - ESX.ShowNotification(Config.Lang["YouBuy"]..label.. Config.Lang["For"]..price..' $') + Config.SendNotification(Config.Lang["YouBuy"]..label.. Config.Lang["For"]..price..' $') ESX.Game.SpawnVehicle(spawnname, coords, heading, function(vehicle) + SetEntityHeading(vehicle, heading) SetVehicleOnGroundProperly(vehicle) + table.insert(TrailerBuy, vehicle) end) else - ESX.ShowNotification(Config.Lang["CantBuy"]) + Config.SendNotification(Config.Lang["CantBuy"]) end end, price) - elseif Config.UseQBCore then + elseif Config.FrameWork == "QBCore" then QBCore.Functions.TriggerCallback('az_trail:buyTrailer', function(canbuy) if canbuy then - QBCore.Functions.Notify(Config.Lang["YouBuy"]..label.. Config.Lang["For"]..price..' $', "success") + Config.SendNotification(Config.Lang["YouBuy"]..label.. Config.Lang["For"]..price..' $') QBCore.Functions.SpawnVehicle(spawnname, function(vehicle) SetEntityHeading(vehicle, heading) SetVehicleOnGroundProperly(vehicle) + table.insert(TrailerBuy, vehicle) end, coords, true) else - QBCore.Functions.Notify(Config.Lang["CantBuy"], "error") + Config.SendNotification(Config.Lang["CantBuy"]) end end, price) end end local npcspawn = false -local lastcoords = nil -local notshown = true Citizen.CreateThread(function() while true do local wait = 2000 - local playercoords = GetEntityCoords(GetPlayerPed(-1)) + local playercoords = GetEntityCoords(PlayerPedId()) for k, v in pairs(Config.TrailerShop) do if GetDistanceBetweenCoords(playercoords, v.npccoords, true) < 50 and not npcspawn then - lastshop = true - lastcoords = v.npccoords - CreatePNJ(v.npccoords, v.heading, v.ped, nil, true) + RequestModel(GetHashKey(v.ped)) + while not HasModelLoaded(GetHashKey(v.ped)) do + Citizen.Wait(0) + end + TrailerPed = CreatePed(7,GetHashKey(v.ped),v.npccoords.x, v.npccoords.y, v.npccoords.z - 1, v.heading,0,true,true) + FreezeEntityPosition(TrailerPed, true) + SetBlockingOfNonTemporaryEvents(TrailerPed, 1) npcspawn = true elseif GetDistanceBetweenCoords(playercoords, v.npccoords, true) < 2 then wait = 0 - if Config.UseESX then - ESX.ShowHelpNotification(Config.Lang["PressToOpen"]) - if IsControlJustReleased(0, 38) then - if v.job == ESX.PlayerData.job.name or v.job == 'none' then - inmenu = true - OpenMenuTrailer(k) - else - ESX.ShowNotification(Config.Lang["NotGoodJob"]) - end - end - elseif Config.UseQBCore then - if notshown then - notshown = false - QBCore.Functions.Notify(Config.Lang["PressToOpen"], "success") - end - if IsControlJustReleased(0, 38) then - if PlayerJob.name == v.job or v.job == 'none' then - inmenu = true - OpenMenuTrailer(k) - else - QBCore.Functions.Notify(Config.Lang["NotGoodJob"], "error") - end + Config.ShowHelpNotification(Config.Lang["PressToOpen"]) + if IsControlJustReleased(0, 38) then + if v.job == Config.GetJob() or v.job == 'none' then + OpenMenuTrailer(k) + else + Config.SendNotification(Config.Lang["NotGoodJob"]) end end - elseif GetDistanceBetweenCoords(playercoords, lastcoords, true) > 2 and inmenu then - wait = 2000 - inmenu = false elseif GetDistanceBetweenCoords(playercoords, lastcoords, true) > 100 and lastshop then DeleteEntity(MissionPed) npcspawn = false - lastcoords = nil - wait = 2000 - inmenu = false end end Citizen.Wait(wait) end end) -function CreatePNJ(coords, heading, ped, scenario, freeze) - MissionPed = nil - RequestModel(GetHashKey(ped)) - while not HasModelLoaded(GetHashKey(ped)) do - Citizen.Wait(0) - end - MissionPed = CreatePed(7,GetHashKey(ped),coords.x, coords.y, coords.z - 1, heading,0,true,true) - if scenario ~= nil then - TaskStartScenarioInPlace(MissionPed, scenario, 0, false) - end - if freeze then - FreezeEntityPosition(MissionPed, true) - SetBlockingOfNonTemporaryEvents(MissionPed, 1) - end -end - -function OpenMenuTrailer(index) - RageUI.CloseAll() - RageUI.Visible(TRAIL.Menu.Main, not RageUI.Visible(TRAIL.Menu.Main)) - TRAIL.Menu.IsOpen = not TRAIL.Menu.IsOpen - TRAIL.Menu.Open(index) -end - -notfindtrailer = true -RegisterCommand(Config.AttachCommand, function() - local ped = GetPlayerPed(-1) - local veh = GetVehiclePedIsIn(ped) - local havetobreak = false - if veh ~= nil and veh ~= 0 then - trailerfind = nil - local belowFaxMachine = GetOffsetFromEntityInWorldCoords(veh, 1.0, 0.0, -1.0) - local boatCoordsInWorldLol = GetEntityCoords(veh) - havefindclass = false - testnb = 0.0 - while notfindtrailer do - GetVehicleInDirection(vector3(boatCoordsInWorldLol.x, boatCoordsInWorldLol.y, boatCoordsInWorldLol.z), vector3(belowFaxMachine.x, belowFaxMachine.y, belowFaxMachine.z - testnb)) - testnb = testnb + 0.1 - if not startdecompte then - startdecompte = true - Citizen.SetTimeout(5000, function() - if trailerfind ~= 0 and trailerfind ~= nil then - startdecompte = false - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") - end - havetobreak = true - end - end) - end - if havetobreak then - break - end - Citizen.Wait(0) - end - if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then - for k, v in pairs(Config.VehicleCanTrail) do - if v.name == GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) then - for x, w in pairs(v.class) do - if w == GetVehicleClass(veh) then - havefindclass = true - end - end - if havefindclass then - AttachEntityToEntity(veh, trailerfind, GetEntityBoneIndexByName(trailerfind, 'chassis'), GetOffsetFromEntityGivenWorldCoords(trailerfind, boatCoordsInWorldLol), 0.0, 0.0, 0.0, false, false, true, false, 20, true) - TaskLeaveVehicle(ped, veh, 64) - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["CantSetThisType"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["CantSetThisType"], "error") - end - end - end - end - trailerfind = nil - notfindtrailer = true - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") - end - end - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["NotInVehicle"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["NotInVehicle"], "error") - end - end -end, false) - spawnarampe = false RegisterCommand('setrampe', function() if not spawnarampe then spawnarampe = true - local ped = GetPlayerPed(-1) - trailerfind = nil - local coordA = GetEntityCoords(GetPlayerPed(-1), 1) - local coordB = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 20.0, 0.0) - GetVehicleInDirection(coordA, coordB) + local ped = PlayerPedId() + local coordA = GetEntityCoords(PlayerPedId(), 1) + local coordB = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 20.0, 0.0) + local trailerfind = GetVehicleInDirection(coordA, coordB) if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then - local playercoords = GetEntityCoords(GetPlayerPed(-1)) + local playercoords = GetEntityCoords(PlayerPedId()) rampe = CreateObject(GetHashKey('prop_water_ramp_02'), playercoords.x, playercoords.y, playercoords.z - 1.4, false, false, false) - SetEntityHeading(rampe, GetEntityHeading(GetPlayerPed(-1))) + SetEntityHeading(rampe, GetEntityHeading(PlayerPedId())) trailerfind = nil notfindtrailer = true else spawnarampe = false - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") - end + Config.SendNotification(Config.Lang["TrailerNotFind"]) end else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["RampeAlreadySet"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["RampeAlreadySet"], "error") - end + Config.SendNotification(Config.Lang["RampeAlreadySet"]) end end, false) @@ -263,94 +201,133 @@ RegisterCommand('deleterampe', function() end end, false) -RegisterCommand('openrampe', function() - local ped = GetPlayerPed(-1) - trailerfind = nil - local coordA = GetEntityCoords(GetPlayerPed(-1), 1) - local coordB = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 20.0, 0.0) - GetVehicleInDirection(coordA, coordB) - if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then - if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then - SetVehicleDoorOpen(trailerfind, 4, false, false) +local CommandTable = { + ["attachtrailer"] = function() + local veh = GetVehiclePedIsIn(PlayerPedId()) + local havetobreak = false + if veh ~= nil and veh ~= 0 then + local belowFaxMachine = GetOffsetFromEntityInWorldCoords(veh, 1.0, 0.0, -1.0) + local boatCoordsInWorldLol = GetEntityCoords(veh) + havefindclass = false + testnb = 0.0 + while notfindtrailer do + local trailerfind = GetVehicleInDirection(vector3(boatCoordsInWorldLol.x, boatCoordsInWorldLol.y, boatCoordsInWorldLol.z), vector3(belowFaxMachine.x, belowFaxMachine.y, belowFaxMachine.z - testnb)) + testnb = testnb + 0.1 + if not startdecompte then + startdecompte = true + Citizen.SetTimeout(5000, function() + if trailerfind ~= 0 and trailerfind ~= nil then + startdecompte = false + Config.SendNotification(Config.Lang["TrailerNotFind"]) + havetobreak = true + end + end) + end + if havetobreak then + break + end + Citizen.Wait(0) + end + if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then + for k, v in pairs(Config.VehicleCanTrail) do + if v.name == GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) then + for x, w in pairs(v.class) do + if w == GetVehicleClass(veh) then + havefindclass = true + end + end + if havefindclass then + AttachEntityToEntity(veh, trailerfind, GetEntityBoneIndexByName(trailerfind, 'chassis'), GetOffsetFromEntityGivenWorldCoords(trailerfind, boatCoordsInWorldLol), 0.0, 0.0, 0.0, false, false, true, false, 20, true) + TaskLeaveVehicle(PlayerPedId(), veh, 64) + else + Config.SendNotification(Config.Lang["CantSetThisType"]) + end + end + end + trailerfind = nil + notfindtrailer = true + else + Config.SendNotification(Config.Lang["TrailerNotFind"]) + end + else + Config.SendNotification(Config.Lang["NotInVehicle"]) end - trailerfind = nil - notfindtrailer = true - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") + end, + ["detachtrailer"] = function() + local veh = GetVehiclePedIsIn(PlayerPedId()) + if IsPedInAnyVehicle(PlayerPedId(), true) then + local veh = GetVehiclePedIsIn(PlayerPedId()) + if DoesEntityExist(veh) and IsEntityAttached(veh) then + DetachEntity(veh, true, true) + notfindtrailer = true + trailerfind = nil + else + Config.SendNotification(Config.Lang["NoVehicleSet"]) + end + else + Config.SendNotification(Config.Lang["NotInVehicle"]) end - end -end, false) - -RegisterCommand('openremorque', function() - local ped = GetPlayerPed(-1) - trailerfind = nil - local coordA = GetEntityCoords(GetPlayerPed(-1), 1) - local coordB = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 20.0, 0.0) - GetVehicleInDirection(coordA, coordB) - if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then - if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then - SetVehicleDoorOpen(trailerfind, 5, false, false) + end, + ["openrampetr2"] = function() + local trailerfind = globalSearch() + if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then + if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then + SetVehicleDoorOpen(trailerfind, 4, false, false) + end + trailerfind = nil + notfindtrailer = true + else + Config.SendNotification(Config.Lang["TrailerNotFind"]) end - trailerfind = nil - notfindtrailer = true - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") + end, + ["closerampetr2"] = function() + local trailerfind = globalSearch() + if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then + if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then + SetVehicleDoorShut(trailerfind, 4, false, false) + end + trailerfind = nil + notfindtrailer = true + else + Config.SendNotification(Config.Lang["TrailerNotFind"]) end - end -end, false) - -RegisterCommand('closerampe', function() - local ped = GetPlayerPed(-1) - trailerfind = nil - local coordA = GetEntityCoords(GetPlayerPed(-1), 1) - local coordB = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 20.0, 0.0) - GetVehicleInDirection(coordA, coordB) - if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then - if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then - SetVehicleDoorShut(trailerfind, 4, false, false) + end, + ["opentrunktr2"] = function() + local trailerfind = globalSearch() + if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then + if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then + SetVehicleDoorOpen(trailerfind, 5, false, false) + end + trailerfind = nil + notfindtrailer = true + else + Config.SendNotification(Config.Lang["TrailerNotFind"]) end - trailerfind = nil - notfindtrailer = true - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") + end, + ["closetrunktr2"] = function() + local trailerfind = globalSearch() + if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then + if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then + SetVehicleDoorShut(trailerfind, 5, false, false) + end + trailerfind = nil + notfindtrailer = true + else + Config.SendNotification(Config.Lang["TrailerNotFind"]) end - end -end, false) + end, +} -RegisterCommand('closeremorque', function() - local ped = GetPlayerPed(-1) - trailerfind = nil - local coordA = GetEntityCoords(GetPlayerPed(-1), 1) - local coordB = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 20.0, 0.0) - GetVehicleInDirection(coordA, coordB) - if tonumber(trailerfind) ~= 0 and trailerfind ~= nil then - if GetDisplayNameFromVehicleModel(GetEntityModel(trailerfind)) == 'TRAILER' then - SetVehicleDoorShut(trailerfind, 5, false, false) - end - trailerfind = nil - notfindtrailer = true - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["TrailerNotFind"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["TrailerNotFind"], "error") - end - end -end, false) +for k, v in pairs(Config.Command) do + RegisterCommand(v, function() + CommandTable[k]() + end) +end function GetVehicleInDirection(cFrom, cTo) trailerfind = nil notfindtrailer = true - local rayHandle = CastRayPointToPoint(cFrom.x, cFrom.y, cFrom.z, cTo.x, cTo.y, cTo.z, 10, GetPlayerPed(-1), 0) + local rayHandle = CastRayPointToPoint(cFrom.x, cFrom.y, cFrom.z, cTo.x, cTo.y, cTo.z, 10, PlayerPedId(), 0) local _, _, _, _, vehicle = GetRaycastResult(rayHandle) if vehicle == 0 then notfindtrailer = true @@ -358,29 +335,5 @@ function GetVehicleInDirection(cFrom, cTo) notfindtrailer = false trailerfind = vehicle end -end - -RegisterCommand(Config.DetachCommand, function() - local ped = GetPlayerPed(-1) - local veh = GetVehiclePedIsIn(ped) - if IsPedInAnyVehicle(ped, true) then - local veh = GetVehiclePedIsIn(ped) - if DoesEntityExist(veh) and IsEntityAttached(veh) then - DetachEntity(veh, true, true) - notfindtrailer = true - trailerfind = nil - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["NoVehicleSet"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["NoVehicleSet"], "error") - end - end - else - if Config.UseESX then - ESX.ShowNotification(Config.Lang["NotInVehicle"]) - elseif Config.UseQBCore then - QBCore.Functions.Notify(Config.Lang["NotInVehicle"], "error") - end - end -end, false) + return trailerfind +end \ No newline at end of file diff --git a/config.lua b/config.lua index 367d4e9..399f948 100644 --- a/config.lua +++ b/config.lua @@ -1,7 +1,7 @@ Config = {} -Config.UseESX = true -Config.UseQBCore = false +Config.RefoundPrice = 250 +Config.FrameWork = "ESX" -- ESX or QBCore Config.TrailerShop = { [1] ={ @@ -10,8 +10,8 @@ Config.TrailerShop = { ped = 'a_f_m_downtown_01', job = 'none', trailertobuy = { - {label = 'une remorque bateau', name = 'boattrailer', price = 250, coordsspawn = vector3(-251.8, 6223.12, 31.49), heading = 311.34}, - {label = 'une remorque voiture', name = 'trailersmall', price = 250, coordsspawn = vector3(-251.09, 6223.35, 32.49), heading = 311.34} + {label = 'Boat Trailer', name = 'boattrailer', price = 250, coordsspawn = vector3(-251.8, 6223.12, 31.49), heading = 311.34}, + {label = 'Car Trailer', name = 'trailersmall', price = 250, coordsspawn = vector3(-251.09, 6223.35, 32.49), heading = 311.34} } }, } @@ -29,6 +29,7 @@ Config.VehicleCanTrail = { {name = 'BOATTRAILER', class = {14}}, {name = 'TRAILER', class = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 18, 19, 20}}, {name = 'WASTLNDR', class = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}}, + {name = 'TRAILER', class = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}} } Config.Lang = { @@ -44,8 +45,42 @@ Config.Lang = { ["BuyFor"] = 'Rent for: ', ["Blip"] = 'Rent a trailer', ["TrailerNotFind"] = 'Trailer not found', - ["NotInVehicle"] = 'You are not in a vehicle' + ["NotInVehicle"] = 'You are not in a vehicle', + + ["refoundTrailer"] = 'Refound a Trailer' } -Config.AttachCommand = 'attacherremorque' -Config.DetachCommand = 'detacherremorque' +Config.SendNotification = function(msg) + if Config.FrameWork == "ESX" then + ESX.ShowNotification(msg) + elseif Config.FrameWork == "QBCore" then + QBCore.Functions.Notify(msg, "error") + end +end + +Config.ShowHelpNotification = function(msg) + if Config.FrameWork == "ESX" then + ESX.ShowHelpNotification(msg) + elseif Config.FrameWork == "QBCore" then + print(msg) + end +end + +Config.GetJob = function() + if Config.FrameWork == "ESX" then + return ESX.PlayerData.job.name + elseif Config.FrameWork == "QBCore" then + return PlayerJob.name + end +end + +Config.Command = { + ["attachtrailer"] = "attachtrailer", + ["detachtrailer"] = "detachtrailer", + + -- TR2 TRAILER + ["openrampetr2"] = "openrampetr2", + ["opentrunktr2"] = "opentrunktr2", + ["closerampetr2"] = "closerampetr2", + ["closetrunktr2"] = "closetrunktr2", +} \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index a4a0cec..f3f77da 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -2,7 +2,7 @@ fx_version 'adamant' games { 'gta5' } description 'Az_trailer by Azeroth' -version '1.1' +version '2.0' client_scripts { 'lib/RMenu.lua', @@ -34,7 +34,6 @@ client_scripts { 'lib/menu/elements/ItemsColour.lua', 'lib/menu/elements/PanelColour.lua', - 'config.lua', 'client/**/*.lua', } diff --git a/server/sv_trail.lua b/server/sv_trail.lua index 8f9bdd5..b3f6eea 100644 --- a/server/sv_trail.lua +++ b/server/sv_trail.lua @@ -1,7 +1,5 @@ -if Config.UseESX then - ESX = nil - - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) +if Config.FrameWork == "ESX" then + ESX = exports['es_extended']:getSharedObject() ESX.RegisterServerCallback("az_trail:buyTrailer", function(source, cb, price) local xPlayer = ESX.GetPlayerFromId(source) @@ -15,7 +13,7 @@ if Config.UseESX then end end end) -elseif Config.UseQBCore then +elseif Config.FrameWork == "QBCore" then QBCore = exports['qb-core']:GetCoreObject() QBCore.Functions.CreateCallback("az_trail:buyTrailer", function(source, cb, price) @@ -29,3 +27,14 @@ elseif Config.UseQBCore then end end) end + +RegisterNetEvent("az_trailer:refound") +AddEventHandler("az_trailer:refound", function() + if Config.FrameWork == "ESX" then + local xPlayer = ESX.GetPlayerFromId(source) + xPlayer.addAccountMoney("money", Config.RefoundPrice) + elseif Config.FrameWork == "QBCore" then + local Player = QBCore.Functions.GetPlayer(source) + Player.Functions.GiveMoney("cash", Config.RefoundPrice) + end +end) \ No newline at end of file