Skip to content

Commit

Permalink
Optimization: Change pair for to numeric for.
Browse files Browse the repository at this point in the history
  • Loading branch information
SuelTheDev committed Sep 30, 2023
1 parent 7182d8c commit 9a48b9b
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CreateThread(function()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local inRange = false
for k in pairs(Config.Registers) do
for k = 1, #Config.Registers do
local dist = #(pos - Config.Registers[k][1].xyz)
if dist <= 1 and Config.Registers[k].robbed then
inRange = true
Expand All @@ -51,7 +51,7 @@ CreateThread(function()
local inRange = false
if QBCore ~= nil then
local pos = GetEntityCoords(PlayerPedId())
for safe,_ in pairs(Config.Safes) do
for safe = 1, #Config.Safes do
local dist = #(pos - Config.Safes[safe][1].xyz)
if dist < 3 then
inRange = true
Expand All @@ -67,15 +67,17 @@ CreateThread(function()
if math.random(100) <= 50 then
TriggerServerEvent('hud:server:GainStress', math.random(1, 3))
end

if Config.Safes[safe].type == "keypad" then
SendNUIMessage({
action = "openKeypad",
})
SetNuiFocus(true, true)
else
QBCore.Functions.TriggerCallback('qb-storerobbery:server:getPadlockCombination', function(combination)
TriggerEvent("SafeCracker:StartMinigame", combination)
end, safe)
QBCore.Functions.TriggerCallback('qb-storerobbery:server:getPadlockCombination',
function(combination)
TriggerEvent("SafeCracker:StartMinigame", combination)
end, safe)
end

if not copsCalled then
Expand All @@ -87,11 +89,14 @@ CreateThread(function()
if street2 ~= nil then
streetLabel = streetLabel .. " " .. street2
end
TriggerServerEvent("qb-storerobbery:server:callCops", "safe", currentSafe, streetLabel, pos)
TriggerServerEvent("qb-storerobbery:server:callCops", "safe", currentSafe,
streetLabel, pos)
copsCalled = true
end
else
QBCore.Functions.Notify(Lang:t("error.minimum_store_robbery_police", { MinimumStoreRobberyPolice = Config.MinimumStoreRobberyPolice}), "error")
QBCore.Functions.Notify(
Lang:t("error.minimum_store_robbery_police",
{ MinimumStoreRobberyPolice = Config.MinimumStoreRobberyPolice }), "error")
end
end
else
Expand Down Expand Up @@ -128,7 +133,7 @@ end)

RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
usingAdvanced = isAdvanced
for k in pairs(Config.Registers) do
for k = 1, #Config.Registers do
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local dist = #(pos - Config.Registers[k][1].xyz)
Expand All @@ -148,7 +153,8 @@ RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
if street2 ~= nil then
streetLabel = streetLabel .. " " .. street2
end
TriggerServerEvent("qb-storerobbery:server:callCops", "cashier", currentRegister, streetLabel, pos)
TriggerServerEvent("qb-storerobbery:server:callCops", "cashier", currentRegister, streetLabel,
pos)
copsCalled = true
end
else
Expand All @@ -165,14 +171,15 @@ RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
if street2 ~= nil then
streetLabel = streetLabel .. " " .. street2
end
TriggerServerEvent("qb-storerobbery:server:callCops", "cashier", currentRegister, streetLabel, pos)
TriggerServerEvent("qb-storerobbery:server:callCops", "cashier", currentRegister, streetLabel,
pos)
copsCalled = true
end

end

else
QBCore.Functions.Notify(Lang:t("error.minimum_store_robbery_police", { MinimumStoreRobberyPolice = Config.MinimumStoreRobberyPolice}), "error")
QBCore.Functions.Notify(
Lang:t("error.minimum_store_robbery_police",
{ MinimumStoreRobberyPolice = Config.MinimumStoreRobberyPolice }), "error")
end
end
end
Expand All @@ -197,22 +204,22 @@ end

function setupRegister()
QBCore.Functions.TriggerCallback('qb-storerobbery:server:getRegisterStatus', function(Registers)
for k in pairs(Registers) do
for k = 1, #Registers do
Config.Registers[k].robbed = Registers[k].robbed
end
end)
end

function setupSafes()
QBCore.Functions.TriggerCallback('qb-storerobbery:server:getSafeStatus', function(Safes)
for k in pairs(Safes) do
for k = 1, #Safes do
Config.Safes[k].robbed = Safes[k].robbed
end
end)
end

DrawText3Ds = function(coords, text)
SetTextScale(0.35, 0.35)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
Expand All @@ -222,7 +229,7 @@ DrawText3Ds = function(coords, text)
SetDrawOrigin(coords, 0)
EndTextCommandDisplayText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end

Expand Down Expand Up @@ -261,25 +268,26 @@ RegisterNUICallback('success', function(_, cb)
TriggerServerEvent('qb-storerobbery:server:setRegisterStatus', currentRegister)
local lockpickTime = 25000
LockpickDoorAnim(lockpickTime)
QBCore.Functions.Progressbar("search_register", Lang:t("text.emptying_the_register"), lockpickTime, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "veh@break_in@0h@p_m_one@",
anim = "low_force_entry_ds",
flags = 16,
}, {}, {}, function() -- Done
openingDoor = false
ClearPedTasks(PlayerPedId())
TriggerServerEvent('qb-storerobbery:server:takeMoney', currentRegister, true)
end, function() -- Cancel
openingDoor = false
ClearPedTasks(PlayerPedId())
QBCore.Functions.Notify(Lang:t("error.process_canceled"), "error")
currentRegister = 0
end)
QBCore.Functions.Progressbar("search_register", Lang:t("text.emptying_the_register"), lockpickTime, false, true,
{
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "veh@break_in@0h@p_m_one@",
anim = "low_force_entry_ds",
flags = 16,
}, {}, {}, function() -- Done
openingDoor = false
ClearPedTasks(PlayerPedId())
TriggerServerEvent('qb-storerobbery:server:takeMoney', currentRegister, true)
end, function() -- Cancel
openingDoor = false
ClearPedTasks(PlayerPedId())
QBCore.Functions.Notify(Lang:t("error.process_canceled"), "error")
currentRegister = 0
end)
CreateThread(function()
while openingDoor do
TriggerServerEvent('hud:server:GainStress', math.random(1, 3))
Expand All @@ -297,7 +305,8 @@ end)
function LockpickDoorAnim(time)
time = time / 1000
loadAnimDict("veh@break_in@0h@p_m_one@")
TaskPlayAnim(PlayerPedId(), "veh@break_in@0h@p_m_one@", "low_force_entry_ds" ,3.0, 3.0, -1, 16, 0, false, false, false)
TaskPlayAnim(PlayerPedId(), "veh@break_in@0h@p_m_one@", "low_force_entry_ds", 3.0, 3.0, -1, 16, 0, false, false,
false)
openingDoor = true
CreateThread(function()
while openingDoor do
Expand Down Expand Up @@ -366,7 +375,7 @@ RegisterNUICallback("CombinationFail", function(_, cb)
cb("ok")
end)

RegisterNUICallback('fail', function(_ ,cb)
RegisterNUICallback('fail', function(_, cb)
if usingAdvanced then
if math.random(1, 100) < 20 then
TriggerServerEvent("qb-storerobbery:server:removeAdvancedLockpick")
Expand Down Expand Up @@ -421,10 +430,10 @@ end)

RegisterNetEvent('qb-storerobbery:client:setRegisterStatus', function(batch, val)
-- Has to be a better way maybe like adding a unique id to identify the register
if(type(batch) ~= "table") then
if (type(batch) ~= "table") then
Config.Registers[batch] = val
else
for k in pairs(batch) do
for k = 1, #batch do
Config.Registers[k] = batch[k]
end
end
Expand Down

0 comments on commit 9a48b9b

Please sign in to comment.