From edf8ea2e5dfc3417e4c49dc8344dfd3e4c46d9b5 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:31:57 +0100 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20esx=5Fstatus=20=F0=9F=8E=A8=20Run?= =?UTF-8?q?=20formatter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../esx_status/client/classes/status.lua | 92 +++--- .../[esx_addons]/esx_status/client/main.lua | 296 +++++++++--------- .../[esx_addons]/esx_status/fxmanifest.lua | 18 +- .../esx_status/server/classes/status.lua | 104 +++--- .../[esx_addons]/esx_status/server/main.lua | 86 ++--- 5 files changed, 298 insertions(+), 298 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_status/client/classes/status.lua b/server-data/resources/[esx_addons]/esx_status/client/classes/status.lua index 6476a2ce6..9d2d65231 100644 --- a/server-data/resources/[esx_addons]/esx_status/client/classes/status.lua +++ b/server-data/resources/[esx_addons]/esx_status/client/classes/status.lua @@ -1,48 +1,48 @@ function CreateStatus(name, default, color, visible, tickCallback) - local self = {} - - self.val = default - self.name = name - self.default = default - self.color = color - self.visible = visible - self.tickCallback = tickCallback - - function self._set(k, v) - self[k] = v - end - - function self._get(k) - return self[k] - end - - function self.onTick() - self.tickCallback(self) - end - - function self.set(val) - self.val = val - end - - function self.add(val) - if self.val + val > Config.StatusMax then - self.val = Config.StatusMax - else - self.val = self.val + val - end - end - - function self.remove(val) - if self.val - val < 0 then - self.val = 0 - else - self.val = self.val - val - end - end - - function self.getPercent() - return (self.val / Config.StatusMax) * 100 - end - - return self + local self = {} + + self.val = default + self.name = name + self.default = default + self.color = color + self.visible = visible + self.tickCallback = tickCallback + + function self._set(k, v) + self[k] = v + end + + function self._get(k) + return self[k] + end + + function self.onTick() + self.tickCallback(self) + end + + function self.set(val) + self.val = val + end + + function self.add(val) + if self.val + val > Config.StatusMax then + self.val = Config.StatusMax + else + self.val = self.val + val + end + end + + function self.remove(val) + if self.val - val < 0 then + self.val = 0 + else + self.val = self.val - val + end + end + + function self.getPercent() + return (self.val / Config.StatusMax) * 100 + end + + return self end diff --git a/server-data/resources/[esx_addons]/esx_status/client/main.lua b/server-data/resources/[esx_addons]/esx_status/client/main.lua index 5d81f2764..b075de99f 100644 --- a/server-data/resources/[esx_addons]/esx_status/client/main.lua +++ b/server-data/resources/[esx_addons]/esx_status/client/main.lua @@ -1,192 +1,192 @@ local Status, isPaused = {}, false function GetStatusData(minimal) - local status = {} - - for i = 1, #Status, 1 do - if minimal then - table.insert(status, { - name = Status[i].name, - val = Status[i].val, - percent = (Status[i].val / Config.StatusMax) * 100, - }) - else - table.insert(status, { - name = Status[i].name, - val = Status[i].val, - color = Status[i].color, - visible = Status[i].visible(Status[i]), - percent = (Status[i].val / Config.StatusMax) * 100, - }) - end - end - - return status + local status = {} + + for i = 1, #Status, 1 do + if minimal then + table.insert(status, { + name = Status[i].name, + val = Status[i].val, + percent = (Status[i].val / Config.StatusMax) * 100, + }) + else + table.insert(status, { + name = Status[i].name, + val = Status[i].val, + color = Status[i].color, + visible = Status[i].visible(Status[i]), + percent = (Status[i].val / Config.StatusMax) * 100, + }) + end + end + + return status end AddEventHandler("esx_status:registerStatus", function(name, default, color, visible, tickCallback) - local status = CreateStatus(name, default, color, visible, tickCallback) - table.insert(Status, status) + local status = CreateStatus(name, default, color, visible, tickCallback) + table.insert(Status, status) end) AddEventHandler("esx_status:unregisterStatus", function(name) - for k, v in ipairs(Status) do - if v.name == name then - table.remove(Status, k) - break - end - end + for k, v in ipairs(Status) do + if v.name == name then + table.remove(Status, k) + break + end + end end) RegisterNetEvent("esx:onPlayerLogout") AddEventHandler("esx:onPlayerLogout", function() - ESX.PlayerLoaded = false - Status = {} - if Config.Display then - SendNUIMessage({ - update = true, - status = Status, - }) - end + ESX.PlayerLoaded = false + Status = {} + if Config.Display then + SendNUIMessage({ + update = true, + status = Status, + }) + end end) RegisterNetEvent("esx_status:load") AddEventHandler("esx_status:load", function(status) - ESX.PlayerLoaded = true - TriggerEvent("esx_status:loaded") - for i = 1, #Status, 1 do - for j = 1, #status, 1 do - if Status[i].name == status[j].name then - Status[i].set(status[j].val) - end - end - end - - if Config.Display then - TriggerEvent("esx_status:setDisplay", 0.5) - end - - CreateThread(function() - local data = {} - while ESX.PlayerLoaded do - for i = 1, #Status do - Status[i].onTick() - table.insert(data, { - name = Status[i].name, - val = Status[i].val, - percent = (Status[i].val / 1000000) * 100, - }) - end - - if Config.Display then - local fullData = data - for i = 1, #data, 1 do - fullData[i].color = Status[i].color - fullData[i].visible = Status[i].visible(Status[i]) - end - SendNUIMessage({ - update = true, - status = fullData, - }) - end - - TriggerEvent("esx_status:onTick", data) - table.wipe(data) - Wait(Config.TickTime) - end - end) + ESX.PlayerLoaded = true + TriggerEvent("esx_status:loaded") + for i = 1, #Status, 1 do + for j = 1, #status, 1 do + if Status[i].name == status[j].name then + Status[i].set(status[j].val) + end + end + end + + if Config.Display then + TriggerEvent("esx_status:setDisplay", 0.5) + end + + CreateThread(function() + local data = {} + while ESX.PlayerLoaded do + for i = 1, #Status do + Status[i].onTick() + table.insert(data, { + name = Status[i].name, + val = Status[i].val, + percent = (Status[i].val / 1000000) * 100, + }) + end + + if Config.Display then + local fullData = data + for i = 1, #data, 1 do + fullData[i].color = Status[i].color + fullData[i].visible = Status[i].visible(Status[i]) + end + SendNUIMessage({ + update = true, + status = fullData, + }) + end + + TriggerEvent("esx_status:onTick", data) + table.wipe(data) + Wait(Config.TickTime) + end + end) end) RegisterNetEvent("esx_status:set") AddEventHandler("esx_status:set", function(name, val) - for i = 1, #Status, 1 do - if Status[i].name == name then - Status[i].set(val) - break - end - end - if Config.Display then - SendNUIMessage({ - update = true, - status = GetStatusData(), - }) - end + for i = 1, #Status, 1 do + if Status[i].name == name then + Status[i].set(val) + break + end + end + if Config.Display then + SendNUIMessage({ + update = true, + status = GetStatusData(), + }) + end end) RegisterNetEvent("esx_status:add") AddEventHandler("esx_status:add", function(name, val) - for i = 1, #Status, 1 do - if Status[i].name == name then - Status[i].add(val) - break - end - end - if Config.Display then - SendNUIMessage({ - update = true, - status = GetStatusData(), - }) - end + for i = 1, #Status, 1 do + if Status[i].name == name then + Status[i].add(val) + break + end + end + if Config.Display then + SendNUIMessage({ + update = true, + status = GetStatusData(), + }) + end end) RegisterNetEvent("esx_status:remove") AddEventHandler("esx_status:remove", function(name, val) - for i = 1, #Status, 1 do - if Status[i].name == name then - Status[i].remove(val) - break - end - end - if Config.Display then - SendNUIMessage({ - update = true, - status = GetStatusData(), - }) - end + for i = 1, #Status, 1 do + if Status[i].name == name then + Status[i].remove(val) + break + end + end + if Config.Display then + SendNUIMessage({ + update = true, + status = GetStatusData(), + }) + end end) AddEventHandler("esx_status:getStatus", function(name, cb) - for i = 1, #Status, 1 do - if Status[i].name == name then - cb(Status[i]) - return - end - end + for i = 1, #Status, 1 do + if Status[i].name == name then + cb(Status[i]) + return + end + end end) AddEventHandler("esx_status:setDisplay", function(val) - SendNUIMessage({ - setDisplay = true, - display = val, - }) + SendNUIMessage({ + setDisplay = true, + display = val, + }) end) -- Pause menu disable hud display if Config.Display then - AddEventHandler("esx:pauseMenuActive", function(state) - if state then - isPaused = true - TriggerEvent("esx_status:setDisplay", 0.0) - return - end - isPaused = false - TriggerEvent("esx_status:setDisplay", 0.5) - end) - - -- Loading screen off event - AddEventHandler("esx:loadingScreenOff", function() - if not isPaused then - TriggerEvent("esx_status:setDisplay", 0.3) - end - end) + AddEventHandler("esx:pauseMenuActive", function(state) + if state then + isPaused = true + TriggerEvent("esx_status:setDisplay", 0.0) + return + end + isPaused = false + TriggerEvent("esx_status:setDisplay", 0.5) + end) + + -- Loading screen off event + AddEventHandler("esx:loadingScreenOff", function() + if not isPaused then + TriggerEvent("esx_status:setDisplay", 0.3) + end + end) end -- Update server CreateThread(function() - while true do - Wait(Config.UpdateInterval) - if ESX.PlayerLoaded then - TriggerServerEvent("esx_status:update", GetStatusData(true)) - end - end + while true do + Wait(Config.UpdateInterval) + if ESX.PlayerLoaded then + TriggerServerEvent("esx_status:update", GetStatusData(true)) + end + end end) diff --git a/server-data/resources/[esx_addons]/esx_status/fxmanifest.lua b/server-data/resources/[esx_addons]/esx_status/fxmanifest.lua index 93ba3c357..c60e3344e 100644 --- a/server-data/resources/[esx_addons]/esx_status/fxmanifest.lua +++ b/server-data/resources/[esx_addons]/esx_status/fxmanifest.lua @@ -9,23 +9,23 @@ lua54("yes") shared_script("@es_extended/imports.lua") server_scripts({ - "@oxmysql/lib/MySQL.lua", - "config.lua", - "server/main.lua", + "@oxmysql/lib/MySQL.lua", + "config.lua", + "server/main.lua", }) client_scripts({ - "config.lua", - "client/classes/status.lua", - "client/main.lua", + "config.lua", + "client/classes/status.lua", + "client/main.lua", }) ui_page("html/ui.html") files({ - "html/ui.html", - "html/css/app.css", - "html/scripts/app.js", + "html/ui.html", + "html/css/app.css", + "html/scripts/app.js", }) dependency("es_extended") diff --git a/server-data/resources/[esx_addons]/esx_status/server/classes/status.lua b/server-data/resources/[esx_addons]/esx_status/server/classes/status.lua index 71de76936..e2792cf74 100644 --- a/server-data/resources/[esx_addons]/esx_status/server/classes/status.lua +++ b/server-data/resources/[esx_addons]/esx_status/server/classes/status.lua @@ -1,54 +1,54 @@ function CreateStatus(xPlayer, name, default, color, visible, tickCallback, clientAction) - local self = {} - - self.val = default - self.xPlayer = xPlayer - self.name = name - self.default = default - self.color = color - self.visible = visible - self.tickCallback = tickCallback - self.clientAction = clientAction - - function self._set(k, v) - self[k] = v - end - - function self._get(k) - return self[k] - end - - function self.onTick() - self.tickCallback(self) - end - - function self.set(val) - self.val = val - end - - function self.add(val) - if self.val + val > Config.StatusMax then - self.val = Config.StatusMax - else - self.val = self.val + val - end - end - - function self.remove(val) - if self.val - val < 0 then - self.val = 0 - else - self.val = self.val - val - end - end - - function self.getPercent() - return (self.val / Config.StatusMax) * 100 - end - - function self.updateClient() - TriggerEvent("esx_status:updateClient", self.xPlayer.source) - end - - return self + local self = {} + + self.val = default + self.xPlayer = xPlayer + self.name = name + self.default = default + self.color = color + self.visible = visible + self.tickCallback = tickCallback + self.clientAction = clientAction + + function self._set(k, v) + self[k] = v + end + + function self._get(k) + return self[k] + end + + function self.onTick() + self.tickCallback(self) + end + + function self.set(val) + self.val = val + end + + function self.add(val) + if self.val + val > Config.StatusMax then + self.val = Config.StatusMax + else + self.val = self.val + val + end + end + + function self.remove(val) + if self.val - val < 0 then + self.val = 0 + else + self.val = self.val - val + end + end + + function self.getPercent() + return (self.val / Config.StatusMax) * 100 + end + + function self.updateClient() + TriggerEvent("esx_status:updateClient", self.xPlayer.source) + end + + return self end diff --git a/server-data/resources/[esx_addons]/esx_status/server/main.lua b/server-data/resources/[esx_addons]/esx_status/server/main.lua index 3dda01f20..d54efe53c 100644 --- a/server-data/resources/[esx_addons]/esx_status/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_status/server/main.lua @@ -1,67 +1,67 @@ local function setPlayerStatus(xPlayer, data) - data = data and json.decode(data) or {} + data = data and json.decode(data) or {} - xPlayer.set("status", data) - ESX.Players[xPlayer.source] = data - TriggerClientEvent("esx_status:load", xPlayer.source, data) + xPlayer.set("status", data) + ESX.Players[xPlayer.source] = data + TriggerClientEvent("esx_status:load", xPlayer.source, data) end AddEventHandler("onResourceStart", function(resourceName) - if GetCurrentResourceName() ~= resourceName then - return - end + if GetCurrentResourceName() ~= resourceName then + return + end - for _, xPlayer in pairs(ESX.Players) do - MySQL.scalar("SELECT status FROM users WHERE identifier = ?", { xPlayer.identifier }, function(result) - setPlayerStatus(xPlayer, result) - end) - end + for _, xPlayer in pairs(ESX.Players) do + MySQL.scalar("SELECT status FROM users WHERE identifier = ?", { xPlayer.identifier }, function(result) + setPlayerStatus(xPlayer, result) + end) + end end) AddEventHandler("esx:playerLoaded", function(_, xPlayer) - MySQL.scalar("SELECT status FROM users WHERE identifier = ?", { xPlayer.identifier }, function(result) - setPlayerStatus(xPlayer, result) - end) + MySQL.scalar("SELECT status FROM users WHERE identifier = ?", { xPlayer.identifier }, function(result) + setPlayerStatus(xPlayer, result) + end) end) AddEventHandler("esx:playerDropped", function(playerId) - local xPlayer = ESX.GetPlayerFromId(playerId) - local status = ESX.Players[xPlayer.source] + local xPlayer = ESX.GetPlayerFromId(playerId) + local status = ESX.Players[xPlayer.source] - MySQL.update("UPDATE users SET status = ? WHERE identifier = ?", { json.encode(status), xPlayer.identifier }) - ESX.Players[xPlayer.source] = nil + MySQL.update("UPDATE users SET status = ? WHERE identifier = ?", { json.encode(status), xPlayer.identifier }) + ESX.Players[xPlayer.source] = nil end) AddEventHandler("esx_status:getStatus", function(playerId, statusName, cb) - local status = ESX.Players[playerId] - for i = 1, #status do - if status[i].name == statusName then - return cb(status[i]) - end - end + local status = ESX.Players[playerId] + for i = 1, #status do + if status[i].name == statusName then + return cb(status[i]) + end + end end) RegisterServerEvent("esx_status:update") AddEventHandler("esx_status:update", function(status) - local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer then - xPlayer.set("status", status) -- save to xPlayer for compatibility - ESX.Players[xPlayer.source] = status -- save locally for performance - end + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer then + xPlayer.set("status", status) -- save to xPlayer for compatibility + ESX.Players[xPlayer.source] = status -- save locally for performance + end end) CreateThread(function() - while true do - Wait(10 * 60 * 1000) - local parameters = {} - for _, xPlayer in pairs(ESX.GetExtendedPlayers()) do - local status = ESX.Players[xPlayer.source] - if status and next(status) then - parameters[#parameters + 1] = { json.encode(status), xPlayer.identifier } - end - end - if #parameters > 0 then - MySQL.prepare("UPDATE users SET status = ? WHERE identifier = ?", parameters) - end - end + while true do + Wait(10 * 60 * 1000) + local parameters = {} + for _, xPlayer in pairs(ESX.GetExtendedPlayers()) do + local status = ESX.Players[xPlayer.source] + if status and next(status) then + parameters[#parameters + 1] = { json.encode(status), xPlayer.identifier } + end + end + if #parameters > 0 then + MySQL.prepare("UPDATE users SET status = ? WHERE identifier = ?", parameters) + end + end end) From 33291467fd07b78841ec42f5bbd761d1de851bb1 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:41:41 +0100 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20esx=5Fbanking=20=F0=9F=8E=A8=20Run?= =?UTF-8?q?=20formatter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[esx_addons]/esx_banking/client/main.lua | 415 +++++++++-------- .../[esx_addons]/esx_banking/config.lua | 258 +++++------ .../[esx_addons]/esx_banking/server/main.lua | 436 +++++++++--------- 3 files changed, 585 insertions(+), 524 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_banking/client/main.lua b/server-data/resources/[esx_addons]/esx_banking/client/main.lua index 9b8e0e15c..931cbb6b2 100644 --- a/server-data/resources/[esx_addons]/esx_banking/client/main.lua +++ b/server-data/resources/[esx_addons]/esx_banking/client/main.lua @@ -1,5 +1,5 @@ local BANK = { - Data = {}, + Data = {}, } local activeBlips, bankPoints, atmPoints, markerPoints = {}, {}, {}, {} @@ -8,263 +8,300 @@ local playerLoaded, uiActive, inMenu = false, false, false --Functions -- General data collecting thread function BANK:Thread() - self:CreateBlips() - local data = self.Data - data.ped = PlayerPedId() - data.coord = GetEntityCoords(data.Ped) - playerLoaded = true + self:CreateBlips() + local data = self.Data + data.ped = PlayerPedId() + data.coord = GetEntityCoords(data.Ped) + playerLoaded = true - CreateThread(function() - while playerLoaded do - data.coord = GetEntityCoords(data.ped) - data.ped = PlayerPedId() - bankPoints, atmPoints, markerPoints = {}, {}, {} + CreateThread(function() + while playerLoaded do + data.coord = GetEntityCoords(data.ped) + data.ped = PlayerPedId() + bankPoints, atmPoints, markerPoints = {}, {}, {} - if (IsPedOnFoot(data.ped) and not ESX.PlayerData.dead) and not inMenu then - for i = 1, #Config.AtmModels do - local atm = GetClosestObjectOfType(data.coord.x, data.coord.y, data.coord.z, 0.7, Config.AtmModels[i], false, false, false) - if atm ~= 0 then - atmPoints[#atmPoints + 1] = GetEntityCoords(atm) - end - end + if (IsPedOnFoot(data.ped) and not ESX.PlayerData.dead) and not inMenu then + for i = 1, #Config.AtmModels do + local atm = GetClosestObjectOfType( + data.coord.x, + data.coord.y, + data.coord.z, + 0.7, + Config.AtmModels[i], + false, + false, + false + ) + if atm ~= 0 then + atmPoints[#atmPoints + 1] = GetEntityCoords(atm) + end + end - for i = 1, #Config.Banks do - local bankDistance = #(data.coord - Config.Banks[i].Position.xyz) - if bankDistance <= 0.7 then - bankPoints[#bankPoints + 1] = Config.Banks[i].Position.xyz - end - if Config.ShowMarker and bankDistance <= (Config.DrawMarker or 10) then - markerPoints[#markerPoints + 1] = Config.Banks[i].Position.xyz - end - end - end + for i = 1, #Config.Banks do + local bankDistance = #(data.coord - Config.Banks[i].Position.xyz) + if bankDistance <= 0.7 then + bankPoints[#bankPoints + 1] = Config.Banks[i].Position.xyz + end + if Config.ShowMarker and bankDistance <= (Config.DrawMarker or 10) then + markerPoints[#markerPoints + 1] = Config.Banks[i].Position.xyz + end + end + end - if next(bankPoints) and not uiActive then - self:TextUi(true) - end + if next(bankPoints) and not uiActive then + self:TextUi(true) + end - if next(atmPoints) and not uiActive then - self:TextUi(true, true) - end + if next(atmPoints) and not uiActive then + self:TextUi(true, true) + end - if not next(bankPoints) and not next(atmPoints) and uiActive then - self:TextUi(false) - end + if not next(bankPoints) and not next(atmPoints) and uiActive then + self:TextUi(false) + end - Wait(1000) - end - end) + Wait(1000) + end + end) - if not Config.ShowMarker then - return - end + if not Config.ShowMarker then + return + end - CreateThread(function() - local wait = 1000 - while playerLoaded do - if next(markerPoints) then - for i = 1, #markerPoints do - 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 - end - Wait(wait) - end - end) + CreateThread(function() + local wait = 1000 + while playerLoaded do + if next(markerPoints) then + for i = 1, #markerPoints do + 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 + end + Wait(wait) + end + end) end -- Handle text ui / Keypress function BANK:TextUi(state, atm) - uiActive = state - if not state then - return ESX.HideUI() - end - ESX.TextUI(_U("press_e_banking")) - CreateThread(function() - while uiActive do - if IsControlJustReleased(0, 38) then - self:HandleUi(true, atm) - self:TextUi(false) - end - Wait(0) - end - end) + uiActive = state + if not state then + return ESX.HideUI() + end + ESX.TextUI(_U("press_e_banking")) + CreateThread(function() + while uiActive do + if IsControlJustReleased(0, 38) then + self:HandleUi(true, atm) + self:TextUi(false) + end + Wait(0) + end + end) end -- Create Blips function BANK:CreateBlips() - local tmpActiveBlips = {} - for i = 1, #Config.Banks do - if type(Config.Banks[i].Blip) == "table" and Config.Banks[i].Blip.Enabled then - local position = Config.Banks[i].Position - local bInfo = Config.Banks[i].Blip - local blip = AddBlipForCoord(position.x, position.y, position.z) - SetBlipSprite(blip, bInfo.Sprite) - SetBlipScale(blip, bInfo.Scale) - SetBlipColour(blip, bInfo.Color) - SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(bInfo.Label) - EndTextCommandSetBlipName(blip) - tmpActiveBlips[#tmpActiveBlips + 1] = blip - end - end + local tmpActiveBlips = {} + for i = 1, #Config.Banks do + if type(Config.Banks[i].Blip) == "table" and Config.Banks[i].Blip.Enabled then + local position = Config.Banks[i].Position + local bInfo = Config.Banks[i].Blip + local blip = AddBlipForCoord(position.x, position.y, position.z) + SetBlipSprite(blip, bInfo.Sprite) + SetBlipScale(blip, bInfo.Scale) + SetBlipColour(blip, bInfo.Color) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("STRING") + AddTextComponentSubstringPlayerName(bInfo.Label) + EndTextCommandSetBlipName(blip) + tmpActiveBlips[#tmpActiveBlips + 1] = blip + end + end - activeBlips = tmpActiveBlips + activeBlips = tmpActiveBlips end -- Remove blips function BANK:RemoveBlips() - for i = 1, #activeBlips do - if DoesBlipExist(activeBlips[i]) then - RemoveBlip(activeBlips[i]) - end - end - activeBlips = {} + for i = 1, #activeBlips do + if DoesBlipExist(activeBlips[i]) then + RemoveBlip(activeBlips[i]) + end + end + activeBlips = {} end -- Open / Close ui function BANK:HandleUi(state, atm) - atm = atm or false - SetNuiFocus(state, state) - inMenu = state - ClearPedTasks(PlayerPedId()) - if not state then - SendNUIMessage({ - showMenu = false, - }) - return - end - ESX.TriggerServerCallback("esx_banking:getPlayerData", function(data) - SendNUIMessage({ - showMenu = true, - openATM = atm, - datas = { - your_money_panel = { - accountsData = { { - name = "cash", - amount = data.money, - }, { - name = "bank", - amount = data.bankMoney, - } }, - }, - bankCardData = { - bankName = _U("bank_name"), - cardNumber = "2232 2222 2222 2222", - createdDate = "08/08", - name = data.playerName, - }, - transactionsData = data.transactionHistory, - }, - }) - end) + atm = atm or false + SetNuiFocus(state, state) + inMenu = state + ClearPedTasks(PlayerPedId()) + if not state then + SendNUIMessage({ + showMenu = false, + }) + return + end + ESX.TriggerServerCallback("esx_banking:getPlayerData", function(data) + SendNUIMessage({ + showMenu = true, + openATM = atm, + datas = { + your_money_panel = { + accountsData = { + { + name = "cash", + amount = data.money, + }, + { + name = "bank", + amount = data.bankMoney, + }, + }, + }, + bankCardData = { + bankName = _U("bank_name"), + cardNumber = "2232 2222 2222 2222", + createdDate = "08/08", + name = data.playerName, + }, + transactionsData = data.transactionHistory, + }, + }) + end) end function BANK:LoadNpc(index, netID) - CreateThread(function() - while not NetworkDoesEntityExistWithNetworkId(netID) do - Wait(200) - end - local npc = NetworkGetEntityFromNetworkId(netID) - TaskStartScenarioInPlace(npc, Config.Peds[index].Scenario, 0, true) - SetEntityProofs(npc, true, true, true, true, true, true, true, true) - SetBlockingOfNonTemporaryEvents(npc, true) - FreezeEntityPosition(npc, true) - SetPedCanRagdollFromPlayerImpact(npc, false) - SetPedCanRagdoll(npc, false) - SetEntityAsMissionEntity(npc, true, true) - SetEntityDynamic(npc, false) - end) + CreateThread(function() + while not NetworkDoesEntityExistWithNetworkId(netID) do + Wait(200) + end + local npc = NetworkGetEntityFromNetworkId(netID) + TaskStartScenarioInPlace(npc, Config.Peds[index].Scenario, 0, true) + SetEntityProofs(npc, true, true, true, true, true, true, true, true) + SetBlockingOfNonTemporaryEvents(npc, true) + FreezeEntityPosition(npc, true) + SetPedCanRagdollFromPlayerImpact(npc, false) + SetPedCanRagdoll(npc, false) + SetEntityAsMissionEntity(npc, true, true) + SetEntityDynamic(npc, false) + end) end -- Events RegisterNetEvent("esx_banking:closebanking", function() - BANK:HandleUi(false) + BANK:HandleUi(false) end) RegisterNetEvent("esx_banking:pedHandler", function(netIdTable) - for i = 1, #netIdTable do - BANK:LoadNpc(i, netIdTable[i]) - end + for i = 1, #netIdTable do + BANK:LoadNpc(i, netIdTable[i]) + end end) RegisterNetEvent("esx_banking:updateMoneyInUI", function(doingType, bankMoney, money) - SendNUIMessage({ - updateData = true, - data = { - type = doingType, - bankMoney = bankMoney, - money = money, - }, - }) + SendNUIMessage({ + updateData = true, + data = { + type = doingType, + bankMoney = bankMoney, + money = money, + }, + }) end) -- Handlers -- Resource starting AddEventHandler("onResourceStart", function(resource) - if resource ~= GetCurrentResourceName() then - return - end - BANK:Thread() + if resource ~= GetCurrentResourceName() then + return + end + BANK:Thread() end) -- Enable the script on player loaded RegisterNetEvent("esx:playerLoaded", function() - BANK:Thread() + BANK:Thread() end) -- Disable the script on player logout RegisterNetEvent("esx:onPlayerLogout", function() - playerLoaded = false + playerLoaded = false end) -- Resource stopping AddEventHandler("onResourceStop", function(resource) - if resource ~= GetCurrentResourceName() then - return - end - BANK:RemoveBlips() - if uiActive then - BANK:TextUi(false) - end + if resource ~= GetCurrentResourceName() then + return + end + BANK:RemoveBlips() + if uiActive then + BANK:TextUi(false) + end end) RegisterNetEvent("esx:onPlayerDeath", function() - BANK:TextUi(false) + BANK:TextUi(false) end) -- Nui Callbacks RegisterNUICallback("close", function(_, cb) - BANK:HandleUi(false) - cb("ok") + BANK:HandleUi(false) + cb("ok") end) RegisterNUICallback("clickButton", function(data, cb) - if not data or not inMenu then - return cb("ok") - end + if not data or not inMenu then + return cb("ok") + end - TriggerServerEvent("esx_banking:doingType", data) - cb("ok") + TriggerServerEvent("esx_banking:doingType", data) + cb("ok") end) RegisterNUICallback("checkPincode", function(data, cb) - if not data or not inMenu then - return cb("ok") - end + if not data or not inMenu then + return cb("ok") + end - ESX.TriggerServerCallback("esx_banking:checkPincode", function(pincode) - if pincode then - cb({ - success = true, - }) - ESX.ShowNotification(_U("pincode_found"), "success") - else - cb({ - error = true, - }) - ESX.ShowNotification(_U("pincode_not_found"), "error") - end - end, data) + ESX.TriggerServerCallback("esx_banking:checkPincode", function(pincode) + if pincode then + cb({ + success = true, + }) + ESX.ShowNotification(_U("pincode_found"), "success") + else + cb({ + error = true, + }) + ESX.ShowNotification(_U("pincode_not_found"), "error") + end + end, data) end) diff --git a/server-data/resources/[esx_addons]/esx_banking/config.lua b/server-data/resources/[esx_addons]/esx_banking/config.lua index 39fb91297..37b55518f 100644 --- a/server-data/resources/[esx_addons]/esx_banking/config.lua +++ b/server-data/resources/[esx_addons]/esx_banking/config.lua @@ -1,131 +1,131 @@ Config = { - Debug = false, - DrawMarker = 10, - Locale = "en", - EnablePeds = true, - AtmModels = { `prop_fleeca_atm`, `prop_atm_01`, `prop_atm_02`, `prop_atm_03` }, - Banks = { - { - Position = vector4(149.91, -1040.74, 29.374, 160), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(-1212.63, -330.78, 37.59, 210), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(-2962.47, 482.93, 15.5, 270), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(-113.01, 6470.24, 31.43, 315), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(314.16, -279.09, 53.97, 160), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(-350.99, -49.99, 48.84, 160), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(1175.02, 2706.87, 37.89, 0), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - { - Position = vector4(246.63, 223.62, 106.0, 160), - Blip = { - Enabled = true, - Color = 69, - Label = "Bank", - Sprite = 108, - Scale = 0.7, - }, - }, - }, - Peds = { - { - Position = vector4(149.5513, -1042.1570, 29.3680, 341.6520), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(-1211.8585, -331.9854, 37.7809, 28.5983), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(-2961.0720, 483.1107, 15.6970, 88.1986), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(-112.2223, 6471.1128, 31.6267, 132.7517), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(313.8176, -280.5338, 54.1647, 339.1609), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(-351.3247, -51.3466, 49.0365, 339.3305), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(1174.9718, 2708.2034, 38.0879, 178.2974), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - { - Position = vector4(247.0348, 225.1851, 106.2875, 158.7528), - Model = `U_M_M_BankMan`, - Scenario = "WORLD_HUMAN_CLIPBOARD", - }, - }, + Debug = false, + DrawMarker = 10, + Locale = "en", + EnablePeds = true, + AtmModels = { `prop_fleeca_atm`, `prop_atm_01`, `prop_atm_02`, `prop_atm_03` }, + Banks = { + { + Position = vector4(149.91, -1040.74, 29.374, 160), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(-1212.63, -330.78, 37.59, 210), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(-2962.47, 482.93, 15.5, 270), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(-113.01, 6470.24, 31.43, 315), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(314.16, -279.09, 53.97, 160), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(-350.99, -49.99, 48.84, 160), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(1175.02, 2706.87, 37.89, 0), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + { + Position = vector4(246.63, 223.62, 106.0, 160), + Blip = { + Enabled = true, + Color = 69, + Label = "Bank", + Sprite = 108, + Scale = 0.7, + }, + }, + }, + Peds = { + { + Position = vector4(149.5513, -1042.1570, 29.3680, 341.6520), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(-1211.8585, -331.9854, 37.7809, 28.5983), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(-2961.0720, 483.1107, 15.6970, 88.1986), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(-112.2223, 6471.1128, 31.6267, 132.7517), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(313.8176, -280.5338, 54.1647, 339.1609), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(-351.3247, -51.3466, 49.0365, 339.3305), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(1174.9718, 2708.2034, 38.0879, 178.2974), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + { + Position = vector4(247.0348, 225.1851, 106.2875, 158.7528), + Model = `U_M_M_BankMan`, + Scenario = "WORLD_HUMAN_CLIPBOARD", + }, + }, } diff --git a/server-data/resources/[esx_addons]/esx_banking/server/main.lua b/server-data/resources/[esx_addons]/esx_banking/server/main.lua index 3ece31e42..4f790e2cb 100644 --- a/server-data/resources/[esx_addons]/esx_banking/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_banking/server/main.lua @@ -2,244 +2,268 @@ local spawnedPeds, netIdTable = {}, {} -- get keys utils local function get_key(t) - local key - for k, _ in pairs(t) do - key = k - end - return key + local key + for k, _ in pairs(t) do + key = k + end + return key end -- Resource starting AddEventHandler("onResourceStart", function(resourceName) - if GetCurrentResourceName() ~= resourceName then - return - end - if Config.EnablePeds then - BANK.CreatePeds() - end - local twoMonthMs = (os.time() - 5259487) * 1000 - MySQL.Sync.fetchScalar("DELETE FROM banking WHERE time < ? ", { twoMonthMs }) + if GetCurrentResourceName() ~= resourceName then + return + end + if Config.EnablePeds then + BANK.CreatePeds() + end + local twoMonthMs = (os.time() - 5259487) * 1000 + MySQL.Sync.fetchScalar("DELETE FROM banking WHERE time < ? ", { twoMonthMs }) end) AddEventHandler("onResourceStop", function(resourceName) - if GetCurrentResourceName() ~= resourceName then - return - end - if Config.EnablePeds then - BANK.DeletePeds() - end + if GetCurrentResourceName() ~= resourceName then + return + end + if Config.EnablePeds then + BANK.DeletePeds() + end end) if Config.EnablePeds then - AddEventHandler("esx:playerLoaded", function(playerId) - TriggerClientEvent("esx_banking:pedHandler", playerId, netIdTable) - end) + AddEventHandler("esx:playerLoaded", function(playerId) + TriggerClientEvent("esx_banking:pedHandler", playerId, netIdTable) + end) end -- event RegisterServerEvent("esx_banking:doingType") AddEventHandler("esx_banking:doingType", function(typeData) - if source == nil then - return - end - if typeData == nil then - return - end - - local source = source - local xPlayer = ESX.GetPlayerFromId(source) - local identifier = xPlayer.getIdentifier() - local money = xPlayer.getAccount("money").money - local bankMoney = xPlayer.getAccount("bank").money - local amount - - local key = get_key(typeData) - if typeData.deposit then - amount = tonumber(typeData.deposit) - elseif typeData.withdraw then - amount = tonumber(typeData.withdraw) - elseif typeData.transfer and typeData.transfer.moneyAmount then - amount = tonumber(typeData.transfer.moneyAmount) - elseif typeData.pincode then - amount = tonumber(typeData.pincode) - end - - if not tonumber(amount) then - return - end - amount = ESX.Math.Round(amount) - - if amount == nil or (not typeData.pincode and amount <= 0) then - TriggerClientEvent("esx:showNotification", source, _U("invalid_amount"), "error") - else - if typeData.deposit and amount <= money then - -- deposit - BANK.Deposit(amount, xPlayer) - elseif typeData.withdraw and bankMoney ~= nil and amount <= bankMoney then - -- withdraw - BANK.Withdraw(amount, xPlayer) - elseif typeData.pincode then - -- pincode - BANK.Pincode(amount, identifier) - elseif typeData.transfer then - -- transfer - if tonumber(typeData.transfer.playerId) <= 0 then - TriggerClientEvent("esx:showNotification", source, _U("cant_do_it"), "error") - return - end - - if bankMoney < amount then - TriggerClientEvent("esx:showNotification", source, _U("not_enough_money", amount), "error") - return - end - - local xTarget = ESX.GetPlayerFromId(tonumber(typeData.transfer.playerId)) - if not BANK.Transfer(xTarget, xPlayer, amount, key) then - return - end - else - TriggerClientEvent("esx:showNotification", source, _U("not_enough_money", amount), "error") - return - end - - money = xPlayer.getAccount("money").money - bankMoney = xPlayer.getAccount("bank").money - if typeData.transfer then - TriggerClientEvent("esx:showNotification", source, _U(string.format("%s_money", key), amount, typeData.transfer.playerId), "success") - else - TriggerClientEvent("esx:showNotification", source, _U(string.format("%s_money", key), typeData.pincode and (string.format("%04d", amount)) or amount), "success") - end - if not typeData.pincode then - BANK.LogTransaction(source, string.upper(key), string.upper(key), amount, bankMoney) - end - - TriggerClientEvent("esx_banking:updateMoneyInUI", source, key, bankMoney, money) - end + if source == nil then + return + end + if typeData == nil then + return + end + + local source = source + local xPlayer = ESX.GetPlayerFromId(source) + local identifier = xPlayer.getIdentifier() + local money = xPlayer.getAccount("money").money + local bankMoney = xPlayer.getAccount("bank").money + local amount + + local key = get_key(typeData) + if typeData.deposit then + amount = tonumber(typeData.deposit) + elseif typeData.withdraw then + amount = tonumber(typeData.withdraw) + elseif typeData.transfer and typeData.transfer.moneyAmount then + amount = tonumber(typeData.transfer.moneyAmount) + elseif typeData.pincode then + amount = tonumber(typeData.pincode) + end + + if not tonumber(amount) then + return + end + amount = ESX.Math.Round(amount) + + if amount == nil or (not typeData.pincode and amount <= 0) then + TriggerClientEvent("esx:showNotification", source, _U("invalid_amount"), "error") + else + if typeData.deposit and amount <= money then + -- deposit + BANK.Deposit(amount, xPlayer) + elseif typeData.withdraw and bankMoney ~= nil and amount <= bankMoney then + -- withdraw + BANK.Withdraw(amount, xPlayer) + elseif typeData.pincode then + -- pincode + BANK.Pincode(amount, identifier) + elseif typeData.transfer then + -- transfer + if tonumber(typeData.transfer.playerId) <= 0 then + TriggerClientEvent("esx:showNotification", source, _U("cant_do_it"), "error") + return + end + + if bankMoney < amount then + TriggerClientEvent("esx:showNotification", source, _U("not_enough_money", amount), "error") + return + end + + local xTarget = ESX.GetPlayerFromId(tonumber(typeData.transfer.playerId)) + if not BANK.Transfer(xTarget, xPlayer, amount, key) then + return + end + else + TriggerClientEvent("esx:showNotification", source, _U("not_enough_money", amount), "error") + return + end + + money = xPlayer.getAccount("money").money + bankMoney = xPlayer.getAccount("bank").money + if typeData.transfer then + TriggerClientEvent( + "esx:showNotification", + source, + _U(string.format("%s_money", key), amount, typeData.transfer.playerId), + "success" + ) + else + TriggerClientEvent( + "esx:showNotification", + source, + _U(string.format("%s_money", key), typeData.pincode and (string.format("%04d", amount)) or amount), + "success" + ) + end + if not typeData.pincode then + BANK.LogTransaction(source, string.upper(key), string.upper(key), amount, bankMoney) + end + + TriggerClientEvent("esx_banking:updateMoneyInUI", source, key, bankMoney, money) + end end) -- register callbacks ESX.RegisterServerCallback("esx_banking:getPlayerData", function(source, cb) - local xPlayer = ESX.GetPlayerFromId(source) - local identifier = xPlayer.getIdentifier() - local weekAgo = (os.time() - 604800) * 1000 - local transactionHistory = MySQL.Sync.fetchAll("SELECT * FROM banking WHERE identifier = ? AND time > ? ORDER BY time DESC LIMIT 10", { identifier, weekAgo }) - local playerData = { - playerName = xPlayer.getName(), - money = xPlayer.getAccount("money").money, - bankMoney = xPlayer.getAccount("bank").money, - transactionHistory = transactionHistory, - } - - cb(playerData) + local xPlayer = ESX.GetPlayerFromId(source) + local identifier = xPlayer.getIdentifier() + local weekAgo = (os.time() - 604800) * 1000 + local transactionHistory = MySQL.Sync.fetchAll( + "SELECT * FROM banking WHERE identifier = ? AND time > ? ORDER BY time DESC LIMIT 10", + { identifier, weekAgo } + ) + local playerData = { + playerName = xPlayer.getName(), + money = xPlayer.getAccount("money").money, + bankMoney = xPlayer.getAccount("bank").money, + transactionHistory = transactionHistory, + } + + cb(playerData) end) ESX.RegisterServerCallback("esx_banking:checkPincode", function(source, cb, inputPincode) - local xPlayer = ESX.GetPlayerFromId(source) - local identifier = xPlayer.getIdentifier() - local pincode = MySQL.Sync.fetchScalar("SELECT COUNT(1) AS pincode FROM users WHERE identifier = ? AND pincode = ?", { identifier, inputPincode }) - cb(pincode > 0) + local xPlayer = ESX.GetPlayerFromId(source) + local identifier = xPlayer.getIdentifier() + local pincode = MySQL.Sync.fetchScalar( + "SELECT COUNT(1) AS pincode FROM users WHERE identifier = ? AND pincode = ?", + { identifier, inputPincode } + ) + cb(pincode > 0) end) function logTransaction(targetSource, label, key, amount) - if targetSource == nil then - print("ERROR: TargetSource nil!") - return - end - - if key == nil then - print("ERROR: Do you need use these: WITHDRAW,DEPOSIT,TRANSFER_RECEIVE") - return - end - - if type(key) ~= "string" or key == "" then - print("ERROR: Do you need use these: WITHDRAW,DEPOSIT,TRANSFER_RECEIVE and can only be string type!") - return - end - - if amount == nil then - print("ERROR: Amount value is nil! Add some numeric value to the amount!") - return - end - - if label == nil then - label = "UNKNOW LABEL" - end - - local xPlayer = ESX.GetPlayerFromId(tonumber(targetSource)) - - if xPlayer ~= nil then - local bankCurrentMoney = xPlayer.getAccount("bank").money - BANK.LogTransaction(targetSource, label, string.upper(key), amount, bankCurrentMoney) - else - print("ERROR: xPlayer is nil!") - end + if targetSource == nil then + print("ERROR: TargetSource nil!") + return + end + + if key == nil then + print("ERROR: Do you need use these: WITHDRAW,DEPOSIT,TRANSFER_RECEIVE") + return + end + + if type(key) ~= "string" or key == "" then + print("ERROR: Do you need use these: WITHDRAW,DEPOSIT,TRANSFER_RECEIVE and can only be string type!") + return + end + + if amount == nil then + print("ERROR: Amount value is nil! Add some numeric value to the amount!") + return + end + + if label == nil then + label = "UNKNOW LABEL" + end + + local xPlayer = ESX.GetPlayerFromId(tonumber(targetSource)) + + if xPlayer ~= nil then + local bankCurrentMoney = xPlayer.getAccount("bank").money + BANK.LogTransaction(targetSource, label, string.upper(key), amount, bankCurrentMoney) + else + print("ERROR: xPlayer is nil!") + end end exports("logTransaction", logTransaction) RegisterServerEvent("esx_banking:logTransaction") AddEventHandler("esx_banking:logTransaction", function(label, key, amount) - logTransaction(source, label, key, amount) + logTransaction(source, label, key, amount) end) -- bank functions BANK = { - CreatePeds = function() - for i = 1, #Config.Peds do - local model = Config.Peds[i].Model - local coords = Config.Peds[i].Position - spawnedPeds[i] = CreatePed(0, model, coords.x, coords.y, coords.z, coords.w, true, true) - netIdTable[i] = NetworkGetNetworkIdFromEntity(spawnedPeds[i]) - while not DoesEntityExist(spawnedPeds[i]) do - Wait(50) - end - end - - Wait(100) - TriggerClientEvent("esx_banking:PedHandler", -1, netIdTable) - end, - DeletePeds = function() - for i = 1, #spawnedPeds do - DeleteEntity(spawnedPeds[i]) - spawnedPeds[i] = nil - end - end, - Withdraw = function(amount, xPlayer) - xPlayer.addAccountMoney("money", amount) - xPlayer.removeAccountMoney("bank", amount) - end, - Deposit = function(amount, xPlayer) - xPlayer.removeAccountMoney("money", amount) - xPlayer.addAccountMoney("bank", amount) - end, - Transfer = function(xTarget, xPlayer, amount) - if xTarget == nil or xPlayer.source == xTarget.source then - TriggerClientEvent("esx:showNotification", source, _U("cant_do_it"), "error") - return false - end - - xPlayer.removeAccountMoney("bank", amount) - xTarget.addAccountMoney("bank", amount) - local bankMoney = xTarget.getAccount("bank").money - BANK.LogTransaction(xTarget.source, "TRANSFER_RECEIVE", amount, bankMoney) - TriggerClientEvent("esx:showNotification", xTarget.source, _U("receive_transfer", amount, xPlayer.source), "success") - - return true - end, - Pincode = function(amount, identifier) - MySQL.update("UPDATE users SET pincode = ? WHERE identifier = ? ", { amount, identifier }) - end, - LogTransaction = function(playerId, label, logType, amount, bankMoney) - if playerId == nil then - return - end - - if label == nil then - label = logType - end - - local xPlayer = ESX.GetPlayerFromId(playerId) - local identifier = xPlayer.getIdentifier() - - MySQL.insert("INSERT INTO banking (identifier, label, type, amount, time, balance) VALUES (?, ?, ?, ?, ?, ?)", { identifier, label, logType, amount, os.time() * 1000, bankMoney }) - end, + CreatePeds = function() + for i = 1, #Config.Peds do + local model = Config.Peds[i].Model + local coords = Config.Peds[i].Position + spawnedPeds[i] = CreatePed(0, model, coords.x, coords.y, coords.z, coords.w, true, true) + netIdTable[i] = NetworkGetNetworkIdFromEntity(spawnedPeds[i]) + while not DoesEntityExist(spawnedPeds[i]) do + Wait(50) + end + end + + Wait(100) + TriggerClientEvent("esx_banking:PedHandler", -1, netIdTable) + end, + DeletePeds = function() + for i = 1, #spawnedPeds do + DeleteEntity(spawnedPeds[i]) + spawnedPeds[i] = nil + end + end, + Withdraw = function(amount, xPlayer) + xPlayer.addAccountMoney("money", amount) + xPlayer.removeAccountMoney("bank", amount) + end, + Deposit = function(amount, xPlayer) + xPlayer.removeAccountMoney("money", amount) + xPlayer.addAccountMoney("bank", amount) + end, + Transfer = function(xTarget, xPlayer, amount) + if xTarget == nil or xPlayer.source == xTarget.source then + TriggerClientEvent("esx:showNotification", source, _U("cant_do_it"), "error") + return false + end + + xPlayer.removeAccountMoney("bank", amount) + xTarget.addAccountMoney("bank", amount) + local bankMoney = xTarget.getAccount("bank").money + BANK.LogTransaction(xTarget.source, "TRANSFER_RECEIVE", amount, bankMoney) + TriggerClientEvent( + "esx:showNotification", + xTarget.source, + _U("receive_transfer", amount, xPlayer.source), + "success" + ) + + return true + end, + Pincode = function(amount, identifier) + MySQL.update("UPDATE users SET pincode = ? WHERE identifier = ? ", { amount, identifier }) + end, + LogTransaction = function(playerId, label, logType, amount, bankMoney) + if playerId == nil then + return + end + + if label == nil then + label = logType + end + + local xPlayer = ESX.GetPlayerFromId(playerId) + local identifier = xPlayer.getIdentifier() + + MySQL.insert( + "INSERT INTO banking (identifier, label, type, amount, time, balance) VALUES (?, ?, ?, ?, ?, ?)", + { identifier, label, logType, amount, os.time() * 1000, bankMoney } + ) + end, }