120 lines
3.6 KiB
Lua
120 lines
3.6 KiB
Lua
local framework = GetResourceState('es_extended') == 'started' and 'ESX' or GetResourceState('qb-core') == 'started' and 'QBCore' or 'None'
|
|
|
|
CreateThread(function ()
|
|
if framework == 'None' then
|
|
if Config.debug then
|
|
print(('^1[Svdden Banking Error]^0 %s'):format('No framework found, please make sure you have either ESX or qb-core or qbx_core running. [Stopping Resource]'))
|
|
end
|
|
|
|
StopResource(GetCurrentResourceName())
|
|
return
|
|
end
|
|
|
|
if framework == 'ESX' then
|
|
ESX = exports['es_extended']:getSharedObject()
|
|
elseif framework == 'QBCore' then
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
end
|
|
|
|
if Config.debug then
|
|
print(('^5[Svdden Banking Debug]^0 %s'):format('Using framework: ' .. framework .. (framework == 'QBCore' and ' or qbx_core' or '') .. ' [Starting Resource]'))
|
|
end
|
|
end)
|
|
|
|
function fetchUserBySource(source)
|
|
if framework == 'ESX' then
|
|
local playerData = ESX.GetPlayerFromId(source)
|
|
return playerData
|
|
elseif framework == 'QBCore' then
|
|
local playerData = QBCore.Functions.GetPlayer(source)
|
|
return playerData
|
|
end
|
|
end
|
|
|
|
function fetchUsersUUID(source)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.identifier
|
|
elseif framework == 'QBCore' then
|
|
return playerData.PlayerData.citizenid
|
|
end
|
|
end
|
|
|
|
function fetchUserNameBySource(source)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.getName()
|
|
elseif framework == 'QBCore' then
|
|
return playerData.PlayerData.charinfo.firstname .. ' ' .. playerData.PlayerData.charinfo.lastname
|
|
end
|
|
end
|
|
|
|
function getUserPrimaryAccount(source)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.getAccount('bank').money
|
|
elseif framework == 'QBCore' then
|
|
return playerData.PlayerData.money.bank
|
|
end
|
|
end
|
|
|
|
function getUserCashAmount(source)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.getMoney()
|
|
elseif framework == 'QBCore' then
|
|
return playerData.PlayerData.money.cash
|
|
end
|
|
end
|
|
|
|
function removeAcountMoney(source, amount)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.removeAccountMoney('bank', amount)
|
|
elseif framework == 'QBCore' then
|
|
return playerData.Functions.RemoveMoney('bank', amount)
|
|
end
|
|
end
|
|
|
|
function addAccountMoney(source, amount)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.addAccountMoney('bank', amount)
|
|
elseif framework == 'QBCore' then
|
|
return playerData.Functions.AddMoney('bank', amount)
|
|
end
|
|
end
|
|
|
|
function removeCashAmount(source, amount)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.removeMoney(amount)
|
|
elseif framework == 'QBCore' then
|
|
return playerData.Functions.RemoveMoney('cash', amount)
|
|
end
|
|
end
|
|
|
|
function addCashAmount(source, amount)
|
|
local playerData = fetchUserBySource(source)
|
|
if not playerData then return end
|
|
|
|
if framework == 'ESX' then
|
|
return playerData.addMoney(amount)
|
|
elseif framework == 'QBCore' then
|
|
return playerData.Functions.AddMoney('cash', amount)
|
|
end
|
|
end |