Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
275 lines (245 loc) · 8.92 KB
/
Copy pathclient.lua
File metadata and controls
275 lines (245 loc) · 8.92 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
local cam = nil
local charPed = nil
local loadScreenCheckState = false
local QBCore = exports['qb-core']:GetCoreObject({ 'Functions' })
local cached_player_skins = {}
local randommodels = { -- models possible to load when choosing empty slot
'mp_m_freemode_01',
'mp_f_freemode_01',
}
-- Main Thread
CreateThread(function()
while true do
Wait(0)
if NetworkIsSessionStarted() then
TriggerEvent('qb-multicharacter:client:chooseChar')
return
end
end
end)
-- Functions
local function loadModel(model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(0)
end
end
local function initializePedModel(model, data)
CreateThread(function()
if not model then
model = joaat(randommodels[math.random(#randommodels)])
end
loadModel(model)
charPed = CreatePed(2, model, Config.PedCoords.x, Config.PedCoords.y, Config.PedCoords.z - 0.98, Config.PedCoords.w, false, true)
SetPedComponentVariation(charPed, 0, 0, 0, 2)
FreezeEntityPosition(charPed, false)
SetEntityInvincible(charPed, true)
PlaceObjectOnGroundProperly(charPed)
SetBlockingOfNonTemporaryEvents(charPed, true)
if data then
TriggerEvent('qb-clothing:client:loadPlayerClothing', data, charPed)
end
end)
end
local function skyCam(bool)
TriggerEvent('qb-weathersync:client:DisableSync')
if bool then
DoScreenFadeIn(1000)
SetTimecycleModifier('hud_def_blur')
SetTimecycleModifierStrength(1.0)
FreezeEntityPosition(PlayerPedId(), false)
cam = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', Config.CamCoords.x, Config.CamCoords.y, Config.CamCoords.z, 0.0, 0.0, Config.CamCoords.w, 60.00, false, 0)
SetCamActive(cam, true)
RenderScriptCams(true, false, 1, true, true)
else
SetTimecycleModifier('default')
SetCamActive(cam, false)
DestroyCam(cam, true)
RenderScriptCams(false, false, 1, true, true)
FreezeEntityPosition(PlayerPedId(), false)
end
end
local function openCharMenu(bool)
QBCore.Functions.TriggerCallback('qb-multicharacter:server:GetNumberOfCharacters', function(result, countries)
local translations = {}
for k in pairs(Lang.fallback and Lang.fallback.phrases or Lang.phrases) do
if k:sub(0, ('ui.'):len()) then
translations[k:sub(('ui.'):len() + 1)] = Lang:t(k)
end
end
SetNuiFocus(bool, bool)
SendNUIMessage({
action = 'ui',
customNationality = Config.customNationality,
toggle = bool,
nChar = result,
enableDeleteButton = Config.EnableDeleteButton,
translations = translations,
countries = countries,
})
skyCam(bool)
if not loadScreenCheckState then
ShutdownLoadingScreenNui()
loadScreenCheckState = true
end
end)
end
-- Events
RegisterNetEvent('qb-multicharacter:client:closeNUIdefault', function() -- This event is only for no starting apartments
DeleteEntity(charPed)
SetNuiFocus(false, false)
DoScreenFadeOut(500)
Wait(2000)
SetEntityCoords(PlayerPedId(), Config.DefaultSpawn.x, Config.DefaultSpawn.y, Config.DefaultSpawn.z)
TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)
Wait(500)
openCharMenu()
SetEntityVisible(PlayerPedId(), true)
Wait(500)
DoScreenFadeIn(250)
TriggerEvent('qb-weathersync:client:EnableSync')
TriggerEvent('qb-clothes:client:CreateFirstCharacter')
end)
RegisterNetEvent('qb-multicharacter:client:closeNUI', function()
DeleteEntity(charPed)
SetNuiFocus(false, false)
end)
RegisterNetEvent('qb-multicharacter:client:chooseChar', function()
SetNuiFocus(false, false)
DoScreenFadeOut(10)
Wait(1000)
local interior = GetInteriorAtCoords(Config.Interior.x, Config.Interior.y, Config.Interior.z - 18.9)
LoadInterior(interior)
while not IsInteriorReady(interior) do
Wait(1000)
end
FreezeEntityPosition(PlayerPedId(), true)
SetEntityCoords(PlayerPedId(), Config.HiddenCoords.x, Config.HiddenCoords.y, Config.HiddenCoords.z)
Wait(1500)
ShutdownLoadingScreen()
ShutdownLoadingScreenNui()
openCharMenu(true)
end)
RegisterNetEvent('qb-multicharacter:client:spawnLastLocation', function(coords, cData)
QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result)
if result then
TriggerEvent('apartments:client:SetHomeBlip', result.type)
local ped = PlayerPedId()
SetEntityCoords(ped, coords.x, coords.y, coords.z)
SetEntityHeading(ped, coords.w)
FreezeEntityPosition(ped, false)
SetEntityVisible(ped, true)
local PlayerData = QBCore.Functions.GetPlayerData()
local insideMeta = PlayerData.metadata['inside']
DoScreenFadeOut(500)
if insideMeta.house then
TriggerEvent('qb-houses:client:LastLocationHouse', insideMeta.house)
elseif insideMeta.apartment.apartmentType and insideMeta.apartment.apartmentId then
TriggerEvent('qb-apartments:client:LastLocationHouse', insideMeta.apartment.apartmentType, insideMeta.apartment.apartmentId)
else
SetEntityCoords(ped, coords.x, coords.y, coords.z)
SetEntityHeading(ped, coords.w)
FreezeEntityPosition(ped, false)
SetEntityVisible(ped, true)
end
TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
Wait(2000)
DoScreenFadeIn(250)
end
end, cData.citizenid)
end)
-- NUI Callbacks
RegisterNUICallback('closeUI', function(_, cb)
local cData = data.cData
DoScreenFadeOut(10)
TriggerServerEvent('qb-multicharacter:server:loadUserData', cData)
openCharMenu(false)
SetEntityAsMissionEntity(charPed, true, true)
DeleteEntity(charPed)
if Config.SkipSelection then
SetNuiFocus(false, false)
skyCam(false)
else
openCharMenu(false)
end
cb('ok')
end)
RegisterNUICallback('disconnectButton', function(_, cb)
SetEntityAsMissionEntity(charPed, true, true)
DeleteEntity(charPed)
TriggerServerEvent('qb-multicharacter:server:disconnect')
cb('ok')
end)
RegisterNUICallback('selectCharacter', function(data, cb)
local cData = data.cData
DoScreenFadeOut(10)
TriggerServerEvent('qb-multicharacter:server:loadUserData', cData)
openCharMenu(false)
SetEntityAsMissionEntity(charPed, true, true)
DeleteEntity(charPed)
cb('ok')
end)
RegisterNUICallback('cDataPed', function(nData, cb)
local cData = nData.cData
SetEntityAsMissionEntity(charPed, true, true)
DeleteEntity(charPed)
if cData ~= nil then
if not cached_player_skins[cData.citizenid] then
local temp_model = promise.new()
local temp_data = promise.new()
QBCore.Functions.TriggerCallback('qb-multicharacter:server:getSkin', function(model, data)
temp_model:resolve(model)
temp_data:resolve(data)
end, cData.citizenid)
local resolved_model = Citizen.Await(temp_model)
local resolved_data = Citizen.Await(temp_data)
cached_player_skins[cData.citizenid] = { model = resolved_model, data = resolved_data }
end
local model = cached_player_skins[cData.citizenid].model
local data = cached_player_skins[cData.citizenid].data
model = model ~= nil and tonumber(model) or false
if model ~= nil then
initializePedModel(model, json.decode(data))
else
initializePedModel()
end
cb('ok')
else
initializePedModel()
cb('ok')
end
end)
RegisterNUICallback('setupCharacters', function(_, cb)
QBCore.Functions.TriggerCallback('qb-multicharacter:server:setupCharacters', function(result)
cached_player_skins = {}
SendNUIMessage({
action = 'setupCharacters',
characters = result
})
cb('ok')
end)
end)
RegisterNUICallback('removeBlur', function(_, cb)
SetTimecycleModifier('default')
cb('ok')
end)
RegisterNUICallback('createNewCharacter', function(data, cb)
local cData = data
DoScreenFadeOut(150)
if cData.gender == Lang:t('ui.male') then
cData.gender = 0
elseif cData.gender == Lang:t('ui.female') then
cData.gender = 1
end
TriggerServerEvent('qb-multicharacter:server:createCharacter', cData)
Wait(500)
cb('ok')
end)
RegisterNUICallback('removeCharacter', function(data, cb)
TriggerServerEvent('qb-multicharacter:server:deleteCharacter', data.citizenid)
DeletePed(charPed)
TriggerEvent('qb-multicharacter:client:chooseChar')
cb('ok')
end)