From cb90363227bb783b99d9e8a70a5a40b3a9746fc7 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:13:30 -0400 Subject: [PATCH 1/2] refactor: ox_lib, core exports, switch notify, network vehicles --- client/camera.lua | 145 +++++++++------------ client/main.lua | 316 +++++++++++++++++++++------------------------- fxmanifest.lua | 14 +- server/main.lua | 28 ++-- 4 files changed, 229 insertions(+), 274 deletions(-) diff --git a/client/camera.lua b/client/camera.lua index 0a68f18..88f8e30 100644 --- a/client/camera.lua +++ b/client/camera.lua @@ -61,8 +61,7 @@ local function CheckInputRotation(cam, zoomvalue) end local function HandleZoom(cam) - local lPed = PlayerPedId() - if not ( IsPedSittingInAnyVehicle( lPed ) ) then + if not ( IsPedSittingInAnyVehicle(cache.ped) ) then if IsControlJustPressed(0,241) then fov = math.max(fov - zoomspeed, fov_min) @@ -119,26 +118,23 @@ end RegisterNetEvent("Cam:ToggleCam", function() if not holdingCam then - RequestModel(GetHashKey(camModel)) - while not HasModelLoaded(GetHashKey(camModel)) do - Wait(100) - end + lib.requestModel(camModel) - local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()), 0.0, 0.0, -5.0) - local camspawned = CreateObject(GetHashKey(camModel), plyCoords.x, plyCoords.y, plyCoords.z, 1, 1, 1) + local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(cache.playerId), 0.0, 0.0, -5.0) + local camspawned = CreateObject(camModel, plyCoords.x, plyCoords.y, plyCoords.z, 1, 1, 1) Wait(1000) local netid = ObjToNet(camspawned) SetNetworkIdExistsOnAllMachines(netid, true) NetworkSetNetworkIdDynamic(netid, true) SetNetworkIdCanMigrate(netid, false) - AttachEntityToEntity(camspawned, GetPlayerPed(PlayerId()), GetPedBoneIndex(GetPlayerPed(PlayerId()), 28422), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1) - TaskPlayAnim(GetPlayerPed(PlayerId()), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 - TaskPlayAnim(GetPlayerPed(PlayerId()), camanimDict, camanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) + AttachEntityToEntity(camspawned, GetPlayerPed(cache.playerId), GetPedBoneIndex(GetPlayerPed(cache.playerId), 28422), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1) + TaskPlayAnim(GetPlayerPed(cache.playerId), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 + TaskPlayAnim(GetPlayerPed(cache.playerId), camanimDict, camanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) cam_net = netid holdingCam = true DisplayNotification(Lang:t("text.weazle_overlay")) else - ClearPedSecondaryTask(GetPlayerPed(PlayerId())) + ClearPedSecondaryTask(GetPlayerPed(cache.playerId)) DetachEntity(NetToObj(cam_net), 1, 1) DeleteEntity(NetToObj(cam_net)) cam_net = nil @@ -148,23 +144,20 @@ end) CreateThread(function() while true do - if PlayerJob.name == "reporter" then + if QBX.PlayerData.job.name == "reporter" then if holdingCam then - while not HasAnimDictLoaded(camanimDict) do - RequestAnimDict(camanimDict) - Wait(100) - end + lib.requestAnimDict(camanimDict) - if not IsEntityPlayingAnim(PlayerPedId(), camanimDict, camanimName, 3) then - TaskPlayAnim(GetPlayerPed(PlayerId()), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 - TaskPlayAnim(GetPlayerPed(PlayerId()), camanimDict, camanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) + if not IsEntityPlayingAnim(cache.ped, camanimDict, camanimName, 3) then + TaskPlayAnim(GetPlayerPed(cache.playerId), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 + TaskPlayAnim(GetPlayerPed(cache.playerId), camanimDict, camanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) end - DisablePlayerFiring(PlayerId(), true) + DisablePlayerFiring(cache.playerId, true) DisableControlAction(0,25,true) -- disable aim DisableControlAction(0, 44, true) -- INPUT_COVER DisableControlAction(0,37,true) -- INPUT_SELECT_WEAPON - SetCurrentPedWeapon(PlayerPedId(), GetHashKey("WEAPON_UNARMED"), true) + SetCurrentPedWeapon(cache.ped, joaat("WEAPON_UNARMED"), true) Wait(7) else Wait(100) @@ -181,35 +174,34 @@ end) CreateThread(function() while true do - if PlayerJob.name == "reporter" then + if QBX.PlayerData.job.name == "reporter" then if holdingCam then if IsControlJustReleased(1, 244) then movcamera = true SetTimecycleModifier("default") SetTimecycleModifierStrength(0.3) - local scaleform = RequestScaleformMovie("security_camera") + local scaleform = lib.requestScaleformMovie("security_camera") while not HasScaleformMovieLoaded(scaleform) do Wait(10) end - local lPed = PlayerPedId() - local vehicle = GetVehiclePedIsIn(lPed) + local vehicle = GetVehiclePedIsIn(cache.ped) local cam1 = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true) - AttachCamToEntity(cam1, lPed, 0.0,0.0,1.0, true) - SetCamRot(cam1, 2.0,1.0,GetEntityHeading(lPed)) + AttachCamToEntity(cam1, cache.ped, 0.0,0.0,1.0, true) + SetCamRot(cam1, 2.0,1.0,GetEntityHeading(cache.ped)) SetCamFov(cam1, fov) RenderScriptCams(true, false, 0, 1, 0) PushScaleformMovieFunction(scaleform, "security_camera") PopScaleformMovieFunctionVoid() - while movcamera and not IsEntityDead(lPed) and (GetVehiclePedIsIn(lPed) == vehicle) and true do + while movcamera and not IsEntityDead(cache.ped) and (GetVehiclePedIsIn(cache.ped) == vehicle) and true do if IsControlJustPressed(0, 177) then PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false) movcamera = false end - SetEntityRotation(lPed, 0, 0, new_z,2, true) + SetEntityRotation(cache.ped, 0, 0, new_z,2, true) local zoomvalue = (1.0/(fov_max-fov_min))*(fov-fov_min) CheckInputRotation(cam1, zoomvalue) HandleZoom(cam1) @@ -231,8 +223,8 @@ CreateThread(function() camHeading = 180.0 end camHeading = (camHeading + 180.0) / 360.0 - SetTaskMoveNetworkSignalFloat(PlayerPedId(), "Pitch", camPitch) - SetTaskMoveNetworkSignalFloat(PlayerPedId(), "Heading", camHeading * -1.0 + 1.0) + SetTaskMoveNetworkSignalFloat(cache.ped, "Pitch", camPitch) + SetTaskMoveNetworkSignalFloat(cache.ped, "Heading", camHeading * -1.0 + 1.0) Wait(1) end movcamera = false @@ -260,36 +252,30 @@ end) CreateThread(function() while true do - if PlayerJob.name == "reporter" then + if QBX.PlayerData.job.name == "reporter" then if holdingCam then if IsControlJustReleased(1, 38) then newscamera = true SetTimecycleModifier("default") SetTimecycleModifierStrength(0.3) - local scaleform = RequestScaleformMovie("security_camera") - local scaleform2 = RequestScaleformMovie("breaking_news") - while not HasScaleformMovieLoaded(scaleform) do - Wait(10) - end - while not HasScaleformMovieLoaded(scaleform2) do - Wait(10) - end - local lPed = PlayerPedId() - local vehicle = GetVehiclePedIsIn(lPed) + local scaleform = lib.requestScaleformMovie("security_camera") + local scaleform2 = lib.requestScaleformMovie("breaking_news") + + local vehicle = GetVehiclePedIsIn(cache.ped) local cam2 = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true) - AttachCamToEntity(cam2, lPed, 0.0,0.0,1.0, true) - SetCamRot(cam2, 2.0,1.0,GetEntityHeading(lPed)) + AttachCamToEntity(cam2, cache.ped, 0.0,0.0,1.0, true) + SetCamRot(cam2, 2.0,1.0,GetEntityHeading(cache.ped)) SetCamFov(cam2, fov) RenderScriptCams(true, false, 0, 1, 0) PushScaleformMovieFunction(scaleform, "SET_CAM_LOGO") PushScaleformMovieFunction(scaleform2, "breaking_news") PopScaleformMovieFunctionVoid() - while newscamera and not IsEntityDead(lPed) and (GetVehiclePedIsIn(lPed) == vehicle) and true do + while newscamera and not IsEntityDead(cache.ped) and (GetVehiclePedIsIn(cache.ped) == vehicle) and true do if IsControlJustPressed(1, 177) then PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false) newscamera = false end - SetEntityRotation(lPed, 0, 0, new_z,2, true) + SetEntityRotation(cache.ped, 0, 0, new_z,2, true) local zoomvalue = (1.0/(fov_max-fov_min))*(fov-fov_min) CheckInputRotation(cam2, zoomvalue) HandleZoom(cam2) @@ -311,8 +297,8 @@ CreateThread(function() camHeading = 180.0 end camHeading = (camHeading + 180.0) / 360.0 - SetTaskMoveNetworkSignalFloat(PlayerPedId(), "Pitch", camPitch) - SetTaskMoveNetworkSignalFloat(PlayerPedId(), "Heading", camHeading * -1.0 + 1.0) + SetTaskMoveNetworkSignalFloat(cache.ped, "Pitch", camPitch) + SetTaskMoveNetworkSignalFloat(cache.ped, "Heading", camHeading * -1.0 + 1.0) Wait(1) end newscamera = false @@ -340,24 +326,21 @@ end) RegisterNetEvent("Mic:ToggleBMic", function() if not holdingBmic then - RequestModel(GetHashKey(bmicModel)) - while not HasModelLoaded(GetHashKey(bmicModel)) do - Wait(100) - end - local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()), 0.0, 0.0, -5.0) - local bmicspawned = CreateObject(GetHashKey(bmicModel), plyCoords.x, plyCoords.y, plyCoords.z, true, true, false) + lib.requestModel(bmicModel) + local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(cache.playerId), 0.0, 0.0, -5.0) + local bmicspawned = CreateObject(bmicModel, plyCoords.x, plyCoords.y, plyCoords.z, true, true, false) Wait(1000) local netid = ObjToNet(bmicspawned) SetNetworkIdExistsOnAllMachines(netid, true) NetworkSetNetworkIdDynamic(netid, true) SetNetworkIdCanMigrate(netid, false) - AttachEntityToEntity(bmicspawned, GetPlayerPed(PlayerId()), GetPedBoneIndex(GetPlayerPed(PlayerId()), 28422), -0.08, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1) - TaskPlayAnim(GetPlayerPed(PlayerId()), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 - TaskPlayAnim(GetPlayerPed(PlayerId()), bmicanimDict, bmicanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) + AttachEntityToEntity(bmicspawned, GetPlayerPed(cache.playerId), GetPedBoneIndex(GetPlayerPed(cache.playerId), 28422), -0.08, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1) + TaskPlayAnim(GetPlayerPed(cache.playerId), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 + TaskPlayAnim(GetPlayerPed(cache.playerId), bmicanimDict, bmicanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) bmic_net = netid holdingBmic = true else - ClearPedSecondaryTask(GetPlayerPed(PlayerId())) + ClearPedSecondaryTask(GetPlayerPed(cache.playerId)) DetachEntity(NetToObj(bmic_net), 1, 1) DeleteEntity(NetToObj(bmic_net)) bmic_net = nil @@ -367,23 +350,20 @@ end) CreateThread(function() while true do - if PlayerJob.name == "reporter" then + if QBX.PlayerData.job.name == "reporter" then if holdingBmic then - while not HasAnimDictLoaded(bmicanimDict) do - RequestAnimDict(bmicanimDict) - Wait(100) - end - if not IsEntityPlayingAnim(PlayerPedId(), bmicanimDict, bmicanimName, 3) then - TaskPlayAnim(PlayerPedId(), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 - TaskPlayAnim(PlayerPedId(), bmicanimDict, bmicanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) + lib.requestAnimDict(bmicanimDict) + if not IsEntityPlayingAnim(cache.ped, bmicanimDict, bmicanimName, 3) then + TaskPlayAnim(cache.ped, 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 + TaskPlayAnim(cache.ped, bmicanimDict, bmicanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) end - DisablePlayerFiring(PlayerId(), true) + DisablePlayerFiring(cache.playerId, true) DisableControlAction(0,25,true) -- disable aim DisableControlAction(0, 44, true) -- INPUT_COVER DisableControlAction(0,37,true) -- INPUT_SELECT_WEAPON - SetCurrentPedWeapon(PlayerPedId(), GetHashKey("WEAPON_UNARMED"), true) - if IsPedInAnyVehicle(PlayerPedId(), false) or QBCore.Functions.GetPlayerData().metadata["ishandcuffed"] or holdingMic then - ClearPedSecondaryTask(PlayerPedId()) + SetCurrentPedWeapon(cache.ped, joaat("WEAPON_UNARMED"), true) + if IsPedInAnyVehicle(cache.ped, false) or QBX.PlayerData.metadata.ishandcuffed or holdingMic then + ClearPedSecondaryTask(cache.ped) DetachEntity(NetToObj(bmic_net), 1, 1) DeleteEntity(NetToObj(bmic_net)) bmic_net = nil @@ -413,29 +393,22 @@ end) --------------------------------------------------------------------------- RegisterNetEvent("Mic:ToggleMic", function() if not holdingMic then - RequestModel(GetHashKey(micModel)) - while not HasModelLoaded(GetHashKey(micModel)) do - Wait(100) - end - - while not HasAnimDictLoaded(micanimDict) do - RequestAnimDict(micanimDict) - Wait(100) - end - local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()), 0.0, 0.0, -5.0) - local micspawned = CreateObject(GetHashKey(micModel), plyCoords.x, plyCoords.y, plyCoords.z, 1, 1, 1) + lib.requestModel(micModel) + lib.requestAnimDict(micanimDict) + local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(cache.playerId), 0.0, 0.0, -5.0) + local micspawned = CreateObject(micModel, plyCoords.x, plyCoords.y, plyCoords.z, 1, 1, 1) Wait(1000) local netid = ObjToNet(micspawned) SetNetworkIdExistsOnAllMachines(netid, true) NetworkSetNetworkIdDynamic(netid, true) SetNetworkIdCanMigrate(netid, false) - AttachEntityToEntity(micspawned, GetPlayerPed(PlayerId()), GetPedBoneIndex(GetPlayerPed(PlayerId()), 60309), 0.055, 0.05, 0.0, 240.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1) - TaskPlayAnim(GetPlayerPed(PlayerId()), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 - TaskPlayAnim(GetPlayerPed(PlayerId()), micanimDict, micanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) + AttachEntityToEntity(micspawned, GetPlayerPed(cache.playerId), GetPedBoneIndex(GetPlayerPed(cache.playerId), 60309), 0.055, 0.05, 0.0, 240.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1) + TaskPlayAnim(GetPlayerPed(cache.playerId), 1.0, -1, -1, 50, 0, 0, 0, 0) -- 50 = 32 + 16 + 2 + TaskPlayAnim(GetPlayerPed(cache.playerId), micanimDict, micanimName, 1.0, -1, -1, 50, 0, 0, 0, 0) mic_net = netid holdingMic = true else - ClearPedSecondaryTask(GetPlayerPed(PlayerId())) + ClearPedSecondaryTask(GetPlayerPed(cache.playerId)) DetachEntity(NetToObj(mic_net), 1, 1) DeleteEntity(NetToObj(mic_net)) mic_net = nil diff --git a/client/main.lua b/client/main.lua index 7f1aa0b..9554883 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,52 +1,54 @@ -QBCore = exports['qbx-core']:GetCoreObject() -PlayerJob = {} - RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - PlayerJob = QBCore.Functions.GetPlayerData().job - if PlayerJob.name == "reporter" then - local blip = AddBlipForCoord(Config.Locations["main"].coords.x, Config.Locations["main"].coords.y, Config.Locations["main"].coords.z) + if QBX.PlayerData.job.name == "reporter" then + local blip = AddBlipForCoord(Config.Locations.main.coords.x, Config.Locations.main.coords.y, Config.Locations.main.coords.z) SetBlipSprite(blip, 225) SetBlipDisplay(blip, 4) SetBlipScale(blip, 0.6) SetBlipAsShortRange(blip, true) SetBlipColour(blip, 1) BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(Config.Locations["main"].label) + AddTextComponentSubstringPlayerName(Config.Locations.main.label) EndTextCommandSetBlipName(blip) end end) RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo) - PlayerJob = JobInfo - if PlayerJob.name == "reporter" then - local blip = AddBlipForCoord(Config.Locations["main"].coords.x, Config.Locations["main"].coords.y, Config.Locations["main"].coords.z) + if QBX.PlayerData.job.name == "reporter" then + local blip = AddBlipForCoord(Config.Locations.main.coords.x, Config.Locations.main.coords.y, Config.Locations.main.coords.z) SetBlipSprite(blip, 225) SetBlipDisplay(blip, 4) SetBlipScale(blip, 0.6) SetBlipAsShortRange(blip, true) SetBlipColour(blip, 1) BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(Config.Locations["main"].label) + AddTextComponentSubstringPlayerName(Config.Locations.main.label) EndTextCommandSetBlipName(blip) end end) -function TakeOutVehicle(vehicleInfo) - local coords = Config.Locations["vehicle"].coords - QBCore.Functions.SpawnVehicle(vehicleInfo, function(veh) - SetVehicleNumberPlateText(veh, "WZNW"..tostring(math.random(1000, 9999))) - SetEntityHeading(veh, coords.w) - SetVehicleFuelLevel(veh, 100.0) - TaskWarpPedIntoVehicle(cache.ped, veh, -1) - TriggerEvent("vehiclekeys:client:SetOwner", QBCore.Functions.GetPlate(veh)) - SetVehicleEngineOn(veh, true, true, false) +function TakeOutVehicle(vehType, coords) + local netId = lib.callback.await('qbx_newsjob:server:spawnVehicle', false, vehType, coords, 'WZN'..tostring(math.random(10000, 99999))) + local timeout = 100 + while not NetworkDoesEntityExistWithNetworkId(netId) and timeout > 0 do + Wait(10) + timeout -= 1 + end + local veh = NetToVeh(netId) + if veh == 0 then exports.qbx_core:Notify('Something went wrong spawning the vehicle', 'error') return end + local vehClass = GetVehicleClass(veh) + if vehClass == 12 then -- Vans SetVehicleLivery(veh, 2) - CurrentPlate = QBCore.Functions.GetPlate(veh) - end, coords, true) + end + SetVehicleFuelLevel(veh, 100.0) + SetVehicleFuelLevel(veh, 100.0) + TaskWarpPedIntoVehicle(cache.ped, veh, -1) + TriggerEvent("vehiclekeys:client:SetOwner", GetPlate(veh)) + SetVehicleEngineOn(veh, true, true, false) + CurrentPlate = GetPlate(veh) end function MenuGarage() - local authorizedVehicles = Config.Vehicles[QBCore.Functions.GetPlayerData().job.grade.level] + local authorizedVehicles = Config.Vehicles[QBX.PlayerData.job.grade.level] local optionsMenu = {} for veh, label in pairs(authorizedVehicles) do @@ -68,30 +70,16 @@ function MenuGarage() lib.showContext('weazel_garage_context_menu') end -function TakeOutHelicopters(vehicleInfo) - local coords = Config.Locations["heli"].coords - QBCore.Functions.SpawnVehicle(vehicleInfo, function(veh) - SetVehicleNumberPlateText(veh, "WZNW"..tostring(math.random(1000, 9999))) - SetEntityHeading(veh, coords.w) - SetVehicleFuelLevel(veh, 100.0) - TaskWarpPedIntoVehicle(cache.ped, veh, -1) - TriggerEvent("vehiclekeys:client:SetOwner", QBCore.Functions.GetPlate(veh)) - SetVehicleEngineOn(veh, true, true, false) - SetVehicleLivery(veh, 2) - CurrentPlate = QBCore.Functions.GetPlate(veh) - end, coords, true) -end - function MenuHeliGarage() - local Helicopters = Config.Helicopters[QBCore.Functions.GetPlayerData().job.grade.level] + local Helicopters = Config.Helicopters[QBX.PlayerData.job.grade.level] local optionsMenu = {} for veh, label in pairs(Helicopters) do optionsMenu[#optionsMenu + 1] = { title = label, - event = 'qb-newsjob:client:TakeOutHelicopters', + event = 'qb-newsjob:client:TakeOutVehicle', args = { - vehicle = veh + helicopter = veh } } end @@ -112,90 +100,78 @@ CreateThread(function() local inRange = false local boxZone = false local pos = GetEntityCoords(cache.ped) - if PlayerJob.name == "reporter" then - if #(pos - vector3(Config.Locations["vehicle"].coords.x, Config.Locations["vehicle"].coords.y, Config.Locations["vehicle"].coords.z)) < 10.0 then + if QBX.PlayerData.job.name == "reporter" then + if #(pos - vector3(Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z)) < 10.0 then inRange = true - DrawMarker(2, Config.Locations["vehicle"].coords.x, Config.Locations["vehicle"].coords.y, Config.Locations["vehicle"].coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 200, 200, 200, 222, false, false, 0, true, false, false, false) - if #(pos - vector3(Config.Locations["vehicle"].coords.x, Config.Locations["vehicle"].coords.y, Config.Locations["vehicle"].coords.z)) < 1.5 then - local function onEnter() - if IsPedInAnyVehicle(cache.ped, false) then - lib.showTextUI(Lang:t("text.store_vehicle")) - else - lib.showTextUI(Lang:t("text.vehicles")) - end - end - - local function onExit() - lib.hideTextUI() - end - - local function inside() - if IsPedInAnyVehicle(cache.ped, false) then - if IsControlJustReleased(0, 38) then - if IsPedInAnyVehicle(cache.ped, false) then - DeleteVehicle(GetVehiclePedIsIn(cache.ped, false)) - end - end - else - if IsControlJustReleased(0, 38) then - MenuGarage() - end - end - end - + DrawMarker(2, Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 200, 200, 200, 222, false, false, 0, true, false, false, false) + if #(pos - vector3(Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z)) < 1.5 then if not VehicleZone then VehicleZone = lib.zones.box({ - coords = vec3(Config.Locations["vehicle"].coords.x, Config.Locations["vehicle"].coords.y, Config.Locations["vehicle"].coords.z), + coords = vec3(Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z), size = vec3(4, 4, 4), rotation = 45, debug = Config.DebugZones, - inside = inside, - onEnter = onEnter, - onExit = onExit + onEnter = function() + if IsPedInAnyVehicle(cache.ped, false) then + lib.showTextUI(Lang:t("text.store_vehicle")) + else + lib.showTextUI(Lang:t("text.vehicles")) + end + end, + onExit = function() + lib.hideTextUI() + end, + inside = function() + if IsPedInAnyVehicle(cache.ped, false) then + if IsControlJustReleased(0, 38) then + if IsPedInAnyVehicle(cache.ped, false) then + DeleteVehicle(cache.vehicle) + end + end + else + if IsControlJustReleased(0, 38) then + MenuGarage() + end + end + end }) end inRange = true end - elseif #(pos - vector3(Config.Locations["heli"].coords.x, Config.Locations["heli"].coords.y, Config.Locations["heli"].coords.z)) < 5.0 then + elseif #(pos - vector3(Config.Locations.heli.coords.x, Config.Locations.heli.coords.y, Config.Locations.heli.coords.z)) < 5.0 then inRange = true - DrawMarker(2, Config.Locations["heli"].coords.x, Config.Locations["heli"].coords.y, Config.Locations["heli"].coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 200, 200, 200, 222, false, false, 0, true, false, false, false) - if #(pos - vector3(Config.Locations["heli"].coords.x, Config.Locations["heli"].coords.y, Config.Locations["heli"].coords.z)) < 1.5 then - local function onEnter() - if IsPedInAnyVehicle(cache.ped, false) then - lib.showTextUI(Lang:t("text.store_helicopters")) - else - lib.showTextUI(Lang:t("text.helicopters")) - end - end - - local function onExit() - lib.hideTextUI() - end - - local function inside() - if IsPedInAnyVehicle(cache.ped, false) then - if IsControlJustReleased(0, 38) then - if IsPedInAnyVehicle(cache.ped, false) then - DeleteVehicle(GetVehiclePedIsIn(cache.ped, false)) - end - end - else - if IsControlJustReleased(0, 38) then - MenuHeliGarage() - end - end - end - + DrawMarker(2, Config.Locations.heli.coords.x, Config.Locations.heli.coords.y, Config.Locations.heli.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 200, 200, 200, 222, false, false, 0, true, false, false, false) + if #(pos - vector3(Config.Locations.heli.coords.x, Config.Locations.heli.coords.y, Config.Locations.heli.coords.z)) < 1.5 then if not HeliZone then HeliZone = lib.zones.box({ - coords = vec3(Config.Locations["heli"].coords.x, Config.Locations["heli"].coords.y, Config.Locations["heli"].coords.z), + coords = vec3(Config.Locations.heli.coords.x, Config.Locations.heli.coords.y, Config.Locations.heli.coords.z), size = vec3(4, 4, 4), rotation = 267.49, debug = Config.DebugZones, - inside = inside, - onEnter = onEnter, - onExit = onExit + onEnter = function() + if IsPedInAnyVehicle(cache.ped, false) then + lib.showTextUI(Lang:t("text.store_helicopters")) + else + lib.showTextUI(Lang:t("text.helicopters")) + end + end, + onExit = function() + lib.hideTextUI() + end, + inside = function() + if IsPedInAnyVehicle(cache.ped, false) then + if IsControlJustReleased(0, 38) then + if IsPedInAnyVehicle(cache.ped, false) then + DeleteVehicle(cache.vehicle) + end + end + else + if IsControlJustReleased(0, 38) then + MenuHeliGarage() + end + end + end }) end @@ -229,81 +205,69 @@ CreateThread(function() local inRange = false if LocalPlayer.state.isLoggedIn then local pos = GetEntityCoords(cache.ped) - if #(pos - vector3(Config.Locations["main"].coords.x, Config.Locations["main"].coords.y, Config.Locations["main"].coords.z)) < 1.5 or #(pos - vector3(Config.Locations["inside"].coords.x, Config.Locations["inside"].coords.y, Config.Locations["inside"].coords.z)) < 1.5 then + if #(pos - vector3(Config.Locations.main.coords.x, Config.Locations.main.coords.y, Config.Locations.main.coords.z)) < 1.5 or #(pos - vector3(Config.Locations.inside.coords.x, Config.Locations.inside.coords.y, Config.Locations.inside.coords.z)) < 1.5 then inRange = true - if #(pos - vector3(Config.Locations["main"].coords.x, Config.Locations["main"].coords.y, Config.Locations["main"].coords.z)) < 1.5 then - local function onEnter() - lib.showTextUI(Lang:t("text.enter")) - end - - local function onExit() - lib.hideTextUI() - end - - local function inside() - if IsControlJustReleased(0, 38) then - lib.hideTextUI() - DoScreenFadeOut(500) - while not IsScreenFadedOut() do - Wait(10) - end - - SetEntityCoords(cache.ped, Config.Locations["inside"].coords.x, Config.Locations["inside"].coords.y, Config.Locations["inside"].coords.z, false, false, false, false) - SetEntityHeading(cache.ped, Config.Locations["inside"].coords.w) - - Wait(100) - - DoScreenFadeIn(1000) - end - end - + if #(pos - vector3(Config.Locations.main.coords.x, Config.Locations.main.coords.y, Config.Locations.main.coords.z)) < 1.5 then if not MainEntrance then MainEntrance = lib.zones.box({ - coords = vec3(Config.Locations["main"].coords.x, Config.Locations["main"].coords.y, Config.Locations["main"].coords.z), + coords = vec3(Config.Locations.main.coords.x, Config.Locations.main.coords.y, Config.Locations.main.coords.z), size = vec3(4, 4, 4), rotation = 267.49, debug = Config.DebugZones, - inside = inside, - onEnter = onEnter, - onExit = onExit + onEnter = function() + lib.showTextUI(Lang:t("text.enter")) + end, + onExit = function() + lib.hideTextUI() + end, + inside = function() + if IsControlJustReleased(0, 38) then + lib.hideTextUI() + DoScreenFadeOut(500) + while not IsScreenFadedOut() do + Wait(10) + end + + SetEntityCoords(cache.ped, Config.Locations.inside.coords.x, Config.Locations.inside.coords.y, Config.Locations.inside.coords.z, false, false, false, false) + SetEntityHeading(cache.ped, Config.Locations.inside.coords.w) + + Wait(100) + + DoScreenFadeIn(1000) + end + end }) end - elseif #(pos - vector3(Config.Locations["inside"].coords.x, Config.Locations["inside"].coords.y, Config.Locations["inside"].coords.z)) < 1.5 then - local function onEnter() - lib.showTextUI(Lang:t("text.go_outside")) - end - - local function onExit() - lib.hideTextUI() - end - - local function inside() - if IsControlJustReleased(0, 38) then - lib.hideTextUI() - DoScreenFadeOut(500) - while not IsScreenFadedOut() do - Wait(10) - end - - SetEntityCoords(cache.ped, Config.Locations["outside"].coords.x, Config.Locations["outside"].coords.y, Config.Locations["outside"].coords.z, false, false, false, false) - SetEntityHeading(cache.ped, Config.Locations["outside"].coords.w) - - Wait(100) - - DoScreenFadeIn(1000) - end - end - + elseif #(pos - vector3(Config.Locations.inside.coords.x, Config.Locations.inside.coords.y, Config.Locations.inside.coords.z)) < 1.5 then if not MainExit then MainExit = lib.zones.box({ - coords = vec3(Config.Locations["inside"].coords.x, Config.Locations["inside"].coords.y, Config.Locations["inside"].coords.z), + coords = vec3(Config.Locations.inside.coords.x, Config.Locations.inside.coords.y, Config.Locations.inside.coords.z), size = vec3(2, 2, 2), rotation = 245.46, debug = Config.DebugZones, - inside = inside, - onEnter = onEnter, - onExit = onExit + onEnter = function() + lib.showTextUI(Lang:t("text.go_outside")) + end, + onExit = function() + lib.hideTextUI() + end, + inside = function() + if IsControlJustReleased(0, 38) then + lib.hideTextUI() + DoScreenFadeOut(500) + while not IsScreenFadedOut() do + Wait(10) + end + + SetEntityCoords(cache.ped, Config.Locations.outside.coords.x, Config.Locations.outside.coords.y, Config.Locations.outside.coords.z, false, false, false, false) + SetEntityHeading(cache.ped, Config.Locations.outside.coords.w) + + Wait(100) + + DoScreenFadeIn(1000) + end + end }) end end @@ -324,11 +288,13 @@ CreateThread(function() end) RegisterNetEvent('qb-newsjob:client:TakeOutVehicle', function(data) - local vehicle = data.vehicle - TakeOutVehicle(vehicle) -end) - -RegisterNetEvent('qb-newsjob:client:TakeOutHelicopters', function(data) - local vehicle = data.vehicle - TakeOutHelicopters(vehicle) + if data.vehicle then + local coords = Config.Locations.vehicle.coords + local veh = data.vehicle + TakeOutVehicle(veh, coords) + elseif data.helicopter then + local coords = Config.Locations.heli.coords + local veh = data.helicopter + TakeOutVehicle(veh, coords) + end end) diff --git a/fxmanifest.lua b/fxmanifest.lua index cd8d67b..5d10a2a 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,12 +1,14 @@ fx_version 'cerulean' game 'gta5' -description 'QB-NewsJob' +description 'QBX-NewsJob' +repository 'https://github.com/Qbox-project/qbx_newsjob' version '1.0.1' shared_scripts { + '@qbx_core/import.lua', 'config.lua', - '@qb-core/shared/locale.lua', + '@qbx_core/shared/locale.lua', 'locales/en.lua', 'locales/*.lua', '@ox_lib/init.lua' @@ -17,6 +19,12 @@ client_scripts { 'client/camera.lua' } +modules { + 'qbx_core:playerdata', + 'qbx_core:utils' +} + server_script 'server/main.lua' -lua54 'yes' \ No newline at end of file +lua54 'yes' +use_experimental_fxv2_oal 'yes' \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 0bbdee7..3d68e6b 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,22 +1,30 @@ -local QBCore = exports['qbx-core']:GetCoreObject() +lib.callback.register('qbx_newsjob:server:spawnVehicle', function(source, model, coords, plate) + local netId = SpawnVehicle(source, model, coords, true) + if not netId or netId == 0 then return end + local veh = NetworkGetEntityFromNetworkId(netId) + if not veh or veh == 0 then return end + SetVehicleNumberPlateText(veh, plate) + TriggerClientEvent('vehiclekeys:client:SetOwner', source, plate) + return netId +end) -QBCore.Commands.Add("newscam", "Grab a news camera", {}, false, function(source, _) - local Player = QBCore.Functions.GetPlayer(source) - if Player.PlayerData.job.name == "reporter" then +lib.addCommand('newscam', {help = 'Grab a news camera'}, function(source, _) + local player = exports.qbx_core:GetPlayer(source) + if player.PlayerData.job.name == "reporter" then TriggerClientEvent("Cam:ToggleCam", source) end end) -QBCore.Commands.Add("newsmic", "Grab a news microphone", {}, false, function(source, _) - local Player = QBCore.Functions.GetPlayer(source) - if Player.PlayerData.job.name == "reporter" then +lib.addCommand('newsmic', {help = 'Grab a news microphone'}, function(source, _) + local player = exports.qbx_core:GetPlayer(source) + if player.PlayerData.job.name == "reporter" then TriggerClientEvent("Mic:ToggleMic", source) end end) -QBCore.Commands.Add("newsbmic", "Grab a Boom microphone", {}, false, function(source, _) - local Player = QBCore.Functions.GetPlayer(source) - if Player.PlayerData.job.name == "reporter" then +lib.addCommand('newsbmic', {help = 'Grab a Boom microphone'}, function(source, _) + local player = exports.qbx_core:GetPlayer(source) + if player.PlayerData.job.name == "reporter" then TriggerClientEvent("Mic:ToggleBMic", source) end end) From 6a28ef6aeca292e3897d3357a2d760422211e699 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:21:34 -0400 Subject: [PATCH 2/2] fix some linting errors --- client/main.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/main.lua b/client/main.lua index 9554883..aa9a21f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -12,7 +12,7 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() end end) -RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo) +RegisterNetEvent('QBCore:Client:OnJobUpdate', function() if QBX.PlayerData.job.name == "reporter" then local blip = AddBlipForCoord(Config.Locations.main.coords.x, Config.Locations.main.coords.y, Config.Locations.main.coords.z) SetBlipSprite(blip, 225) @@ -98,14 +98,13 @@ CreateThread(function() Wait(0) if LocalPlayer.state.isLoggedIn then local inRange = false - local boxZone = false local pos = GetEntityCoords(cache.ped) if QBX.PlayerData.job.name == "reporter" then if #(pos - vector3(Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z)) < 10.0 then inRange = true DrawMarker(2, Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.15, 200, 200, 200, 222, false, false, 0, true, false, false, false) if #(pos - vector3(Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z)) < 1.5 then - if not VehicleZone then + if not VehicleZone then VehicleZone = lib.zones.box({ coords = vec3(Config.Locations.vehicle.coords.x, Config.Locations.vehicle.coords.y, Config.Locations.vehicle.coords.z), size = vec3(4, 4, 4),