mirror of
https://github.com/project-error/qb-pefcl.git
synced 2026-04-05 09:03:58 -04:00
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()
|
RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
|
||||||
TriggerServerEvent("qb-pefcl:server:UnloadPlayer")
|
TriggerServerEvent("qb-pefcl:server:UnloadPlayer")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("pefcl:newDefaultAccountBalance", function(balance)
|
RegisterNetEvent("pefcl:newDefaultAccountBalance", function(balance)
|
||||||
TriggerServerEvent("qb-pefcl:server:SyncMoney")
|
TriggerServerEvent("qb-pefcl:server:SyncMoney")
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent("QBCore:Client:OnJobUpdate", function(newJob)
|
||||||
|
TriggerServerEvent("qb-pefcl:server:OnJobUpdate", currentJob)
|
||||||
|
currentJob = newJob
|
||||||
end)
|
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"
|
author "Sam Shanks"
|
||||||
lua54 'yes'
|
lua54 'yes'
|
||||||
|
|
||||||
server_script 'server.lua'
|
server_scripts{
|
||||||
|
'server.lua',
|
||||||
|
'config.lua'
|
||||||
|
}
|
||||||
client_script 'client.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
|
return Player.PlayerData.money["cash"] or 0
|
||||||
end
|
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("addCash", addCash)
|
||||||
exports("removeCash", removeCash)
|
exports("removeCash", removeCash)
|
||||||
exports("getCash", getCash)
|
exports("getCash", getCash)
|
||||||
@@ -26,11 +71,9 @@ AddEventHandler("QBCore:Server:PlayerLoaded", function(player)
|
|||||||
local citizenid = player.PlayerData.citizenid
|
local citizenid = player.PlayerData.citizenid
|
||||||
local charInfo = player.PlayerData.charinfo
|
local charInfo = player.PlayerData.charinfo
|
||||||
local playerSrc = player.PlayerData.source
|
local playerSrc = player.PlayerData.source
|
||||||
exports.pefcl:loadPlayer(playerSrc, {
|
local PlayerJob = player.PlayerData.job
|
||||||
source = playerSrc,
|
loadPlayer(playerSrc, citizenid, charInfo.firstname .. " " .. charInfo.lastname)
|
||||||
identifier = citizenid,
|
UniqueAccounts(player)
|
||||||
name = charInfo.firstname .. " " .. charInfo.lastname,
|
|
||||||
})
|
|
||||||
player.Functions.SyncMoney()
|
player.Functions.SyncMoney()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -43,19 +86,20 @@ RegisterNetEvent("qb-pefcl:server:SyncMoney", function()
|
|||||||
player.Functions.SyncMoney()
|
player.Functions.SyncMoney()
|
||||||
end)
|
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)
|
AddEventHandler("onServerResourceStart", function(resName)
|
||||||
if resName ~= GetCurrentResourceName() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local players = QBCore.Functions.GetQBPlayers()
|
local players = QBCore.Functions.GetQBPlayers()
|
||||||
|
|
||||||
for _, v in pairs(players) do
|
for _, v in pairs(players) do
|
||||||
exports.pefcl:loadPlayer(v.PlayerData.source, {
|
loadPlayer(v.PlayerData.source, v.PlayerData.citizenid, v.PlayerData.charinfo.firstname .. " " .. v.PlayerData.charinfo.lastname)
|
||||||
source = v.PlayerData.source,
|
UniqueAccounts(v)
|
||||||
identifier = v.PlayerData.citizenid,
|
|
||||||
name = v.PlayerData.charinfo.firstname .. " " .. v.PlayerData.charinfo.lastname,
|
|
||||||
})
|
|
||||||
v.Functions.SyncMoney()
|
v.Functions.SyncMoney()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user