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

refactor(client/doors): function organization #14

Merged
merged 2 commits into from
Jan 3, 2024
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
114 changes: 89 additions & 25 deletions client/doors.lua
Original file line number Diff line number Diff line change
@@ -1,59 +1,123 @@
local bigBanks = require 'config.shared'.bigBanks
local sharedConfig = require 'config.shared'

local function resetDoor(object, bank)
local heading = bank.isOpened and bank.heading.open or bank.heading.closed
SetEntityHeading(object, heading)
end

function ResetBankDoors()
for k in pairs(sharedConfig.smallBanks) do
local coords = sharedConfig.smallBanks[k].coords
local object = GetClosestObjectOfType(coords.x, coords.y, coords.z, 5.0, sharedConfig.smallBanks[k].object, false, false, false)
resetDoor(object, sharedConfig.smallBanks[k])
end

local paletoCoords = sharedConfig.bigBanks.paleto.coords
local paletoObject = GetClosestObjectOfType(paletoCoords.x, paletoCoords.y, paletoCoords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
resetDoor(paletoObject, sharedConfig.bigBanks.paleto)

local pacificCoords = sharedConfig.bigBanks.pacific.coords[2]
local pacificObject = GetClosestObjectOfType(pacificCoords.x, pacificCoords.y, pacificCoords.z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
resetDoor(pacificObject, sharedConfig.bigBanks.pacific)
end

--- This will open the bank door of any small bank
--- @param bankId number
--- @return nil
function OpenFleecaDoor(bankId)
local object = GetClosestObjectOfType(sharedConfig.smallBanks[bankId].coords.x, sharedConfig.smallBanks[bankId].coords.y, sharedConfig.smallBanks[bankId].coords.z, 5.0, sharedConfig.smallBanks[bankId].object, false, false, false)
local entHeading = sharedConfig.smallBanks[bankId].heading.closed
if object ~= 0 then
CreateThread(function()
while entHeading ~= sharedConfig.smallBanks[bankId].heading.open do
SetEntityHeading(object, entHeading - 10)
entHeading -= 0.5
Wait(10)
end
end)
end
end

--- This will open the bank door of the pacific bank
--- @return nil
function OpenPacificDoor()
local object = GetClosestObjectOfType(sharedConfig.bigBanks.pacific.coords[2].x, sharedConfig.bigBanks.pacific.coords[2].y, sharedConfig.bigBanks.pacific.coords[2].z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
local entHeading = sharedConfig.bigBanks.pacific.heading.closed
if object ~= 0 then
CreateThread(function()
while entHeading > sharedConfig.bigBanks.pacific.heading.open do
SetEntityHeading(object, entHeading - 10)
entHeading -= 0.5
Wait(10)
end
end)
end
end

--- This will open the bank door of the paleto bank
--- @return nil
function OpenPaletoDoor()
--Config.DoorlockAction(4, false)
local object = GetClosestObjectOfType(sharedConfig.bigBanks.paleto.coords.x, sharedConfig.bigBanks.paleto.coords.y, sharedConfig.bigBanks.paleto.coords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, sharedConfig.bigBanks.paleto.heading.open)
end
end

RegisterNetEvent('qb-bankrobbery:client:ClearTimeoutDoors', function()
--Config.DoorlockAction(4, true)
local paletoObject = GetClosestObjectOfType(bigBanks.paleto.coords.x, bigBanks.paleto.coords.y, bigBanks.paleto.coords.z, 5.0, bigBanks.paleto.object, false, false, false)
local paletoObject = GetClosestObjectOfType(sharedConfig.bigBanks.paleto.coords.x, sharedConfig.bigBanks.paleto.coords.y, sharedConfig.bigBanks.paleto.coords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
if paletoObject ~= 0 then
SetEntityHeading(paletoObject, bigBanks.paleto.heading.closed)
SetEntityHeading(paletoObject, sharedConfig.bigBanks.paleto.heading.closed)
end
local object = GetClosestObjectOfType(bigBanks.pacific.coords[2].x, bigBanks.pacific.coords[2].y, bigBanks.pacific.coords[2].z, 20.0, bigBanks.pacific.object, false, false, false)
local object = GetClosestObjectOfType(sharedConfig.bigBanks.pacific.coords[2].x, sharedConfig.bigBanks.pacific.coords[2].y, sharedConfig.bigBanks.pacific.coords[2].z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, bigBanks.pacific.heading.closed)
SetEntityHeading(object, sharedConfig.bigBanks.pacific.heading.closed)
end
for k in pairs(bigBanks.pacific.lockers) do
bigBanks.pacific.lockers[k].isBusy = false
bigBanks.pacific.lockers[k].isOpened = false
for k in pairs(sharedConfig.bigBanks.pacific.lockers) do
sharedConfig.bigBanks.pacific.lockers[k].isBusy = false
sharedConfig.bigBanks.pacific.lockers[k].isOpened = false
end
for k in pairs(bigBanks.paleto.lockers) do
bigBanks.paleto.lockers[k].isBusy = false
bigBanks.paleto.lockers[k].isOpened = false
for k in pairs(sharedConfig.bigBanks.paleto.lockers) do
sharedConfig.bigBanks.paleto.lockers[k].isBusy = false
sharedConfig.bigBanks.paleto.lockers[k].isOpened = false
end
bigBanks.paleto.isOpened = false
bigBanks.pacific.isOpened = false
sharedConfig.bigBanks.paleto.isOpened = false
sharedConfig.bigBanks.pacific.isOpened = false
end)

CreateThread(function()
while true do
local pos = GetEntityCoords(cache.ped)
local paletoDist = #(pos - bigBanks.paleto.coords)
local pacificDist = #(pos - bigBanks.pacific.coords[2])
local paletoDist = #(pos - sharedConfig.bigBanks.paleto.coords)
local pacificDist = #(pos - sharedConfig.bigBanks.pacific.coords[2])
if paletoDist < 15 then
if bigBanks.paleto.isOpened then
if sharedConfig.bigBanks.paleto.isOpened then
--Config.DoorlockAction(4, false)
local object = GetClosestObjectOfType(bigBanks.paleto.coords.x, bigBanks.paleto.coords.y, bigBanks.paleto.coords.z, 5.0, bigBanks.paleto.object, false, false, false)
local object = GetClosestObjectOfType(sharedConfig.bigBanks.paleto.coords.x, sharedConfig.bigBanks.paleto.coords.y, sharedConfig.bigBanks.paleto.coords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, bigBanks.paleto.heading.open)
SetEntityHeading(object, sharedConfig.bigBanks.paleto.heading.open)
end
else
--Config.DoorlockAction(4, true)
local object = GetClosestObjectOfType(bigBanks.paleto.coords.x, bigBanks.paleto.coords.y, bigBanks.paleto.coords.z, 5.0, bigBanks.paleto.object, false, false, false)
local object = GetClosestObjectOfType(sharedConfig.bigBanks.paleto.coords.x, sharedConfig.bigBanks.paleto.coords.y, sharedConfig.bigBanks.paleto.coords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, bigBanks.paleto.heading.closed)
SetEntityHeading(object, sharedConfig.bigBanks.paleto.heading.closed)
end
end
end

-- Pacific Check
if pacificDist < 50 then
if bigBanks.pacific.isOpened then
local object = GetClosestObjectOfType(bigBanks.pacific.coords[2].x, bigBanks.pacific.coords[2].y, bigBanks.pacific.coords[2].z, 20.0, bigBanks.pacific.object, false, false, false)
if sharedConfig.bigBanks.pacific.isOpened then
local object = GetClosestObjectOfType(sharedConfig.bigBanks.pacific.coords[2].x, sharedConfig.bigBanks.pacific.coords[2].y, sharedConfig.bigBanks.pacific.coords[2].z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, bigBanks.pacific.heading.open)
SetEntityHeading(object, sharedConfig.bigBanks.pacific.heading.open)
end
else
local object = GetClosestObjectOfType(bigBanks.pacific.coords[2].x, bigBanks.pacific.coords[2].y, bigBanks.pacific.coords[2].z, 20.0, bigBanks.pacific.object, false, false, false)
local object = GetClosestObjectOfType(sharedConfig.bigBanks.pacific.coords[2].x, sharedConfig.bigBanks.pacific.coords[2].y, sharedConfig.bigBanks.pacific.coords[2].z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, bigBanks.pacific.heading.closed)
SetEntityHeading(object, sharedConfig.bigBanks.pacific.heading.closed)
end
end
end
Expand Down
80 changes: 7 additions & 73 deletions client/fleeca.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,24 @@ local copsCalled = false
local refreshed = false
local currentLocker = 0

local function resetDoor(object, bank)
local heading = bank.isOpened and bank.heading.open or bank.heading.closed
SetEntityHeading(object, heading)
end

local function resetBankDoors()
for k in pairs(sharedConfig.smallBanks) do
local coords = sharedConfig.smallBanks[k].coords
local object = GetClosestObjectOfType(coords.x, coords.y, coords.z, 5.0, sharedConfig.smallBanks[k].object, false, false, false)
resetDoor(object, sharedConfig.smallBanks[k])
end

local paletoCoords = sharedConfig.bigBanks.paleto.coords
local paletoObject = GetClosestObjectOfType(paletoCoords.x, paletoCoords.y, paletoCoords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
resetDoor(paletoObject, sharedConfig.bigBanks.paleto)

local pacificCoords = sharedConfig.bigBanks.pacific.coords[2]
local pacificObject = GetClosestObjectOfType(pacificCoords.x, pacificCoords.y, pacificCoords.z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
resetDoor(pacificObject, sharedConfig.bigBanks.pacific)
end

AddEventHandler('onResourceStop', function(resource)
if resource ~= cache.resource then return end
resetBankDoors()
ResetBankDoors()
end)

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local config1, config2, config3 = lib.callback.await('qb-bankrobbery:server:GetConfig', false)
sharedConfig.powerStations = config1
sharedConfig.bigBanks = config2
sharedConfig.smallBanks = config3
resetBankDoors()
ResetBankDoors()
isLoggedIn = true
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
isLoggedIn = false
end)

-- Functions

--- This will open the bank door of the paleto bank
--- @return nil
local function openPaletoDoor()
--Config.DoorlockAction(4, false)
local object = GetClosestObjectOfType(sharedConfig.bigBanks.paleto.coords.x, sharedConfig.bigBanks.paleto.coords.y, sharedConfig.bigBanks.paleto.coords.z, 5.0, sharedConfig.bigBanks.paleto.object, false, false, false)
if object ~= 0 then
SetEntityHeading(object, sharedConfig.bigBanks.paleto.heading.open)
end
end

--- This will open the bank door of the pacific bank
--- @return nil
local function openPacificDoor()
local object = GetClosestObjectOfType(sharedConfig.bigBanks.pacific.coords[2].x, sharedConfig.bigBanks.pacific.coords[2].y, sharedConfig.bigBanks.pacific.coords[2].z, 20.0, sharedConfig.bigBanks.pacific.object, false, false, false)
local entHeading = sharedConfig.bigBanks.pacific.heading.closed
if object ~= 0 then
CreateThread(function()
while entHeading > sharedConfig.bigBanks.pacific.heading.open do
SetEntityHeading(object, entHeading - 10)
entHeading -= 0.5
Wait(10)
end
end)
end
end

--- This is triggered once the hack at a small bank is done
--- @param success boolean
--- @return nil
Expand All @@ -86,23 +37,6 @@ local function onHackDone(success)
TriggerServerEvent('qb-bankrobbery:server:setBankState', closestBank)
end

--- This will open the bank door of any small bank
--- @param bankId number
--- @return nil
local function openBankDoor(bankId)
local object = GetClosestObjectOfType(sharedConfig.smallBanks[bankId].coords.x, sharedConfig.smallBanks[bankId].coords.y, sharedConfig.smallBanks[bankId].coords.z, 5.0, sharedConfig.smallBanks[bankId].object, false, false, false)
local entHeading = sharedConfig.smallBanks[bankId].heading.closed
if object ~= 0 then
CreateThread(function()
while entHeading ~= sharedConfig.smallBanks[bankId].heading.open do
SetEntityHeading(object, entHeading - 10)
entHeading -= 0.5
Wait(10)
end
end)
end
end

--- This will trigger the sequence of opening a safe locker of a bank
--- @param bankId string | number
--- @param lockerId number
Expand Down Expand Up @@ -294,13 +228,13 @@ end)
RegisterNetEvent('qb-bankrobbery:client:setBankState', function(bankId)
if bankId == 'paleto' then
sharedConfig.bigBanks.paleto.isOpened = true
openPaletoDoor()
OpenPaletoDoor()
elseif bankId == 'pacific' then
sharedConfig.bigBanks.pacific.isOpened = true
openPacificDoor()
OpenPacificDoor()
else
sharedConfig.smallBanks[bankId].isOpened = true
openBankDoor(bankId)
OpenFleecaDoor(bankId)
end
end)

Expand Down Expand Up @@ -399,7 +333,7 @@ CreateThread(function()
while true do
if closestBank ~= 0 then
if not refreshed then
resetBankDoors()
ResetBankDoors()
refreshed = true
end
else
Expand All @@ -410,7 +344,7 @@ CreateThread(function()
end)

CreateThread(function()
while true do -- This is kept for the resetBankDoors function to be executed outside of the polyzone
while true do -- This is kept for the ResetBankDoors function to be executed outside of the polyzone
local pos = GetEntityCoords(cache.ped)
local inRange = false
if isLoggedIn then
Expand Down
Loading