Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This stops the errors that are within the standard Qbox recipe #12

Merged
merged 6 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local new_z
local movcamera
local newscamera

local isLoggedIn = LocalPlayer.state.isLoggedIn

--FUNCTIONS--
local function HideHUDThisFrame()
Expand Down Expand Up @@ -136,6 +137,7 @@ end)

CreateThread(function()
while true do
if not isLoggedIn then return end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isLoggedIn then return end
local function handleCamera()
CreateThread(function()
while holdingCam do
lib.requestAnimDict(camanimDict)
if not IsEntityPlayingAnim(cache.ped, camanimDict, camanimName, 3) then
TaskPlayAnim(cache.ped, camanimDict, camanimName, 1.0, -1, -1, 50, 0, 0, 0, 0)
end
DisablePlayerFiring(cache.playerId, true)
DisableControlAction(0,25, true)
DisableControlAction(0, 44, true)
DisableControlAction(0,37, true)
SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`, true)
Wait(100)
end
end)
RegisterNetEvent('qbx_newsjob:client:toggleCam', function()
if QBX.PlayerData.job.name ~= 'reporter' then return end
if not holdingCam then
lib.requestModel(camModel)
local plyCoords = GetOffsetFromEntityInWorldCoords(cache.ped, 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, cache.ped, GetPedBoneIndex(cache.ped, 28422), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1)
TaskPlayAnim(cache.ped, camanimDict, camanimName, 1.0, -1, -1, 50, 0, 0, 0, 0)
cam_net = netid
holdingCam = true
lib.showTextUI(Lang:t('info.weazle_overlay'))
handleCamera()
else
lib.hideTextUI()
ClearPedSecondaryTask(cache.ped)
DetachEntity(NetToObj(cam_net), 1, 1)
DeleteEntity(NetToObj(cam_net))
cam_net = nil
holdingCam = false
end
end)

So rather than return this thread early we should delay the thread creation until we actually need it. Something like this to replace everything in this area. Then do something similar for the other threads where
they get put them into functions and then call those functions as needed when you activate the camera/mic boom etc.

This will reduce the thread count as well as clean up the readability of this resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. Making changes now..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just testing now

if QBX.PlayerData.job.name == 'reporter' then
if holdingCam then
lib.requestAnimDict(camanimDict)
Expand Down Expand Up @@ -165,6 +167,7 @@ end)

CreateThread(function()
while true do
if not isLoggedIn then return end
if QBX.PlayerData.job.name == 'reporter' then
if holdingCam then
if IsControlJustReleased(1, 244) then
Expand Down Expand Up @@ -243,6 +246,7 @@ end)

CreateThread(function()
while true do
if not isLoggedIn then return end
if QBX.PlayerData.job.name == 'reporter' then
if holdingCam then
if IsControlJustReleased(1, 38) then
Expand Down Expand Up @@ -340,6 +344,7 @@ end)

CreateThread(function()
while true do
if not isLoggedIn then return end
if QBX.PlayerData.job.name == 'reporter' then
if holdingBmic then
lib.requestAnimDict(bmicanimDict)
Expand Down Expand Up @@ -402,4 +407,4 @@ RegisterNetEvent('qbx_newsjob:client:toggleMic', function()
mic_net = nil
holdingMic = false
end
end)
end)
2 changes: 1 addition & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ local function init()
registerEnterRoof()
registerExitRoof()

if QBX.PlayerData.job.name == 'reporter' then
if QBX.PlayerData.job.name == 'reporter' and isLoggedIn then
registerVehicleStorage()
registerHeliStorage()
end
Expand Down
Loading