Skip to content

Commit

Permalink
refactor: namings and organization
Browse files Browse the repository at this point in the history
* refactor: style fixes

* fix: typos
  • Loading branch information
mafewtm authored Dec 11, 2023
1 parent 43b9c3c commit 2734df4
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 262 deletions.
31 changes: 3 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
# qbx_storerobbery (WIP)

A resource which gives the player the ability to rob the stores around the map!
244 changes: 121 additions & 123 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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'),
Expand All @@ -133,85 +94,122 @@ 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
})
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)
6 changes: 3 additions & 3 deletions config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ return {
},

registerRefresh = {
min = 420000,
max = 90000,
min = 90000,
max = 420000,
},

SafeReward = {
safeReward = {
markedBillsAmount = {
min = 1,
max = 3,
Expand Down
Loading

0 comments on commit 2734df4

Please sign in to comment.