-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.lua
152 lines (132 loc) · 4.16 KB
/
server.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
local QBCore = exports["qb-core"]:GetCoreObject()
local function addCash(src, amount)
local Player = QBCore.Functions.GetPlayer(src)
Player.Functions.AddMoney("cash", amount)
end
local function removeCash(src, amount)
local Player = QBCore.Functions.GetPlayer(src)
Player.Functions.RemoveMoney("cash", amount)
end
local function getCash(src)
local Player = QBCore.Functions.GetPlayer(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 playerSrc = player.PlayerData.source
local PlayerJob = player.PlayerData.job
if Config.BusinessAccounts[PlayerJob.name] then
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
local function getCards(source)
local Player = QBCore.Functions.GetPlayer(source)
local cards = Player.Functions.GetItemsByName('visa')
local retval = {}
if cards then
for k, v in pairs(cards) do
retval[#retval+1] = {
id = v.info.id,
holder = v.info.holder,
number = v.info.number
}
end
end
return retval
end
local function giveCard(source, card)
local Player = QBCore.Functions.GetPlayer(source)
local info = {
id = card.id,
holder = card.holder,
number = card.number
}
Player.Functions.AddItem('visa', 1, nil, info)
end
local function getBank(source)
local Player = QBCore.Functions.GetPlayer(source)
return Player.PlayerData.money["bank"] or 0
end
exports("getBank", getBank)
exports("addCash", addCash)
exports("removeCash", removeCash)
exports("getCash", getCash)
exports("giveCard", giveCard)
exports("getCards", getCards)
AddEventHandler("QBCore:Server:OnMoneyChange", function(playerSrc, moneyType, amount, action, reason)
if moneyType ~= "bank" then return end
if action == "add" then
exports.pefcl:addBankBalance(playerSrc, { amount = amount, message = reason })
end
if action == "remove" then
exports.pefcl:removeBankBalance(playerSrc, { amount = amount, message = reason })
end
if action == "set" then
exports.pefcl:setBankBalance(playerSrc, { amount = amount, message = reason })
end
end)
AddEventHandler("QBCore:Server:PlayerLoaded", function(player)
if not player then
return
end
local citizenid = player.PlayerData.citizenid
local charInfo = player.PlayerData.charinfo
local playerSrc = player.PlayerData.source
loadPlayer(playerSrc, citizenid, charInfo.firstname .. " " .. charInfo.lastname)
UniqueAccounts(player)
player.Functions.SyncMoney()
end)
RegisterNetEvent("qb-pefcl:server:UnloadPlayer", function()
exports.pefcl:unloadPlayer(source)
end)
RegisterNetEvent("qb-pefcl:server:SyncMoney", function()
local player = QBCore.Functions.GetPlayer(source)
player.Functions.SyncMoney()
end)
RegisterNetEvent("qb-pefcl:server:OnJobUpdate", function(oldJob)
local player = QBCore.Functions.GetPlayer(source)
UniqueAccounts(player)
end)
local currentResName = GetCurrentResourceName()
AddEventHandler("onServerResourceStart", function(resName)
if resName ~= currentResName then return end
local players = QBCore.Functions.GetQBPlayers()
if not players or players == nil then
print("Error loading players, if no players on the server ignore this")
return
end
for _, v in pairs(players) do
loadPlayer(v.PlayerData.source, v.PlayerData.citizenid, v.PlayerData.charinfo.firstname .. " " .. v.PlayerData.charinfo.lastname)
UniqueAccounts(v)
v.Functions.SyncMoney()
end
end)