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

Changed code #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
129 changes: 79 additions & 50 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end)
-- Banks
RegisterNetEvent('ps-banking:client:open:bank')
AddEventHandler('ps-banking:client:open:bank', function()
Citizen.Wait(100)
Citizen.Wait(100)
SendNUIMessage({
action = "openBank",
})
Expand All @@ -32,10 +32,10 @@ Citizen.CreateThread(function()
coords = vec3(location.x, location.y, location.z),
distance = 2.5,
interactDst = 2.5,
id = locale("openBank").."interact",
name = locale("openBank").."interact:name",
id = locale("openBank") .. "interact",
name = locale("openBank") .. "interact:name",
options = {
{
{
label = 'Access Bank',
action = function()
SendNUIMessage({
Expand All @@ -60,59 +60,87 @@ Citizen.CreateThread(function()
},
})
else
exports["qb-target"]:AddBoxZone(zoneName, vector3(location.x, location.y, location.z), 1.5, 1.6, {
name = zoneName,
heading = 0.0,
debugPoly = false,
minZ = location.z - 1,
maxZ = location.z + 1,
}, {
options = {
{
icon = "fas fa-credit-card",
label = locale("openBank"),
action = function()
SendNUIMessage({
action = "openBank",
})
SetNuiFocus(true, true)
end,
exports["qb-target"]:AddBoxZone(zoneName, vector3(location.x, location.y, location.z), 1.5, 1.6, {
name = zoneName,
heading = 0.0,
debugPoly = false,
minZ = location.z - 1,
maxZ = location.z + 1,
}, {
options = {
{
icon = "fas fa-credit-card",
label = locale("openBank"),
action = function()
SendNUIMessage({
action = "openBank",
})
SetNuiFocus(true, true)
end,
},
},
},
distance = 2.5,
})
zoneId = zoneId + 1
end
distance = 2.5,
})
zoneId = zoneId + 1
end

for i = 1, #Config.BankLocations.Coords do
local blip = AddBlipForCoord(vector3(Config.BankLocations.Coords[i].x, Config.BankLocations.Coords[i].y,
Config.BankLocations.Coords[i].z))
SetBlipSprite(blip, Config.BankLocations.Blips.sprite)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, Config.BankLocations.Blips.scale)
SetBlipColour(blip, Config.BankLocations.Blips.color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(Config.BankLocations.Blips.name)
EndTextCommandSetBlipName(blip)
for i = 1, #Config.BankLocations.Coords do
local blip = AddBlipForCoord(vector3(Config.BankLocations.Coords[i].x, Config.BankLocations.Coords[i].y,
Config.BankLocations.Coords[i].z))
SetBlipSprite(blip, Config.BankLocations.Blips.sprite)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, Config.BankLocations.Blips.scale)
SetBlipColour(blip, Config.BankLocations.Blips.color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(Config.BankLocations.Blips.name)
EndTextCommandSetBlipName(blip)
end
end
end)

-- ATMs
RegisterNetEvent('ps-banking:client:open:atm')
AddEventHandler('ps-banking:client:open:atm', function()
Citizen.Wait(100)
---
--- Checks if the player is close to an ATM
---
--- @return boolean Returns true if the player is close to an ATM, false otherwise
local function isCloseToAnAtm()
local length = #Config.ATM_Models
local found = false
for i = 1, length do
local el = Config.ATM_Models[i]
local Atm = joaat(el)
local coords = GetEntityCoords(PlayerPedId())
local object = GetClosestObjectOfType(coords.x, coords.y, coords.z, 2.5, Atm, false, true, true)
found = object > 0 and true or false
end
return not not found
end

local function openAtm()
if IsNuiFocused() then
SetNuiFocus(false, false)
end
if not isCloseToAnAtm() then
print("No ATM found nearby for you to access")
return
end
Wait(100)
ATM_Animation()
SendNUIMessage({
action = "openATM",
})
SetNuiFocus(true, true)
end
-- ATMs
RegisterNetEvent('ps-banking:client:open:atm')
AddEventHandler('ps-banking:client:open:atm', function()
print("This event is Deprecated, use the export openAtm()")
end)

function ATM_Animation()
lib.playAnim(cache.ped, Config.ATM_Animation.dict, Config.ATM_Animation.name, 8.0, -8.0, -1, Config.ATM_Animation.flag, 0, false, 0, false)
Wait(GetAnimDuration(Config.ATM_Animation.dict,Config.ATM_Animation.name) * 1000)
lib.playAnim(cache.ped, Config.ATM_Animation.dict, Config.ATM_Animation.name, 8.0, -8.0, -1,
Config.ATM_Animation.flag, 0, false, 0, false)
Wait(GetAnimDuration(Config.ATM_Animation.dict, Config.ATM_Animation.name) * 1000)
ClearPedTasks(cache.ped)
end

Expand All @@ -129,7 +157,9 @@ Citizen.CreateThread(function()
options = {
{
label = locale("openATM"),
event = "ps-banking:client:open:atm",
action = function(entity, coords, args)
openAtm()
end
},
}
})
Expand All @@ -139,7 +169,9 @@ Citizen.CreateThread(function()
exports.ox_target:addModel(ATM_Models, {
icon = "fas fa-solid fa-money-bills",
label = locale("openATM"),
event = "ps-banking:client:open:atm",
onSelect = function(data)
openAtm()
end,
canInteract = function(_, distance)
return distance < 2.5
end,
Expand All @@ -152,11 +184,7 @@ Citizen.CreateThread(function()
icon = "fas fa-solid fa-money-bills",
label = locale("openATM"),
action = function()
ATM_Animation()
SendNUIMessage({
action = "openATM",
})
SetNuiFocus(true, true)
openAtm()
end,
},
},
Expand Down Expand Up @@ -361,3 +389,4 @@ RegisterNUICallback("ps-banking:client:getAmountPresets", function(_, cb)
grid = Config.PresetATM_Amounts.Grid,
}))
end)
exports("openAtm", openAtm)
84 changes: 84 additions & 0 deletions server/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- CreateSQLTable
-- @param tableName The name of the table to create.
-- @param colums A table containing the columns to create in the table.
-- The table should have the following structure:
-- @code
-- {
-- {
-- name = "column1",
-- type = "INT",
-- long = 11,
-- attribs = "NOT NULL",
-- default = 0
-- },
-- {
-- name = "column2",
-- type = "VARCHAR",
-- long = 255,
-- attribs = "NOT NULL",
-- default = "default_value"
-- },
-- }
-- @endcode
-- function CreateSQLTable(tableName, columns)
-- CreateThreadNow(function()
-- local consulta = "CREATE TABLE IF NOT EXISTS `" .. tableName .. "` ("
-- for i, columna in ipairs(columns) do
-- consulta = consulta .. "`" .. columna.name .. "` " .. columna.type
-- if columna.long then
-- consulta = consulta .. "(" .. columna.long .. ")"
-- end
-- if columna.attribs then
-- consulta = consulta .. " " .. columna.attribs
-- end
-- if columna.default then
-- if type(columna.default) == "string" then
-- consulta = consulta .. " DEFAULT('" .. columna.default .. "')"
-- else
-- consulta = consulta .. " DEFAULT(" .. columna.default .. ")"
-- end
-- end
-- if i < #columns then
-- consulta = consulta .. ", "
-- end
-- end
-- consulta = consulta .. ");"
-- local resultado = MySQL.rawExecute.await(consulta)
-- if resultado.warningStatus == 1 then
-- print("Table already Created: " .. tableName)
-- else
-- print("Table created: " .. tableName)
-- end
-- end)
-- end

-- local ps_banking_transactions = {
-- { name = "id", type = "INT", long = 0, attribs = "PRIMARY KEY AUTO_INCREMENT" },
-- { name = "identifier", type = "VARCHAR", long = 50, attribs = "NOT NULL" },
-- { name = "description", type = "VARCHAR", long = 255, attribs = "NOT NULL" },
-- { name = "type", type = "VARCHAR", long = 50, attribs = "NOT NULL" },
-- { name = "amount", type = "DECIMAL", long = "10,2", attribs = "NOT NULL" },
-- { name = "date", type = "DATE", attribs = "NOT NULL" },
-- { name = "isIncome", type = "BOOLEAN", attribs = "NOT NULL" },
-- }
-- local ps_banking_bills = {
-- { name = "id", type = "INT", long = 0, attribs = "PRIMARY KEY AUTO_INCREMENT" },
-- { name = "identifier", type = "VARCHAR", long = 50, attribs = "NOT NULL" },
-- { name = "description", type = "VARCHAR", long = 255, attribs = "NOT NULL" },
-- { name = "type", type = "VARCHAR", long = 50, attribs = "NOT NULL" },
-- { name = "amount", type = "DECIMAL", long = "10,2", attribs = "NOT NULL" },
-- { name = "date", type = "DATE", attribs = "NOT NULL" },
-- { name = "isPaid", type = "BOOLEAN", attribs = "NOT NULL" },
-- }
-- local ps_banking_accounts = {
-- { name = "id", type = "INT", long = 0, attribs = "PRIMARY KEY AUTO_INCREMENT" },
-- { name = "balance", type = "BIGINT", attribs = "NOT NULL" },
-- { name = "holder", type = "VARCHAR", long = 255, attribs = "NOT NULL" },
-- { name = "cardNumber", type = "VARCHAR", long = 255, attribs = "NOT NULL" },
-- { name = "users", type = "JSON", attribs = "NOT NULL" },
-- { name = "owner", type = "JSON", attribs = "NOT NULL" },
-- }

-- CreateSQLTable("ps_banking_transactions", ps_banking_transactions)
-- CreateSQLTable("ps_banking_bills", ps_banking_bills)
-- CreateSQLTable("ps_banking_accounts", ps_banking_accounts)