QBCore = nil
local coreLoaded = false
Citizen.CreateThread(function()
while QBCore == nil do
TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end)
Citizen.Wait(200)
end
coreLoaded = true
end)
InBank = false
blips = {}
-- Functions
local function DrawText3Ds(x, y, z, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x,y,z, 0)
DrawText(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)
ClearDrawOrigin()
end
local function createBlips()
for k, v in pairs(Config.BankLocations) do
blips[k] = AddBlipForCoord(tonumber(v.x), tonumber(v.y), tonumber(v.z))
SetBlipSprite(blips[k], Config.Blip.blipType)
SetBlipDisplay(blips[k], 4)
SetBlipScale (blips[k], Config.Blip.blipScale)
SetBlipColour (blips[k], Config.Blip.blipColor)
SetBlipAsShortRange(blips[k], true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(tostring(Config.Blip.blipName))
EndTextCommandSetBlipName(blips[k])
end
end
local function removeBlips()
for k, v in pairs(Config.BankLocations) do
RemoveBlip(blips[k])
end
blips = {}
end
local function openAccountScreen()
QBCore.Functions.TriggerCallback('qb-banking:getBankingInformation', function(banking)
if banking ~= nil then
InBank = true
SetNuiFocus(true, true)
SendNUIMessage({
status = "openbank",
information = banking
})
end
end)
end
-- Events
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
createBlips()
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
removeBlips()
end)
RegisterNetEvent('qb-banking:transferError', function(msg)
SendNUIMessage({
status = "transferError",
error = msg
})
end)
RegisterNetEvent('qb-banking:successAlert', function(msg)
SendNUIMessage({
status = "successMessage",
message = msg
})
end)
RegisterNetEvent('qb-banking:eek:penBankScreen', function()
openAccountScreen()
end)
-- Loop
local letSleep = true
CreateThread(function()
while true do
Wait(1)
letSleep = true
if LocalPlayer.state.isLoggedIn and not InBank then
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed, true)
for k, v in pairs(Config.BankLocations) do
local bankDist = #(playerCoords - v)
if bankDist < 3.0 then
letSleep = false
DrawMarker(27, v.x, v.y, v.z-0.99, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.001, 1.0001, 0.5001, 0, 25, 165, 100, false, true, 2, false, false, false, false)
if bankDist < 1.0 then
DrawText3Ds(v.x, v.y, v.z-0.25, '~g~E~w~ - Access Bank')
if IsControlJustPressed(0, 38) then
openAccountScreen()
end
end
end
end
else
letSleep = false
end
if letSleep then
Wait(100)
end
end
end)
-- NUI
RegisterNetEvent("hidemenu", function()
InBank = false
SetNuiFocus(false, false)
SendNUIMessage({
status = "closebank"
})
end)
RegisterNetEvent('qb-banking:client:newCardSuccess', function(cardno, ctype)
SendNUIMessage({
status = "updateCard",
number = cardno,
cardtype = ctype
})
end)
-- NUI Callbacks
RegisterNUICallback("NUIFocusOff", function(data, cb)
InBank = false
SetNuiFocus(false, false)
SendNUIMessage({
status = "closebank"
})
end)
RegisterNUICallback("createSavingsAccount", function(data, cb)
TriggerServerEvent('qb-banking:createSavingsAccount')
end)
RegisterNUICallback("doDeposit", function(data, cb)
if tonumber(data.amount) ~= nil and tonumber(data.amount) > 0 then
TriggerServerEvent('qb-banking:doQuickDeposit', data.amount)
openAccountScreen()
end
end)
RegisterNUICallback("doWithdraw", function(data, cb)
if tonumber(data.amount) ~= nil and tonumber(data.amount) > 0 then
TriggerServerEvent('qb-banking:doQuickWithdraw', data.amount, true)
openAccountScreen()
end
end)
RegisterNUICallback("doATMWithdraw", function(data, cb)
if tonumber(data.amount) ~= nil and tonumber(data.amount) > 0 then
TriggerServerEvent('qb-banking:doQuickWithdraw', data.amount, false)
openAccountScreen()
end
end)
RegisterNUICallback("savingsDeposit", function(data, cb)
if tonumber(data.amount) ~= nil and tonumber(data.amount) > 0 then
TriggerServerEvent('qb-banking:savingsDeposit', data.amount)
openAccountScreen()
end
end)
RegisterNUICallback("requestNewCard", function(data, cb)
TriggerServerEvent('qb-banking:createNewCard')
end)
RegisterNUICallback("savingsWithdraw", function(data, cb)
if tonumber(data.amount) ~= nil and tonumber(data.amount) > 0 then
TriggerServerEvent('qb-banking:savingsWithdraw', data.amount)
openAccountScreen()
end
end)
RegisterNUICallback("doTransfer", function(data, cb)
if data ~= nil then
TriggerServerEvent('qb-banking:initiateTransfer', data)
end
end)
RegisterNUICallback("createDebitCard", function(data, cb)
if data.pin ~= nil then
TriggerServerEvent('qb-banking:createBankCard', data.pin)
end
end)
RegisterNUICallback("lockCard", function(data, cb)
TriggerServerEvent('qb-banking:toggleCard', true)
end)
RegisterNUICallback("unLockCard", function(data, cb)
TriggerServerEvent('qb-banking:toggleCard', false)
end)
RegisterNUICallback("updatePin", function(data, cb)
if data.pin ~= nil then
TriggerServerEvent('qb-banking:updatePin', data.pin)
end
end)