mirror of
https://github.com/project-error/qb-pefcl.git
synced 2026-03-31 06:33:54 -04:00
Merge pull request #5 from RoccoMyTacco/main
feat: Default account support
This commit is contained in:
14
client.lua
14
client.lua
@@ -1,7 +1,21 @@
|
||||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
local currentJob = {}
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||
QBCore.Functions.GetPlayerData(function(PlayerData)
|
||||
currentJob = PlayerData.job
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
|
||||
TriggerServerEvent("qb-pefcl:server:UnloadPlayer")
|
||||
end)
|
||||
|
||||
RegisterNetEvent("pefcl:newDefaultAccountBalance", function(balance)
|
||||
TriggerServerEvent("qb-pefcl:server:SyncMoney")
|
||||
end)
|
||||
|
||||
RegisterNetEvent("QBCore:Client:OnJobUpdate", function(newJob)
|
||||
TriggerServerEvent("qb-pefcl:server:OnJobUpdate", currentJob)
|
||||
currentJob = newJob
|
||||
end)
|
||||
14
config.lua
Normal file
14
config.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
Config = {}
|
||||
|
||||
Config.BusinessAccounts = {
|
||||
['police'] = { -- Job Name
|
||||
AccountName = 'Los Santos Police', -- Display name for bank account
|
||||
ContributorRole = 2, -- Minimum role required to contribute to the account
|
||||
AdminRole = 3 -- Minumum role to be able to add/remove money from the account
|
||||
},
|
||||
['ambulance'] = { -- Job Name
|
||||
AccountName = 'Los Santos EMS', -- Display name for bank account
|
||||
ContributorRole = 2, -- Minimum role required to contribute to the account
|
||||
AdminRole = 3 -- Minumum role to be able to add/remove money from the account
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ description 'Bridge for QB to PEFCL'
|
||||
author "Sam Shanks"
|
||||
lua54 'yes'
|
||||
|
||||
server_script 'server.lua'
|
||||
server_scripts{
|
||||
'server.lua',
|
||||
'config.lua'
|
||||
}
|
||||
client_script 'client.lua'
|
||||
|
||||
|
||||
76
server.lua
76
server.lua
@@ -15,6 +15,51 @@ local function getCash(src)
|
||||
return Player.PlayerData.money["cash"] or 0
|
||||
end
|
||||
|
||||
local function loadPlayer(src, citizenid, name)
|
||||
exports.pefcl:loadPlayer(src, {
|
||||
source = src,
|
||||
identifier = citizenid,
|
||||
name = name
|
||||
})
|
||||
end
|
||||
|
||||
local function UniqueAccounts(player)
|
||||
local citizenid = player.PlayerData.citizenid
|
||||
local charInfo = player.PlayerData.charinfo
|
||||
local playerSrc = player.PlayerData.source
|
||||
local PlayerJob = player.PlayerData.job
|
||||
if Config.BusinessAccounts[PlayerJob.name] then
|
||||
local data = {
|
||||
PlayerJob.name
|
||||
}
|
||||
if not exports.pefcl:getUniqueAccount(playerSrc, PlayerJob.name).data then
|
||||
local data = {
|
||||
name = tostring(Config.BusinessAccounts[PlayerJob.name].AccountName),
|
||||
type = 'shared',
|
||||
identifier = PlayerJob.name
|
||||
}
|
||||
exports.pefcl:createUniqueAccount(playerSrc, data)
|
||||
end
|
||||
|
||||
local role = false
|
||||
if PlayerJob.grade.level >= Config.BusinessAccounts[PlayerJob.name].AdminRole then
|
||||
role = 'admin'
|
||||
elseif PlayerJob.grade.level >= Config.BusinessAccounts[PlayerJob.name].ContributorRole then
|
||||
role = 'contributor'
|
||||
end
|
||||
|
||||
if role then
|
||||
local data = {
|
||||
role = role,
|
||||
accountIdentifier = PlayerJob.name,
|
||||
userIdentifier = citizenid,
|
||||
source = playerSrc
|
||||
}
|
||||
exports.pefcl:addUserToUniqueAccount(playerSrc, data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
exports("addCash", addCash)
|
||||
exports("removeCash", removeCash)
|
||||
exports("getCash", getCash)
|
||||
@@ -26,11 +71,9 @@ AddEventHandler("QBCore:Server:PlayerLoaded", function(player)
|
||||
local citizenid = player.PlayerData.citizenid
|
||||
local charInfo = player.PlayerData.charinfo
|
||||
local playerSrc = player.PlayerData.source
|
||||
exports.pefcl:loadPlayer(playerSrc, {
|
||||
source = playerSrc,
|
||||
identifier = citizenid,
|
||||
name = charInfo.firstname .. " " .. charInfo.lastname,
|
||||
})
|
||||
local PlayerJob = player.PlayerData.job
|
||||
loadPlayer(playerSrc, citizenid, charInfo.firstname .. " " .. charInfo.lastname)
|
||||
UniqueAccounts(player)
|
||||
player.Functions.SyncMoney()
|
||||
end)
|
||||
|
||||
@@ -43,19 +86,20 @@ RegisterNetEvent("qb-pefcl:server:SyncMoney", function()
|
||||
player.Functions.SyncMoney()
|
||||
end)
|
||||
|
||||
RegisterNetEvent("qb-pefcl:server:OnJobUpdate", function(oldJob)
|
||||
local player = QBCore.Functions.GetPlayer(source)
|
||||
local data = {
|
||||
accountIdentifier = oldJob.name,
|
||||
userIdentifier = player.PlayerData.citizenid,
|
||||
}
|
||||
UniqueAccounts(player)
|
||||
end)
|
||||
|
||||
AddEventHandler("onServerResourceStart", function(resName)
|
||||
if resName ~= GetCurrentResourceName() then
|
||||
return
|
||||
end
|
||||
|
||||
local players = QBCore.Functions.GetQBPlayers()
|
||||
|
||||
for _, v in pairs(players) do
|
||||
exports.pefcl:loadPlayer(v.PlayerData.source, {
|
||||
source = v.PlayerData.source,
|
||||
identifier = v.PlayerData.citizenid,
|
||||
name = v.PlayerData.charinfo.firstname .. " " .. v.PlayerData.charinfo.lastname,
|
||||
})
|
||||
loadPlayer(v.PlayerData.source, v.PlayerData.citizenid, v.PlayerData.charinfo.firstname .. " " .. v.PlayerData.charinfo.lastname)
|
||||
UniqueAccounts(v)
|
||||
v.Functions.SyncMoney()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user