Skip to content

Commit

Permalink
refactor: multiple fixes and TODOs (#111)
Browse files Browse the repository at this point in the history
* chore(server): add TODO

* feat(consumables): add effect exports, fix casing

* chore(disableservices): add TODO

* refactor(flipvehicle): use PascalCase

* refactor(hudcomponents): use PascalCase

* refactor(ignore): remove duplicate function and remove endless loop

* refactor(recoils): remove endless loop
  • Loading branch information
solareon authored Jul 10, 2024
1 parent b3e459e commit 5f51762
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 50 deletions.
1 change: 1 addition & 0 deletions qbx_afk/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ AddEventHandler('QBCore:Server:OnPermissionUpdate', function(source)
updateCheckUser(source)
end)

---@TODO determine if lib.cron is better for this
CreateThread(function()
for _, v in pairs(GetPlayers()) do
v = tonumber(v)
Expand Down
7 changes: 7 additions & 0 deletions qbx_consumables/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local function trevorEffect()
AnimpostfxStop('DrugsTrevorClownsFightIn')
AnimpostfxStop('DrugsTrevorClownsFightOut')
end
exports('TrevorEffect', trevorEffect)

local function methBagEffect()
local startStamina = 8
Expand All @@ -46,6 +47,7 @@ local function methBagEffect()
end
SetRunSprintMultiplierForPlayer(cache.playerId, 1.0)
end
exports('MethBagEffect', methBagEffect)

local function ecstasyEffect()
local startStamina = 30
Expand All @@ -63,6 +65,7 @@ local function ecstasyEffect()
SetPedToRagdoll(cache.ped, math.random(1000, 3000), math.random(1000, 3000), 3, false, false, false)
end
end
exports('EcstasyEffect', ecstasyEffect)

local function alienEffect()
AnimpostfxPlay('DrugsMichaelAliensFightIn', 3.0, false)
Expand All @@ -74,6 +77,7 @@ local function alienEffect()
AnimpostfxStop('DrugsMichaelAliensFight')
AnimpostfxStop('DrugsMichaelAliensFightOut')
end
exports('AlienEffect', alienEffect)

local function crackBaggyEffect()
local startStamina = 8
Expand All @@ -97,6 +101,7 @@ local function crackBaggyEffect()
end
SetRunSprintMultiplierForPlayer(cache.playerId, 1.0)
end
exports('CrackBaggyEffect', crackBaggyEffect)

local function cokeBaggyEffect()
local startStamina = 20
Expand All @@ -121,6 +126,7 @@ local function cokeBaggyEffect()
end
SetRunSprintMultiplierForPlayer(cache.playerId, 1.0)
end
exports('CokeBaggyEffect', cokeBaggyEffect)

local function smokeWeed()
CreateThread(function()
Expand Down Expand Up @@ -408,6 +414,7 @@ RegisterNetEvent('consumables:client:UseJoint', function()
end
end)

--@TODO Rework this to only run when needed.
CreateThread(function()
while true do
Wait(10)
Expand Down
9 changes: 9 additions & 0 deletions qbx_consumables/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ RegisterNetEvent('consumables:server:addThirst', function(amount)
end
end)

---@deprecated use SetHunger instead
exports('setHunger', setHunger)
---@deprecated use AddHunger instead
exports('addHunger', addHunger)
---@deprecated use SetThirst instead
exports('setThirst', setThirst)
---@deprecated use AddThirst instead
exports('addThirst', addThirst)

exports('SetHunger', setHunger)
exports('AddHunger', addHunger)
exports('SetThirst', setThirst)
exports('AddThirst', addThirst)
1 change: 1 addition & 0 deletions qbx_disableservices/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
// Add documentation for each variable here
"enabledServices": [
false,
false,
Expand Down
2 changes: 2 additions & 0 deletions qbx_flipvehicle/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ local function flipVehicle(vehicle, flipTest)
end
end

---@deprecated use FlipVehicle instead
exports('flipVehicle', flipVehicle)

exports('FlipVehicle', flipVehicle)
18 changes: 17 additions & 1 deletion qbx_hudcomponents/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local displayAmmo = config.disable.displayAmmo

CreateThread(function()
while true do

for i = 1, #disableHudComponents do
HideHudComponentThisFrame(disableHudComponents[i])
end
Expand All @@ -30,7 +30,9 @@ local function addDisableHudComponents(hudComponents)
end
end

---@deprecated use AddDisableHudComponents instead
exports('addDisableHudComponents', addDisableHudComponents)
exports('AddDisableHudComponents', addDisableHudComponents)

local function removeDisableHudComponents(hudComponents)
local hudComponentsType = type(hudComponents)
Expand All @@ -52,13 +54,17 @@ local function removeDisableHudComponents(hudComponents)
end
end

---@deprecated use RemoveDisableHudComponents instead
exports('removeDisableHudComponents', removeDisableHudComponents)
exports('RemoveDisableHudComponents', removeDisableHudComponents)

local function getDisableHudComponents()
return disableHudComponents
end

---@deprecated use GetDisableHudComponents instead
exports('getDisableHudComponents', getDisableHudComponents)
exports('GetDisableHudComponents', getDisableHudComponents)

local function addDisableControls(controls)
local controlsType = type(controls)
Expand All @@ -71,7 +77,9 @@ local function addDisableControls(controls)
end
end

---@deprecated use AddDisableControls instead
exports('addDisableControls', addDisableControls)
exports('AddDisableControls', addDisableControls)

local function removeDisableControls(controls)
local controlsType = type(controls)
Expand All @@ -93,22 +101,30 @@ local function removeDisableControls(controls)
end
end

---@deprecated use RemoveDisableControls instead
exports('removeDisableControls', removeDisableControls)
exports('RemoveDisableControls', removeDisableControls)

local function getDisableControls()
return disableControls
end

---@deprecated use GetDisableControls instead
exports('getDisableControls', getDisableControls)
exports('GetDisableControls', getDisableControls)

local function setDisplayAmmo(bool)
displayAmmo = bool
end

---@deprecated use SetDisplayAmmo instead
exports('setDisplayAmmo', setDisplayAmmo)
exports('SetDisplayAmmo', setDisplayAmmo)

local function getDisplayAmmo()
return displayAmmo
end

---@deprecated use GetDisplayAmmo instead
exports('getDisplayAmmo', getDisplayAmmo)
exports('GetDisplayAmmo', getDisplayAmmo)
37 changes: 16 additions & 21 deletions qbx_ignore/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local config = require 'qbx_ignore.config'

---@TODO test if this needs to be called in a loop
CreateThread(function()
while true do
for _, sctyp in next, config.blacklisted.scenarioTypes do
Expand Down Expand Up @@ -42,41 +43,35 @@ CreateThread(function() -- all these should only need to be called once
RemoveVehiclesFromGeneratorsInArea(-724.46 - 300.0, -1444.03 - 300.0, 5.0 - 300.0, -724.46 + 300.0, -1444.03 + 300.0, 5.0 + 300.0) -- REMOVE CHOPPERS WOW
end)

CreateThread(function()
while true do
if IsPedBeingStunned(cache.ped, 0) then
SetPedMinGroundTimeForStungun(cache.ped, math.random(4000, 7000))
Wait(0)
else
Wait(1000)
end
end
end)

if config.disable.idleCamera then
DisableIdleCamera(true)
end

CreateThread(function()
local sleep
while true do
sleep = 500
local weapon = GetSelectedPedWeapon(cache.ped)
if weapon ~= `WEAPON_UNARMED` then
local function pistolWhipLoop()
CreateThread(function()
local sleep
while cache.weapon do
sleep = 500
if IsPedArmed(cache.ped, 6) then
sleep = 0
DisableControlAction(1, 140, true)
DisableControlAction(1, 141, true)
DisableControlAction(1, 142, true)
end

if weapon == `WEAPON_FIREEXTINGUISHER` or weapon == `WEAPON_PETROLCAN` then
if cache.weapon == `WEAPON_FIREEXTINGUISHER` or cache.weapon == `WEAPON_PETROLCAN` then
if IsPedShooting(cache.ped) then
SetPedInfiniteAmmo(cache.ped, true, `WEAPON_FIREEXTINGUISHER`)
SetPedInfiniteAmmo(cache.ped, true, `WEAPON_PETROLCAN`)
end
end
Wait(sleep)
end
Wait(sleep)
end
end)
end)
end

lib.onCache('weapon', function(weapon)
Wait(5)
if not weapon then return end
pistolWhipLoop()
end)
64 changes: 36 additions & 28 deletions qbx_recoils/client.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
local recoils = require 'qbx_recoils.config'

CreateThread(function()
while true do
if IsPedShooting(cache.ped) and not IsPedDoingDriveby(cache.ped) then
local _, wep = GetCurrentPedWeapon(cache.ped, true)
if recoils[wep] and recoils[wep] ~= 0 then
-- luacheck: ignore
local tv = 0
if GetFollowPedCamViewMode() ~= 4 then
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
SetGameplayCamRelativePitch(p + 0.1, 0.2)
tv += 0.1
until tv >= recoils[wep]
else
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
if recoils[wep] > 0.1 then
SetGameplayCamRelativePitch(p + 0.6, 1.2)
tv += 0.6
else
SetGameplayCamRelativePitch(p + 0.016, 0.333)
local function recoilLoop()
CreateThread(function()
while cache.weapon do
if IsPedShooting(cache.ped) and not IsPedDoingDriveby(cache.ped) then
local _, wep = GetCurrentPedWeapon(cache.ped, true)
if recoils[wep] and recoils[wep] ~= 0 then
-- luacheck: ignore
local tv = 0
if GetFollowPedCamViewMode() ~= 4 then
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
SetGameplayCamRelativePitch(p + 0.1, 0.2)
tv += 0.1
end
until tv >= recoils[wep]
until tv >= recoils[wep]
else
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
if recoils[wep] > 0.1 then
SetGameplayCamRelativePitch(p + 0.6, 1.2)
tv += 0.6
else
SetGameplayCamRelativePitch(p + 0.016, 0.333)
tv += 0.1
end
until tv >= recoils[wep]
end
end
end
Wait(350) -- might be able to reduce time here for more recoil
end
Wait(350)
end
end)
end)
end

lib.onCache('weapon', function(weapon)
Wait(5)
if not weapon then return end
recoilLoop()
end)

0 comments on commit 5f51762

Please sign in to comment.