diff --git a/README.md b/README.md index a7230e1..e21a1b2 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,4 @@ -# qb-storerobbery -Gives the player the ability to rob the default stores around the map. Rob the registers through the use of the `lockpick` or `advancedlockpick` item. And crack the safes through minigames. -## Config -- OpenRegisterTime - - Determines how long the progressbar and animation will last when robbing a register with a `lockpick`. Prefferably this should be a number divisble by 2. Number in milliseconds. -- RegisterReward - - Minimum and maximum value that gets given to the player robbing a register. Reward is defaulted to cash - - ChanceAtSticky - - Percentage chance that the player will get a `stickynote` reward with the pin code to open the `keypad` safe type -- RegisterRefresh - - Minimum and maximum time it takes for a register to refresh after being robbed. Number in milliseconds. -- SafeReward - - MarkedBillsAmount - - Minimum and maximum amount of `markedbills` bags you get when robbing a safe. - - MarkedBillsWorth - - The value that should be added to the `markedbills` bags. - - ChanceAtSpecial - - Chance in percentage of the player also getting `rolex` item when robbing a safe. With minimum and max values. The chance is divided by 2 to determine if the player should also get `goldbar` item. Aka half the chance of `rolex`. -- SafeRefresh - - Time it takes for a safe to refresh after being robbed. Number in milliseconds. -- MinimumCops - - The amount of cops required to start a store robbery. To fend of grinders and force RolePlaying. -- NotEnoughCopsNotify - - Notify the player wheter or not there aren't enough cops when trying to rob. -- CallCopsTimeout - - To prevent police report spam. Only create a police alert _per_ player per timeout. Number in milliseconds. -- UseDrawText - - Wheter or not to use DrawTextUI or 3DText \ No newline at end of file +# qbx_storerobbery (WIP) + +A resource which gives the player the ability to rob the stores around the map! diff --git a/client/main.lua b/client/main.lua index 26bd437..cde2d04 100644 --- a/client/main.lua +++ b/client/main.lua @@ -2,11 +2,9 @@ local config = require 'config.client' local sharedConfig = require 'config.shared' local isUsingAdvanced local openingRegister -local openRegisterDict = 'veh@break_in@0h@p_m_one@' -local openRegisterAnim = 'low_force_entry_ds' local currentCombination -local function StartLockpick(bool) +local function startLockpick(bool) SetNuiFocus(bool, bool) SendNUIMessage({ action = "ui", @@ -15,111 +13,74 @@ local function StartLockpick(bool) SetCursorLocation(0.5, 0.2) end -local function OpeningRegisterHandler(LockpickTime) +local function openingRegisterHandler(lockpickTime) openingRegister = true - lib.requestAnimDict(openRegisterDict) - TaskPlayAnim(cache.ped, openRegisterDict, openRegisterAnim, 3.0, 3.0, -1, 16, 0, false, false, false) + lib.requestAnimDict('veh@break_in@0h@p_m_one@') + TaskPlayAnim(cache.ped, 'veh@break_in@0h@p_m_one@', 'low_force_entry_ds', 3.0, 3.0, -1, 16, 0, false, false, false) CreateThread(function() while openingRegister do - TaskPlayAnim(cache.ped, openRegisterDict, openRegisterAnim, 3.0, 3.0, -1, 16, 0, false, false, false) + TaskPlayAnim(cache.ped, 'veh@break_in@0h@p_m_one@', 'low_force_entry_ds', 3.0, 3.0, -1, 16, 0, false, false, false) Wait(2000) - LockpickTime = LockpickTime - 2000 - TriggerServerEvent('qb-storerobbery:server:openregister', false) + lockpickTime = lockpickTime - 2000 + TriggerServerEvent('qbx_storerobbery:server:registerOpened', false) TriggerServerEvent('hud:server:GainStress', math.random(1, 3)) - if LockpickTime <= 0 then + if lockpickTime <= 0 then openingRegister = false - StopAnimTask(cache.ped, openRegisterDict, openRegisterAnim, 1.0) + StopAnimTask(cache.ped, 'veh@break_in@0h@p_m_one@', 'low_force_entry_ds', 1.0) end end end) end -local function SafeAnim() +local function safeAnim() lib.requestAnimDict('amb@prop_human_bum_bin@idle_b') TaskPlayAnim(cache.ped, 'amb@prop_human_bum_bin@idle_b', 'idle_d', 8.0, 8.0, -1, 50, 0, false, false, false) Wait(2500) TaskPlayAnim(cache.ped, 'amb@prop_human_bum_bin@idle_b', 'exit', 8.0, 8.0, -1, 50, 0, false, false, false) end -lib.callback.register('qbx-storerobbery:client:getAlertChance', function() - local chance = config.policeAlertChance - if GetClockHours() >= 1 and GetClockHours() <= 6 then - chance = config.policeNightAlertChance - end - return chance +RegisterNetEvent('qbx_storerobbery:client:initRegisterAttempt', function(isAdvanced) + isUsingAdvanced = isAdvanced + startLockpick(true) end) -CreateThread(function() - local HasShownText - while true do - local PlayerCoords = GetEntityCoords(cache.ped) - local WaitTime = 800 - local Nearby = false - for i = 1, #sharedConfig.registers do - if #(PlayerCoords - sharedConfig.registers[i].coords) <= 1.4 and sharedConfig.registers[i].robbed then - WaitTime = 0 - Nearby = true - if config.useDrawText then - if not HasShownText then - HasShownText = true - lib.showTextUI(Lang:t('text.register_empty'), {position = 'left-center'}) - exports['qbx-core']:DrawText() - end - else - DrawText3D(Lang:t('text.register_empty'), sharedConfig.registers[i].coords) - end - end - end - if not Nearby and HasShownText then - HasShownText = false - lib.hideTextUI() - end - Wait(WaitTime) +RegisterNetEvent('qbx_storerobbery:client:initSafeAttempt', function(closestSafeIndex, combination) + currentCombination = combination + if sharedConfig.safes[closestSafeIndex].type == 'keypad' then + SendNUIMessage({ + action = 'openKeypad', + }) + SetNuiFocus(true, true) + else + TriggerEvent('SafeCracker:StartMinigame', currentCombination) end end) -CreateThread(function() - local HasShownText - while true do - local PlayerCoords = GetEntityCoords(cache.ped) - local WaitTime = 800 - local Nearby = false - local Text - for i = 1, #sharedConfig.safes do - if #(PlayerCoords - sharedConfig.safes[i].coords) <= 1.4 then - WaitTime = 0 - Nearby = true - if sharedConfig.safes[i].robbed then - Text = Lang:t('text.safe_opened') - else - Text = Lang:t('text.try_combination') - if IsControlJustPressed(0, 38) then - TriggerServerEvent('qb-storerobbery:server:trysafe') - end - end - if config.useDrawText then - if not HasShownText then - HasShownText = true - lib.showTextUI(Text, {position = 'left-center'}) - end - else - DrawText3D(Text, sharedConfig.safes[i].coords) - end - end - end - if not Nearby and HasShownText then HasShownText = false lib.hideTextUI() end - Wait(WaitTime) +RegisterNetEvent('SafeCracker:EndMinigame', function(hasWon) + if hasWon then + TriggerServerEvent('qbx_storerobbery:server:safeCracked') + safeAnim() + else + TriggerServerEvent('qbx_storerobbery:server:failedSafeCracking') end end) -RegisterNetEvent('qb-storerobbery:client:startRegister', function(IsAdvanced) - isUsingAdvanced = IsAdvanced - StartLockpick(true) +RegisterNetEvent('qbx_storerobbery:client:updatedRobbables', function(registers, safes) + sharedConfig.registers = registers + sharedConfig.safes = safes +end) + +lib.callback.register('qbx_storerobbery:client:getAlertChance', function() + local chance = config.policeAlertChance + if GetClockHours() >= 1 and GetClockHours() <= 6 then + chance = config.policeNightAlertChance + end + return chance end) RegisterNUICallback('success', function(_, cb) - StartLockpick(false) - OpeningRegisterHandler(config.openRegisterTime) + startLockpick(false) + openingRegisterHandler(config.openRegisterTime) if lib.progressBar({ duration = config.openRegisterTime, label = Lang:t('text.emptying_the_register'), @@ -133,81 +94,55 @@ RegisterNUICallback('success', function(_, cb) } }) then -- if completed openingRegister = false - TriggerServerEvent('qb-storerobbery:server:openregister', true) + TriggerServerEvent('qbx_storerobbery:server:registerOpened', true) else -- if canceled openingRegister = false - TriggerServerEvent('qb-storerobbery:server:cancelledregister') - QBCore.Functions.Notify(Lang:t('error.process_canceled'), 'error') + TriggerServerEvent('qbx_storerobbery:server:registerCanceled') + exports.qbx_core:Notify(Lang:t('error.process_canceled'), 'error') end cb('ok') end) RegisterNUICallback('fail', function(_, cb) - StartLockpick(false) + startLockpick(false) if not IsWearingGloves() then local FingerDropChance = isUsingAdvanced and math.random(0, 30) or math.random(0, 60) if FingerDropChance > math.random(0, 100) then TriggerServerEvent('evidence:server:CreateFingerDrop', GetEntityCoords(cache.ped)) end end - TriggerServerEvent('qb-storerobbery:server:failedregister', isUsingAdvanced) + TriggerServerEvent('qbx_storerobbery:server:registerFailed', isUsingAdvanced) cb('ok') end) RegisterNUICallback('exit', function(_, cb) - StartLockpick(false) - TriggerServerEvent('qb-storerobbery:server:exitedregister') + startLockpick(false) + TriggerServerEvent('qbx_storerobbery:server:registerExited') cb('ok') end) -RegisterNetEvent('qb-storerobbery:client:syncconfig', function(Registers, Safes) - sharedConfig.registers = Registers - sharedConfig.safes = Safes -end) - -RegisterNetEvent('qb-storerobbery:client:trysafe', function(ClosestSafeIndex, Combination) - currentCombination = Combination - if sharedConfig.safes[ClosestSafeIndex].type == 'keypad' then - SendNUIMessage({ - action = 'openKeypad', - }) - SetNuiFocus(true, true) - else - TriggerEvent('SafeCracker:StartMinigame', currentCombination) - end -end) - -RegisterNetEvent('SafeCracker:EndMinigame', function(HasWon) - if HasWon then - TriggerServerEvent('qb-storerobbery:server:successsafe') - SafeAnim() - else - TriggerServerEvent('qb-storerobbery:server:failedsafe') - end -end) - -RegisterNUICallback('PadLockClose', function(_, cb) +RegisterNUICallback('padLockClose', function(_, cb) SetNuiFocus(false, false) - TriggerServerEvent('qb-storerobbery:server:failedsafe') + TriggerServerEvent('qbx_storerobbery:server:failedSafeCracking') cb('ok') end) -RegisterNUICallback('CombinationFail', function(_, cb) - local SoundId = GetSoundId() - PlaySound(SoundId, 'Place_Prop_Fail', 'DLC_Dmod_Prop_Editor_Sounds', false, 0, true) - ReleaseSoundId(SoundId) +RegisterNUICallback('combinationFail', function(_, cb) + local soundId = GetSoundId() + PlaySound(soundId, 'Place_Prop_Fail', 'DLC_Dmod_Prop_Editor_Sounds', false, 0, true) + ReleaseSoundId(soundId) cb('ok') end) -RegisterNUICallback('TryCombination', function(data, cb) +RegisterNUICallback('tryCombination', function(data, cb) SetNuiFocus(false, false) if tonumber(data.combination) == currentCombination then - TriggerServerEvent('qb-storerobbery:server:successsafe') + TriggerServerEvent('qbx_storerobbery:server:safeCracked') SendNUIMessage({ action = "closeKeypad", error = false }) - SafeAnim() + safeAnim() else - TriggerServerEvent('qb-storerobbery:server:failedsafe') + TriggerServerEvent('qbx_storerobbery:server:failedSafeCracking') SendNUIMessage({ action = "closeKeypad", error = true @@ -215,3 +150,66 @@ RegisterNUICallback('TryCombination', function(data, cb) end cb('ok') end) + +CreateThread(function() + local hasShownText + while true do + local coords = GetEntityCoords(cache.ped) + local time = 800 + local nearby = false + for i = 1, #sharedConfig.registers do + if #(coords - sharedConfig.registers[i].coords) <= 1.4 and sharedConfig.registers[i].robbed then + time = 0 + nearby = true + if config.useDrawText then + if not hasShownText then + hasShownText = true + lib.showTextUI(Lang:t('text.register_empty'), {position = 'left-center'}) + exports['qbx-core']:DrawText() + end + else + DrawText3D(Lang:t('text.register_empty'), sharedConfig.registers[i].coords) + end + end + end + if not nearby and hasShownText then + hasShownText = false + lib.hideTextUI() + end + Wait(time) + end +end) + +CreateThread(function() + local hasShownText + while true do + local coords = GetEntityCoords(cache.ped) + local time = 800 + local nearby = false + local text + for i = 1, #sharedConfig.safes do + if #(coords - sharedConfig.safes[i].coords) <= 1.4 then + time = 0 + nearby = true + if sharedConfig.safes[i].robbed then + text = Lang:t('text.safe_opened') + else + text = Lang:t('text.try_combination') + if IsControlJustPressed(0, 38) then + TriggerServerEvent('qbx_storerobbery:server:trySafe') + end + end + if config.useDrawText then + if not hasShownText then + hasShownText = true + lib.showTextUI(text, {position = 'left-center'}) + end + else + DrawText3D(text, sharedConfig.safes[i].coords) + end + end + end + if not nearby and hasShownText then hasShownText = false lib.hideTextUI() end + Wait(time) + end +end) diff --git a/html/script.js b/html/script.js index c1a99fd..798dc9c 100644 --- a/html/script.js +++ b/html/script.js @@ -38,7 +38,7 @@ Padlock.Open = function(data) { Padlock.Close = function() { $("#padlock").css("display", "none"); - $.post(`https://${GetParentResourceName()}/PadLockClose`); + $.post(`https://${GetParentResourceName()}/padLockClose`); } Keypad.Open = function(data) { @@ -69,9 +69,9 @@ Keypad.Open = function(data) { Keypad.Close = function(data) { $("#keypad").css("display", "none"); - $.post(`https://${GetParentResourceName()}/PadLockClose`); + $.post(`https://${GetParentResourceName()}/padLockClose`); if (data?.error) { - $.post(`https://${GetParentResourceName()}/CombinationFail`); + $.post(`https://${GetParentResourceName()}/combinationFail`); } } @@ -91,7 +91,7 @@ var CanConfirm = true; function submitForm(e) { $("#keypad").css("display", "none"); - $.post(`https://${GetParentResourceName()}/TryCombination`, JSON.stringify({ + $.post(`https://${GetParentResourceName()}/tryCombination`, JSON.stringify({ combination: e.value, })); }; diff --git a/server/main.lua b/server/main.lua index 8888139..496c272 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,215 +1,215 @@ local config = require 'config.server' local sharedConfig = require 'config.shared' -local StartedRegister = {} -local StartedSafe = {} -local SafeCodes = {} -local CalledCops = {} +local startedRegister = {} +local startedSafe = {} +local safeCodes = {} +local calledCops = {} local ITEMS = exports.ox_inventory:Items() -local function GetClosestRegister(Coords) - local ClosestRegisterIndex +local function getClosestRegister(coords) + local closestRegisterIndex for i = 1, #sharedConfig.registers do - if #(Coords - sharedConfig.registers[i].coords) <= 2 then - if ClosestRegisterIndex then - if #(Coords - sharedConfig.registers[i].coords) < #(Coords - sharedConfig.registers[ClosestRegisterIndex].coords) then - ClosestRegisterIndex = i + if #(coords - sharedConfig.registers[i].coords) <= 2 then + if closestRegisterIndex then + if #(coords - sharedConfig.registers[i].coords) < #(coords - sharedConfig.registers[closestRegisterIndex].coords) then + closestRegisterIndex = i end else - ClosestRegisterIndex = i + closestRegisterIndex = i end end end - return ClosestRegisterIndex + return closestRegisterIndex end -local function GetClosestSafe(Coords) - local ClosestSafeIndex +local function getClosestSafe(coords) + local closestSafeIndex for i = 1, #sharedConfig.safes do - if #(Coords - sharedConfig.safes[i].coords) <= 2 then - ClosestSafeIndex = i + if #(coords - sharedConfig.safes[i].coords) <= 2 then + closestSafeIndex = i end end - return ClosestSafeIndex + return closestSafeIndex end local function alertPolice(text, source, camId) - if CalledCops[source] then return end + if calledCops[source] then return end - local chance = lib.callback.await('qbx-storerobbery:client:getAlertChance', source) + local chance = lib.callback.await('qbx_storerobbery:client:getAlertChance', source) if math.random() <= chance then - CalledCops[source] = true + calledCops[source] = true TriggerEvent('police:server:policeAlert', text, camId, source) end SetTimeout(config.callCopsTimeout, function() - CalledCops[source] = false + calledCops[source] = false end) end -AddEventHandler('lockpicks:UseLockpick', function(PlayerSource, IsAdvanced) - local PlayerCoords = GetEntityCoords(GetPlayerPed(PlayerSource)) - local ClosestRegisterIndex = GetClosestRegister(PlayerCoords) +AddEventHandler('lockpicks:UseLockpick', function(playerSource, isAdvanced) + local playerCoords = GetEntityCoords(GetPlayerPed(playerSource)) + local closestRegisterIndex = getClosestRegister(playerCoords) local leoCount = exports.qbx_core:GetDutyCountType('leo') - if not ClosestRegisterIndex then return end - if sharedConfig.registers[ClosestRegisterIndex].robbed then return end + if not closestRegisterIndex then return end + if sharedConfig.registers[closestRegisterIndex].robbed then return end if leoCount < config.minimumCops and config.notEnoughCopsNotify then - exports.qbx_core:Notify(PlayerSource, Lang:t('error.no_police', {Required = config.minimumCops}), 'error') + exports.qbx_core:Notify(playerSource, Lang:t('error.no_police', {Required = config.minimumCops}), 'error') return end - StartedRegister[PlayerSource] = true - sharedConfig.registers[ClosestRegisterIndex].robbed = true + startedRegister[playerSource] = true + sharedConfig.registers[closestRegisterIndex].robbed = true - alertPolice(Lang:t('alert.register'), PlayerSource, sharedConfig.registers[ClosestRegisterIndex].camId) - TriggerClientEvent('qb-storerobbery:client:startRegister', PlayerSource, IsAdvanced) + alertPolice(Lang:t('alert.register'), playerSource, sharedConfig.registers[closestRegisterIndex].camId) + TriggerClientEvent('qbx_storerobbery:client:initRegisterAttempt', playerSource, isAdvanced) end) -RegisterNetEvent('qb-storerobbery:server:failedregister', function(IsUsingAdvanced) - local Player = exports.qbx_core:GetPlayer(source) - local PlayerCoords = GetEntityCoords(GetPlayerPed(source)) - local ClosestRegisterIndex = GetClosestRegister(PlayerCoords) - local DeleteChance = IsUsingAdvanced and math.random(0, 30) or math.random(0, 60) +RegisterNetEvent('qbx_storerobbery:server:registerFailed', function(isUsingAdvanced) + local player = exports.qbx_core:GetPlayer(source) + local playerCoords = GetEntityCoords(GetPlayerPed(source)) + local closestRegisterIndex = getClosestRegister(playerCoords) + local deleteChance = isUsingAdvanced and math.random(0, 30) or math.random(0, 60) - StartedRegister[source] = false - sharedConfig.registers[ClosestRegisterIndex].robbed = false - if DeleteChance > math.random(0, 100) then + startedRegister[source] = false + sharedConfig.registers[closestRegisterIndex].robbed = false + if deleteChance > math.random(0, 100) then exports.qbx_core:Notify(source, Lang:t('error.lockpick_broken'), 'error') - if IsUsingAdvanced then - Player.Functions.RemoveItem('advancedlockpick', 1) + if isUsingAdvanced then + player.Functions.RemoveItem('advancedlockpick', 1) TriggerClientEvent('inventory:client:ItemBox', source, ITEMS['advancedlockpick'], 'remove') else - Player.Functions.RemoveItem('lockpick', 1) + player.Functions.RemoveItem('lockpick', 1) TriggerClientEvent('inventory:client:ItemBox', source, ITEMS['lockpick'], 'remove') end end end) -RegisterNetEvent('qb-storerobbery:server:exitedregister', function() - local PlayerCoords = GetEntityCoords(GetPlayerPed(source)) - local ClosestRegisterIndex = GetClosestRegister(PlayerCoords) - StartedRegister[source] = false - sharedConfig.registers[ClosestRegisterIndex].robbed = false +RegisterNetEvent('qbx_storerobbery:server:registerExited', function() + local playerCoords = GetEntityCoords(GetPlayerPed(source)) + local closestRegisterIndex = getClosestRegister(playerCoords) + startedRegister[source] = false + sharedConfig.registers[closestRegisterIndex].robbed = false end) -RegisterNetEvent('qb-storerobbery:server:cancelledregister', function() - StartedRegister[source] = false - TriggerClientEvent('qb-storerobbery:client:syncconfig', -1, sharedConfig.registers, sharedConfig.safes) +RegisterNetEvent('qbx_storerobbery:server:registerCanceled', function() + startedRegister[source] = false + TriggerClientEvent('qbx_storerobbery:client:updatedRobbables', -1, sharedConfig.registers, sharedConfig.safes) end) -RegisterNetEvent('qb-storerobbery:server:openregister', function(IsDone) - local Player = exports.qbx_core:GetPlayer(source) - local PlayerCoords = GetEntityCoords(GetPlayerPed(source)) - local ClosestRegisterIndex = GetClosestRegister(PlayerCoords) - local Amount = exports.qbx_core:GetDutyCountType('leo') +RegisterNetEvent('qbx_storerobbery:server:registerOpened', function(isDone) + local player = exports.qbx_core:GetPlayer(source) + local playerCoords = GetEntityCoords(GetPlayerPed(source)) + local closestRegisterIndex = getClosestRegister(playerCoords) + local amount = exports.qbx_core:GetDutyCountType('leo') - if not ClosestRegisterIndex then return end - if #(PlayerCoords - sharedConfig.registers[ClosestRegisterIndex].coords) > 2 then return end - if not StartedRegister[source] then return end - if Amount < config.minimumCops and config.notEnoughCopsNotify then + if not closestRegisterIndex then return end + if #(playerCoords - sharedConfig.registers[closestRegisterIndex].coords) > 2 then return end + if not startedRegister[source] then return end + if amount < config.minimumCops and config.notEnoughCopsNotify then exports.qbx_core:Notify(source, Lang:t('error.no_police', {Required = config.minimumCops}), 'error') return end - Player.Functions.AddMoney('cash', math.random(config.registerReward.min, config.registerReward.max)) + player.Functions.AddMoney('cash', math.random(config.registerReward.min, config.registerReward.max)) - if not IsDone then return end + if not isDone then return end - TriggerClientEvent('qb-storerobbery:client:syncconfig', -1, sharedConfig.registers, sharedConfig.safes) + TriggerClientEvent('qbx_storerobbery:client:updatedRobbables', -1, sharedConfig.registers, sharedConfig.safes) if config.registerReward.chanceAtSticky > math.random(0, 100) then - local Code = SafeCodes[sharedConfig.registers[ClosestRegisterIndex].safeKey] - local Info - if sharedConfig.safes[sharedConfig.registers[ClosestRegisterIndex].safeKey].type == 'keypad' then - Info = { - label = Lang:t('text.safe_code') .. tostring(Code) + local code = safeCodes[sharedConfig.registers[closestRegisterIndex].safeKey] + local info + if sharedConfig.safes[sharedConfig.registers[closestRegisterIndex].safeKey].type == 'keypad' then + info = { + label = Lang:t('text.safe_code') .. tostring(code) } else - Info = { - label = Lang:t('text.safe_code') .. tostring(math.floor((Code[1] % 360) / 3.60)) .. "-" .. tostring(math.floor((Code[2] % 360) / 3.60)) .. "-" .. tostring(math.floor((Code[3] % 360) / 3.60)) .. "-" .. tostring(math.floor((Code[4] % 360) / 3.60)) .. "-" .. tostring(math.floor((Code[5] % 360) / 3.60)) + info = { + label = Lang:t('text.safe_code') .. tostring(math.floor((code[1] % 360) / 3.60)) .. "-" .. tostring(math.floor((code[2] % 360) / 3.60)) .. "-" .. tostring(math.floor((code[3] % 360) / 3.60)) .. "-" .. tostring(math.floor((code[4] % 360) / 3.60)) .. "-" .. tostring(math.floor((code[5] % 360) / 3.60)) } end - Player.Functions.AddItem('stickynote', 1, false, Info) + player.Functions.AddItem('stickynote', 1, false, info) TriggerClientEvent('inventory:client:ItemBox', source, ITEMS['stickynote'], 'add') end - StartedRegister[source] = false + startedRegister[source] = false SetTimeout(math.random(config.registerRefresh.min, config.registerRefresh.max), function() - sharedConfig.registers[ClosestRegisterIndex].robbed = false - TriggerClientEvent('qb-storerobbery:client:syncconfig', -1, sharedConfig.registers, sharedConfig.safes) + sharedConfig.registers[closestRegisterIndex].robbed = false + TriggerClientEvent('qbx_storerobbery:client:updatedRobbables', -1, sharedConfig.registers, sharedConfig.safes) end) end) -RegisterNetEvent('qb-storerobbery:server:trysafe', function() +RegisterNetEvent('qbx_storerobbery:server:trySafe', function() local src = GetPlayerPed(source) - local PlayerCoords = GetEntityCoords(src) - local ClosestSafeIndex = GetClosestSafe(PlayerCoords) + local playerCoords = GetEntityCoords(src) + local closestSafeIndex = getClosestSafe(playerCoords) local leoCount = exports.qbx_core:GetDutyCountType('leo') - if not ClosestSafeIndex then return end + if not closestSafeIndex then return end if leoCount < config.minimumCops and config.notEnoughCopsNotify then exports.qbx_core:Notify(source, Lang:t('error.no_police', {Required = config.minimumCops}), 'error') return end - sharedConfig.safes[ClosestSafeIndex].robbed = true - StartedSafe[source] = true - alertPolice(Lang:t('alert.safe'), source, sharedConfig.safes[ClosestSafeIndex].camId) - TriggerClientEvent('qb-storerobbery:client:trysafe', source, ClosestSafeIndex, SafeCodes[ClosestSafeIndex]) + sharedConfig.safes[closestSafeIndex].robbed = true + startedSafe[source] = true + alertPolice(Lang:t('alert.safe'), source, sharedConfig.safes[closestSafeIndex].camId) + TriggerClientEvent('qbx_storerobbery:client:initSafeAttempt', source, closestSafeIndex, safeCodes[closestSafeIndex]) end) -RegisterNetEvent('qb-storerobbery:server:failedsafe', function() - local PlayerCoords = GetEntityCoords(GetPlayerPed(source)) - local ClosestSafeIndex = GetClosestSafe(PlayerCoords) - sharedConfig.safes[ClosestSafeIndex].robbed = false - StartedSafe[source] = false +RegisterNetEvent('qbx_storerobbery:server:failedSafeCracking', function() + local playerCoords = GetEntityCoords(GetPlayerPed(source)) + local closestSafeIndex = getClosestSafe(playerCoords) + sharedConfig.safes[closestSafeIndex].robbed = false + startedSafe[source] = false end) -RegisterNetEvent('qb-storerobbery:server:successsafe', function() - local Player = exports.qbx_core:GetPlayer(source) - local PlayerCoords = GetEntityCoords(GetPlayerPed(source)) - local ClosestSafeIndex = GetClosestSafe(PlayerCoords) +RegisterNetEvent('qbx_storerobbery:server:safeCracked', function() + local player = exports.qbx_core:GetPlayer(source) + local playerCoords = GetEntityCoords(GetPlayerPed(source)) + local closestSafeIndex = getClosestSafe(playerCoords) local worthMarkedBills = math.random(config.safeReward.markedBillsWorth.min, config.safeReward.markedBillsWorth.max) local numMarkedBills = math.random(config.safeReward.markedBillsAmount.min, config.safeReward.markedBillsAmount.max) - if not ClosestSafeIndex then return end - if not StartedSafe[source] then return end + if not closestSafeIndex then return end + if not startedSafe[source] then return end local billsMeta = { worth = worthMarkedBills, description = Lang:t('text.value', { value = worthMarkedBills }) } - Player.Functions.AddItem('markedbills', numMarkedBills, false, billsMeta) + player.Functions.AddItem('markedbills', numMarkedBills, false, billsMeta) if config.safeReward.chanceAtSpecial > math.random(0, 100) then - Player.Functions.AddItem('rolex', math.random(config.safeReward.rolexAmount.min, config.safeReward.rolexAmount.max)) + player.Functions.AddItem('rolex', math.random(config.safeReward.rolexAmount.min, config.safeReward.rolexAmount.max)) TriggerClientEvent('inventory:client:ItemBox', source, ITEMS['rolex'], 'add') if config.safeReward.chanceAtSpecial / 2 > math.random(0, 100) then - Player.Functions.AddItem('goldbar', config.safeReward.goldbarAmount) + player.Functions.AddItem('goldbar', config.safeReward.goldbarAmount) TriggerClientEvent('inventory:client:ItemBox', source, ITEMS['goldbar'], 'add') end end - StartedSafe[source] = false - TriggerClientEvent('qb-storerobbery:client:syncconfig', -1, sharedConfig.registers, sharedConfig.safes) + startedSafe[source] = false + TriggerClientEvent('qbx_storerobbery:client:updatedRobbables', -1, sharedConfig.registers, sharedConfig.safes) SetTimeout(math.random(config.safeRefresh.min, config.safeRefresh.wax), function() - sharedConfig.safes[ClosestSafeIndex].robbed = false - TriggerClientEvent('qb-storerobbery:client:syncconfig', -1, sharedConfig.registers, sharedConfig.safes) + sharedConfig.safes[closestSafeIndex].robbed = false + TriggerClientEvent('qbx_storerobbery:client:updatedRobbables', -1, sharedConfig.registers, sharedConfig.safes) end) end) AddEventHandler('playerJoining', function(source) - TriggerClientEvent('qb-storerobbery:client:syncconfig', source, sharedConfig.registers, sharedConfig.safes) + TriggerClientEvent('qbx_storerobbery:client:updatedRobbables', source, sharedConfig.registers, sharedConfig.safes) end) CreateThread(function() while true do - SafeCodes = {} + safeCodes = {} for i = 1, #sharedConfig.safes, 1 do local Safe = sharedConfig.safes[i] if Safe.type == "padlock" then - SafeCodes[i] = { math.random(150, 450), math.random(1.0, 100.0), math.random(360, 450), math.random(300.0, 340.0), math.random(350, 400), math.random(320.0, 340.0), math.random(350, 600) } + safeCodes[i] = { math.random(150, 450), math.random(1.0, 100.0), math.random(360, 450), math.random(300.0, 340.0), math.random(350, 400), math.random(320.0, 340.0), math.random(350, 600) } elseif Safe.type == "keypad" then - SafeCodes[i] = math.random(1000, 9999) + safeCodes[i] = math.random(1000, 9999) else print('[ERROR] Incorrect Safe type!') end