-
Notifications
You must be signed in to change notification settings - Fork 236
/
main.lua
213 lines (191 loc) · 8.29 KB
/
main.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
local QBCore = exports['qb-core']:GetCoreObject()
local hasDonePreloading = {}
-- Functions
local function GiveStarterItems(source)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
for _, v in pairs(QBCore.Shared.StarterItems) do
local info = {}
if v.item == "id_card" then
info.citizenid = Player.PlayerData.citizenid
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.gender = Player.PlayerData.charinfo.gender
info.nationality = Player.PlayerData.charinfo.nationality
elseif v.item == "driver_license" then
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.type = "Class C Driver License"
end
exports['qb-inventory']:AddItem(src, v.item, v.amount, false, info, 'qb-multicharacter:GiveStarterItems')
end
end
local function loadHouseData(src)
local HouseGarages = {}
local Houses = {}
local result = MySQL.query.await('SELECT * FROM houselocations', {})
if result[1] ~= nil then
for _, v in pairs(result) do
local owned = false
if tonumber(v.owned) == 1 then
owned = true
end
local garage = v.garage ~= nil and json.decode(v.garage) or {}
Houses[v.name] = {
coords = json.decode(v.coords),
owned = owned,
price = v.price,
locked = true,
adress = v.label,
tier = v.tier,
garage = garage,
decorations = {},
}
HouseGarages[v.name] = {
label = v.label,
takeVehicle = garage,
}
end
end
TriggerClientEvent("qb-garages:client:houseGarageConfig", src, HouseGarages)
TriggerClientEvent("qb-houses:client:setHouseConfig", src, Houses)
end
-- Commands
QBCore.Commands.Add("logout", Lang:t("commands.logout_description"), {}, false, function(source)
local src = source
QBCore.Player.Logout(src)
TriggerClientEvent('qb-multicharacter:client:chooseChar', src)
end, "admin")
QBCore.Commands.Add("closeNUI", Lang:t("commands.closeNUI_description"), {}, false, function(source)
local src = source
TriggerClientEvent('qb-multicharacter:client:closeNUI', src)
end)
-- Events
AddEventHandler('QBCore:Server:PlayerLoaded', function(Player)
Wait(1000) -- 1 second should be enough to do the preloading in other resources
hasDonePreloading[Player.PlayerData.source] = true
end)
AddEventHandler('QBCore:Server:OnPlayerUnload', function(src)
hasDonePreloading[src] = false
end)
RegisterNetEvent('qb-multicharacter:server:disconnect', function()
local src = source
DropPlayer(src, Lang:t("commands.droppedplayer"))
end)
RegisterNetEvent('qb-multicharacter:server:loadUserData', function(cData)
local src = source
if QBCore.Player.Login(src, cData.citizenid) then
repeat
Wait(10)
until hasDonePreloading[src]
print('^2[qb-core]^7 '..GetPlayerName(src)..' (Citizen ID: '..cData.citizenid..') has successfully loaded!')
QBCore.Commands.Refresh(src)
loadHouseData(src)
if Config.SkipSelection then
local coords = json.decode(cData.position)
TriggerClientEvent('qb-multicharacter:client:spawnLastLocation', src, coords, cData)
else
if GetResourceState('qb-apartments') == 'started' then
TriggerClientEvent('apartments:client:setupSpawnUI', src, cData)
else
TriggerClientEvent('qb-spawn:client:setupSpawns', src, cData, false, nil)
TriggerClientEvent('qb-spawn:client:openUI', src, true)
end
end
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Loaded", "green", "**".. GetPlayerName(src) .. "** (<@"..(QBCore.Functions.GetIdentifier(src, 'discord'):gsub("discord:", "") or "unknown").."> | ||" ..(QBCore.Functions.GetIdentifier(src, 'ip') or 'undefined') .. "|| | " ..(QBCore.Functions.GetIdentifier(src, 'license') or 'undefined') .." | " ..cData.citizenid.." | "..src..") loaded..")
end
end)
RegisterNetEvent('qb-multicharacter:server:createCharacter', function(data)
local src = source
local newData = {}
newData.cid = data.cid
newData.charinfo = data
if QBCore.Player.Login(src, false, newData) then
repeat
Wait(10)
until hasDonePreloading[src]
if GetResourceState('qb-apartments') == 'started' and Apartments.Starting then
local randbucket = (GetPlayerPed(src) .. math.random(1,999))
SetPlayerRoutingBucket(src, randbucket)
print('^2[qb-core]^7 '..GetPlayerName(src)..' has successfully loaded!')
QBCore.Commands.Refresh(src)
loadHouseData(src)
TriggerClientEvent("qb-multicharacter:client:closeNUI", src)
TriggerClientEvent('apartments:client:setupSpawnUI', src, newData)
GiveStarterItems(src)
else
print('^2[qb-core]^7 '..GetPlayerName(src)..' has successfully loaded!')
QBCore.Commands.Refresh(src)
loadHouseData(src)
TriggerClientEvent("qb-multicharacter:client:closeNUIdefault", src)
GiveStarterItems(src)
end
end
end)
RegisterNetEvent('qb-multicharacter:server:deleteCharacter', function(citizenid)
local src = source
QBCore.Player.DeleteCharacter(src, citizenid)
TriggerClientEvent('QBCore:Notify', src, Lang:t("notifications.char_deleted") , "success")
end)
-- Callbacks
QBCore.Functions.CreateCallback("qb-multicharacter:server:GetUserCharacters", function(source, cb)
local src = source
local license = QBCore.Functions.GetIdentifier(src, 'license')
MySQL.query('SELECT * FROM players WHERE license = ?', {license}, function(result)
cb(result)
end)
end)
QBCore.Functions.CreateCallback("qb-multicharacter:server:GetServerLogs", function(_, cb)
MySQL.query('SELECT * FROM server_logs', {}, function(result)
cb(result)
end)
end)
QBCore.Functions.CreateCallback("qb-multicharacter:server:GetNumberOfCharacters", function(source, cb)
local src = source
local license = QBCore.Functions.GetIdentifier(src, 'license')
local numOfChars = 0
if next(Config.PlayersNumberOfCharacters) then
for _, v in pairs(Config.PlayersNumberOfCharacters) do
if v.license == license then
numOfChars = v.numberOfChars
break
else
numOfChars = Config.DefaultNumberOfCharacters
end
end
else
numOfChars = Config.DefaultNumberOfCharacters
end
cb(numOfChars)
end)
QBCore.Functions.CreateCallback("qb-multicharacter:server:setupCharacters", function(source, cb)
local license = QBCore.Functions.GetIdentifier(source, 'license')
local plyChars = {}
MySQL.query('SELECT * FROM players WHERE license = ?', {license}, function(result)
for i = 1, (#result), 1 do
result[i].charinfo = json.decode(result[i].charinfo)
result[i].money = json.decode(result[i].money)
result[i].job = json.decode(result[i].job)
plyChars[#plyChars+1] = result[i]
end
cb(plyChars)
end)
end)
QBCore.Functions.CreateCallback("qb-multicharacter:server:getSkin", function(_, cb, cid)
local result = MySQL.query.await('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', {cid, 1})
if result[1] ~= nil then
cb(result[1].model, result[1].skin)
else
cb(nil)
end
end)
QBCore.Commands.Add("deletechar", Lang:t("commands.deletechar_description"), {{name = Lang:t("commands.citizenid"), help = Lang:t("commands.citizenid_help")}}, false, function(source,args)
if args and args[1] then
QBCore.Player.ForceDeleteCharacter(tostring(args[1]))
TriggerClientEvent("QBCore:Notify", source, Lang:t("notifications.deleted_other_char", {citizenid = tostring(args[1])}))
else
TriggerClientEvent("QBCore:Notify", source, Lang:t("notifications.forgot_citizenid"), "error")
end
end, "god")