mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
@@ -1,15 +1,16 @@
|
|||||||
<h1 align='center'>[ESX] Banking</a></h1><p align='center'><b><a href='https://discord.esx-framework.org/'>Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://docs.esx-framework.org/legacy/installation'>Documentation</a></b></h5>
|
<h1 align='center'>[ESX] Banking</a></h1><p align='center'><b><a href='https://discord.esx-framework.org/'>Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://docs.esx-framework.org/legacy/installation'>Documentation</a></b></h5>
|
||||||
|
|
||||||
A beautiful and Easy-To-Use Banking & ATM system for ESX, with optional OX Target Support
|
A beautiful and Easy-To-Use Banking & ATM system for ESX
|
||||||
|
|
||||||
|
|
||||||
## BANK UI
|
## BANK UI
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## ATM UI
|
## ATM UI
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Special thanks: Gellipapa#9186,Rav3n95#2849,Csoki, csontvazharcos, Füsti, Pécé
|
## Special thanks: Gellipapa#9186,Rav3n95#2849,Csoki, csontvazharcos, Füsti, Pécé
|
||||||
|
|
||||||
## Download & Installation
|
## Download & Installation
|
||||||
@@ -18,6 +19,7 @@ A beautiful and Easy-To-Use Banking & ATM system for ESX, with optional OX Targe
|
|||||||
- Put it in the `[esx-addons]` directory
|
- Put it in the `[esx-addons]` directory
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
- Add this to your `server.cfg`:
|
- Add this to your `server.cfg`:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -25,11 +27,13 @@ ensure esx_banking
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
|
|
||||||
```
|
```
|
||||||
Run the banking.sql into your database. Done.
|
Run the banking.sql into your database. Done.
|
||||||
```
|
```
|
||||||
|
|
||||||
# If you want to create a bank log in another script, you can do it this way! Only server side!
|
# If you want to create a bank log in another script, you can do it this way! Only server side!
|
||||||
|
|
||||||
```
|
```
|
||||||
exports["esx_banking"]:logTransaction(source,logType,amount)
|
exports["esx_banking"]:logTransaction(source,logType,amount)
|
||||||
|
|
||||||
@@ -41,7 +45,9 @@ For example: exports["esx_banking"]:logTransaction(source,"WITHDRAW",200)
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Legal
|
# Legal
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
esx_banking - banking script for ESX
|
esx_banking - banking script for ESX
|
||||||
|
|
||||||
Copyright (C) 2023 ESX-Framework
|
Copyright (C) 2023 ESX-Framework
|
||||||
|
|||||||
@@ -1,257 +1,260 @@
|
|||||||
local ActivateBlips = {}
|
local BANK = {
|
||||||
local PlayerLoaded = true
|
Data = {}
|
||||||
local isInMarker, isInAtmMarker, isInMenu, isMarkerShowed = false, false, false, false
|
}
|
||||||
local _GetEntityCoords, _PlayerPedId
|
|
||||||
|
local activeBlips, bankPoints, atmPoints, markerPoints = {}, {}, {}, {}
|
||||||
-- Functions
|
local playerLoaded, uiActive, inMenu = false, false, false
|
||||||
|
|
||||||
-- Listen for keypress while player inside the marker
|
--Functions
|
||||||
local function Listen4Key()
|
-- General data collecting thread
|
||||||
CreateThread(function()
|
function BANK:Thread()
|
||||||
while (isInMarker or isInAtmMarker) and not isInMenu do
|
self:CreateBlips()
|
||||||
if IsControlJustReleased(0, 38) then
|
local data = self.Data
|
||||||
OpenUi(isInAtmMarker)
|
data.ped = PlayerPedId()
|
||||||
end
|
data.coord = GetEntityCoords(data.Ped)
|
||||||
Wait(0)
|
playerLoaded = true
|
||||||
end
|
|
||||||
end)
|
CreateThread(function ()
|
||||||
end
|
while playerLoaded do
|
||||||
|
data.coord = GetEntityCoords(data.ped)
|
||||||
-- Create Blips
|
data.ped = PlayerPedId()
|
||||||
local function CreateBlips()
|
bankPoints, atmPoints, markerPoints = {}, {}, {}
|
||||||
local tmpActiveBlips = {}
|
|
||||||
for i = 1, #Config.Banks do
|
if (IsPedOnFoot(data.ped) and not ESX.PlayerData.dead) and not inMenu then
|
||||||
if type(Config.Banks[i].Blip) == 'table' and Config.Banks[i].Blip.Enabled then
|
for i = 1, #Config.AtmModels do
|
||||||
local blip = AddBlipForCoord(Config.Banks[i].Position.xy)
|
local atm = GetClosestObjectOfType(data.coord.x, data.coord.y, data.coord.z, 0.7, Config.AtmModels[i], false, false, false)
|
||||||
SetBlipSprite(blip, Config.Banks[i].Blip.Sprite)
|
if atm ~= 0 then
|
||||||
SetBlipScale(blip, Config.Banks[i].Blip.Scale)
|
atmPoints[#atmPoints+1] = GetEntityCoords(atm)
|
||||||
SetBlipColour(blip, Config.Banks[i].Blip.Color)
|
end
|
||||||
SetBlipAsShortRange(blip, true)
|
end
|
||||||
BeginTextCommandSetBlipName('STRING')
|
|
||||||
AddTextComponentSubstringPlayerName(Config.Banks[i].Blip.Label)
|
for i = 1, #Config.Banks do
|
||||||
EndTextCommandSetBlipName(blip)
|
local bankDistance = #(data.coord - Config.Banks[i].Position.xyz)
|
||||||
tmpActiveBlips[#tmpActiveBlips + 1] = blip
|
if bankDistance <= 0.7 then
|
||||||
end
|
bankPoints[#bankPoints+1] = Config.Banks[i].Position.xyz
|
||||||
end
|
end
|
||||||
|
if Config.ShowMarker and bankDistance <= (Config.DrawMarker or 10) then
|
||||||
ActivateBlips = tmpActiveBlips
|
markerPoints[#markerPoints+1] = Config.Banks[i].Position.xyz
|
||||||
end
|
end
|
||||||
|
end
|
||||||
-- Remove blips
|
end
|
||||||
local function RemoveBlips()
|
|
||||||
for i = 1, #ActivateBlips do
|
if next(bankPoints) and not uiActive then
|
||||||
if DoesBlipExist(ActivateBlips[i]) then
|
self:TextUi(true)
|
||||||
RemoveBlip(ActivateBlips[i])
|
end
|
||||||
end
|
|
||||||
end
|
if next(atmPoints) and not uiActive then
|
||||||
ActivateBlips = {}
|
self:TextUi(true, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function OpenUi(atm)
|
if not next(bankPoints) and not next(atmPoints) and uiActive then
|
||||||
atm = atm or false
|
self:TextUi(false)
|
||||||
isInMenu = true
|
end
|
||||||
ESX.HideUI()
|
|
||||||
ESX.TriggerServerCallback('esx_banking:getPlayerData', function(data)
|
Wait(1000)
|
||||||
SendNUIMessage({
|
end
|
||||||
showMenu = true,
|
end)
|
||||||
openATM = atm,
|
|
||||||
datas = {
|
if not Config.ShowMarker then return end
|
||||||
your_money_panel = {
|
|
||||||
accountsData = {{
|
CreateThread(function()
|
||||||
name = "cash",
|
local wait = 1000
|
||||||
amount = data.money
|
while playerLoaded do
|
||||||
}, {
|
if next(markerPoints) then
|
||||||
name = "bank",
|
for i = 1, #markerPoints do
|
||||||
amount = data.bankMoney
|
DrawMarker(20, markerPoints[i].x, markerPoints[i].y, markerPoints[i].z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.2, 187, 255, 0, 255, false, true, 2, false, nil, nil, false)
|
||||||
}}
|
end
|
||||||
},
|
wait = 0
|
||||||
bankCardData = {
|
end
|
||||||
bankName = TranslateCap('bank_name'),
|
Wait(wait)
|
||||||
cardNumber = "2232 2222 2222 2222",
|
end
|
||||||
createdDate = "08/08",
|
end)
|
||||||
name = data.playerName
|
end
|
||||||
},
|
|
||||||
transactionsData = data.transactionHistory
|
-- Handle text ui / Keypress
|
||||||
}
|
function BANK:TextUi(state, atm)
|
||||||
})
|
uiActive = state
|
||||||
end)
|
if not state then
|
||||||
SetNuiFocus(true, true)
|
return ESX.HideUI()
|
||||||
end
|
end
|
||||||
|
ESX.TextUI(TranslateCap('press_e_banking'))
|
||||||
local function CloseUi()
|
CreateThread(function()
|
||||||
SetNuiFocus(false, false)
|
while uiActive do
|
||||||
isInMenu = false
|
if IsControlJustReleased(0, 38) then
|
||||||
SendNUIMessage({
|
self:HandleUi(true, atm)
|
||||||
showMenu = false
|
self:TextUi(false)
|
||||||
})
|
end
|
||||||
|
Wait(0)
|
||||||
if (isInMarker or isInAtmMarker) then
|
end
|
||||||
ESX.TextUI(TranslateCap('press_e_banking'))
|
end)
|
||||||
Listen4Key()
|
end
|
||||||
end
|
|
||||||
end
|
-- Create Blips
|
||||||
|
function BANK:CreateBlips()
|
||||||
local function ShowMarker(coord)
|
local tmpActiveBlips = {}
|
||||||
CreateThread(function()
|
for i = 1, #Config.Banks do
|
||||||
while isMarkerShowed do
|
if type(Config.Banks[i].Blip) == 'table' and Config.Banks[i].Blip.Enabled then
|
||||||
DrawMarker(20, coord.x, coord.y, coord.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.2, 187, 255, 0, 255, false, true, 2, false, nil, nil, false)
|
local position = Config.Banks[i].Position
|
||||||
Wait(0)
|
local bInfo = Config.Banks[i].Blip
|
||||||
end
|
local blip = AddBlipForCoord(position.x, position.y, position.z)
|
||||||
end)
|
SetBlipSprite(blip, bInfo.Sprite)
|
||||||
end
|
SetBlipScale(blip, bInfo.Scale)
|
||||||
|
SetBlipColour(blip, bInfo.Color)
|
||||||
local function StartThread()
|
SetBlipAsShortRange(blip, true)
|
||||||
CreateThread(function()
|
BeginTextCommandSetBlipName('STRING')
|
||||||
CreateBlips()
|
AddTextComponentSubstringPlayerName(bInfo.Label)
|
||||||
|
EndTextCommandSetBlipName(blip)
|
||||||
while PlayerLoaded do
|
tmpActiveBlips[#tmpActiveBlips + 1] = blip
|
||||||
_PlayerPedId = PlayerPedId()
|
end
|
||||||
_GetEntityCoords = GetEntityCoords(_PlayerPedId)
|
end
|
||||||
local closestBank = {}
|
|
||||||
|
activeBlips = tmpActiveBlips
|
||||||
if IsPedOnFoot(PlayerPedId()) then
|
end
|
||||||
|
|
||||||
for i = 1, #Config.AtmModels do
|
-- Remove blips
|
||||||
local atm = GetClosestObjectOfType(_GetEntityCoords, 8.0, Config.AtmModels[i], false)
|
function BANK:RemoveBlips()
|
||||||
if atm ~= 0 then
|
for i = 1, #activeBlips do
|
||||||
local atmOffset = GetOffsetFromEntityInWorldCoords(atm, 0.0, -0.7, 0.0)
|
if DoesBlipExist(activeBlips[i]) then
|
||||||
local atmDistance = #(_GetEntityCoords - atmOffset)
|
RemoveBlip(activeBlips[i])
|
||||||
if not isInAtmMarker and atmDistance <= 1.5 then
|
end
|
||||||
isInAtmMarker = true
|
end
|
||||||
ESX.TextUI(TranslateCap('press_e_banking'))
|
activeBlips = {}
|
||||||
Listen4Key()
|
end
|
||||||
elseif isInAtmMarker and atmDistance > 1.5 then
|
|
||||||
isInAtmMarker = false
|
-- Open / Close ui
|
||||||
ESX.HideUI()
|
function BANK:HandleUi(state, atm)
|
||||||
end
|
atm = atm or false
|
||||||
end
|
SetNuiFocus(state, state)
|
||||||
end
|
inMenu = state
|
||||||
|
if not state then
|
||||||
for i = 1, #Config.Banks do
|
SendNUIMessage({
|
||||||
local bankDistance = #(_GetEntityCoords - Config.Banks[i].Position.xyz)
|
showMenu = false
|
||||||
|
})
|
||||||
if bankDistance <= Config.DrawMarker then
|
return
|
||||||
closestBank = {Config.Banks[i].Position, bankDistance}
|
end
|
||||||
end
|
ESX.TriggerServerCallback('esx_banking:getPlayerData', function(data)
|
||||||
end
|
SendNUIMessage({
|
||||||
|
showMenu = true,
|
||||||
if not isMarkerShowed and next(closestBank) then
|
openATM = atm,
|
||||||
isMarkerShowed = true
|
datas = {
|
||||||
ShowMarker(closestBank[1].xyz)
|
your_money_panel = {
|
||||||
elseif isMarkerShowed and not next(closestBank) then
|
accountsData = {{
|
||||||
isMarkerShowed = false
|
name = "cash",
|
||||||
end
|
amount = data.money
|
||||||
|
}, {
|
||||||
if next(closestBank) then
|
name = "bank",
|
||||||
if not isInMarker and closestBank[2] <= 1.0 then
|
amount = data.bankMoney
|
||||||
isInMarker = true
|
}}
|
||||||
ESX.TextUI(TranslateCap('press_e_banking'))
|
},
|
||||||
Listen4Key()
|
bankCardData = {
|
||||||
elseif isInMarker and closestBank[2] > 1.0 then
|
bankName = TranslateCap('bank_name'),
|
||||||
isInMarker = false
|
cardNumber = "2232 2222 2222 2222",
|
||||||
ESX.HideUI()
|
createdDate = "08/08",
|
||||||
end
|
name = data.playerName
|
||||||
elseif not next(closestBank) and isInMarker then
|
},
|
||||||
isInMarker = false
|
transactionsData = data.transactionHistory
|
||||||
ESX.HideUI()
|
}
|
||||||
end
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
Wait(1000)
|
|
||||||
end
|
function BANK:LoadNpc(index, netID)
|
||||||
end)
|
CreateThread(function()
|
||||||
end
|
while not NetworkDoesEntityExistWithNetworkId(netID) do
|
||||||
|
Wait(200)
|
||||||
-- NuiCallbacks
|
end
|
||||||
RegisterNUICallback('close', function(data, cb)
|
local npc = NetworkGetEntityFromNetworkId(netID)
|
||||||
CloseUi()
|
TaskStartScenarioInPlace(npc, Config.Peds[index].Scenario, 0, true)
|
||||||
cb('ok')
|
SetEntityProofs(npc, true, true, true, true, true, true, true, true)
|
||||||
end)
|
SetBlockingOfNonTemporaryEvents(npc, true)
|
||||||
|
FreezeEntityPosition(npc, true)
|
||||||
RegisterNUICallback('clickButton', function(data, cb)
|
SetPedCanRagdollFromPlayerImpact(npc, false)
|
||||||
if data ~= nil and isInMenu then
|
SetPedCanRagdoll(npc, false)
|
||||||
TriggerServerEvent("esx_banking:doingType", data)
|
SetEntityAsMissionEntity(npc, true, true)
|
||||||
end
|
SetEntityDynamic(npc, false)
|
||||||
cb('ok')
|
end)
|
||||||
end)
|
end
|
||||||
|
|
||||||
RegisterNUICallback('checkPincode', function(data, cb)
|
-- Events
|
||||||
if data ~= nil and isInMenu then
|
RegisterNetEvent('esx_banking:closebanking', function()
|
||||||
ESX.TriggerServerCallback("esx_banking:checkPincode", function(pincode)
|
BANK:HandleUi(false)
|
||||||
if pincode then
|
end)
|
||||||
cb({
|
|
||||||
success = true
|
RegisterNetEvent('esx_banking:pedHandler', function(netIdTable)
|
||||||
})
|
for i = 1, #netIdTable do
|
||||||
ESX.ShowNotification(TranslateCap('pincode_found'), "success")
|
BANK:LoadNpc(i, netIdTable[i])
|
||||||
|
end
|
||||||
else
|
end)
|
||||||
cb({
|
|
||||||
error = true
|
RegisterNetEvent('esx_banking:updateMoneyInUI', function(doingType, bankMoney, money)
|
||||||
})
|
SendNUIMessage({
|
||||||
ESX.ShowNotification(TranslateCap('pincode_not_found'), "error")
|
updateData = true,
|
||||||
end
|
data = {
|
||||||
end, data)
|
type = doingType,
|
||||||
end
|
bankMoney = bankMoney,
|
||||||
end)
|
money = money
|
||||||
|
}
|
||||||
-- Events
|
})
|
||||||
RegisterNetEvent('esx_banking:closebanking', function()
|
end)
|
||||||
CloseUi()
|
|
||||||
end)
|
-- Handlers
|
||||||
|
-- Resource starting
|
||||||
local function loadNPC(index, netID)
|
AddEventHandler('onResourceStart', function(resource)
|
||||||
CreateThread(function()
|
if resource ~= GetCurrentResourceName() then return end
|
||||||
while not NetworkDoesEntityExistWithNetworkId(netID) do
|
BANK:Thread()
|
||||||
Wait(200)
|
end)
|
||||||
end
|
|
||||||
local npc = NetworkGetEntityFromNetworkId(netID)
|
-- Enable the script on player loaded
|
||||||
|
RegisterNetEvent('esx:playerLoaded', function()
|
||||||
TaskStartScenarioInPlace(npc, Config.Peds[index].Scenario, 0, true)
|
BANK:Thread()
|
||||||
SetEntityProofs(npc, true, true, true, true, true, true, true, true)
|
end)
|
||||||
SetBlockingOfNonTemporaryEvents(npc, true)
|
|
||||||
FreezeEntityPosition(npc, true)
|
-- Disable the script on player logout
|
||||||
SetPedCanRagdollFromPlayerImpact(npc, false)
|
RegisterNetEvent('esx:onPlayerLogout', function()
|
||||||
SetPedCanRagdoll(npc, false)
|
playerLoaded = false
|
||||||
SetEntityAsMissionEntity(npc, true, true)
|
end)
|
||||||
SetEntityDynamic(npc, false)
|
|
||||||
end)
|
-- Resource stopping
|
||||||
end
|
AddEventHandler('onResourceStop', function(resource)
|
||||||
|
if resource ~= GetCurrentResourceName() then return end
|
||||||
RegisterNetEvent('esx_banking:PedHandler', function(netIdTable)
|
BANK:RemoveBlips()
|
||||||
for i = 1, #netIdTable do
|
if uiActive then BANK:TextUi(false) end
|
||||||
loadNPC(i, netIdTable[i])
|
end)
|
||||||
end
|
|
||||||
end)
|
RegisterNetEvent('esx:onPlayerDeath', function() BANK:TextUi(false) end)
|
||||||
|
|
||||||
RegisterNetEvent('esx_banking:updateMoneyInUI')
|
-- Nui Callbacks
|
||||||
AddEventHandler('esx_banking:updateMoneyInUI', function(doingType, bankMoney, money)
|
RegisterNUICallback('close', function(data, cb)
|
||||||
SendNUIMessage({
|
BANK:HandleUi(false)
|
||||||
updateData = true,
|
cb('ok')
|
||||||
data = {
|
end)
|
||||||
type = doingType,
|
|
||||||
bankMoney = bankMoney,
|
RegisterNUICallback('clickButton', function(data, cb)
|
||||||
money = money
|
if not data or not inMenu then
|
||||||
}
|
return cb('ok')
|
||||||
})
|
end
|
||||||
end)
|
|
||||||
|
TriggerServerEvent("esx_banking:doingType", data)
|
||||||
-- Resource starting
|
cb('ok')
|
||||||
AddEventHandler('onResourceStart', function(resource)
|
end)
|
||||||
if resource ~= GetCurrentResourceName() then return end
|
|
||||||
StartThread()
|
RegisterNUICallback('checkPincode', function(data, cb)
|
||||||
end)
|
if not data or not inMenu then
|
||||||
|
return cb('ok')
|
||||||
-- Enables it on player loaded
|
end
|
||||||
RegisterNetEvent('esx:playerLoaded', function()
|
|
||||||
StartThread()
|
ESX.TriggerServerCallback("esx_banking:checkPincode", function(pincode)
|
||||||
end)
|
if pincode then
|
||||||
|
cb({
|
||||||
-- Resource stopping
|
success = true
|
||||||
AddEventHandler('onResourceStop', function(resource)
|
})
|
||||||
if resource ~= GetCurrentResourceName() then return end
|
ESX.ShowNotification(TranslateCap('pincode_found'), "success")
|
||||||
RemoveBlips()
|
|
||||||
ESX.HideUI()
|
else
|
||||||
if isInMenu then
|
cb({
|
||||||
CloseUi()
|
error = true
|
||||||
end
|
})
|
||||||
end)
|
ESX.ShowNotification(TranslateCap('pincode_not_found'), "error")
|
||||||
|
end
|
||||||
|
end, data)
|
||||||
|
end)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Config = {
|
Config = {
|
||||||
Debug = false,
|
|
||||||
DrawMarker = 10,
|
DrawMarker = 10,
|
||||||
|
ShowMarker = true,
|
||||||
Locale = GetConvar('esx:locale', 'en'),
|
Locale = GetConvar('esx:locale', 'en'),
|
||||||
EnablePeds = true,
|
EnablePeds = true,
|
||||||
AtmModels = {`prop_fleeca_atm`, `prop_atm_01`, `prop_atm_02`, `prop_atm_03`},
|
AtmModels = {`prop_fleeca_atm`, `prop_atm_01`, `prop_atm_02`, `prop_atm_03`},
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ end)
|
|||||||
|
|
||||||
if Config.EnablePeds then
|
if Config.EnablePeds then
|
||||||
AddEventHandler('esx:playerLoaded', function(playerId)
|
AddEventHandler('esx:playerLoaded', function(playerId)
|
||||||
TriggerClientEvent('esx_banking:PedHandler', playerId, netIdTable)
|
TriggerClientEvent('esx_banking:pedHandler', playerId, netIdTable)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user