-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
219 lines (195 loc) · 8.8 KB
/
client.lua
File metadata and controls
219 lines (195 loc) · 8.8 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
local QBCore = exports['qb-core']:GetCoreObject()
local choosingSpawn = false
local Houses = {}
local cam = nil
local cam2 = nil
local camZPlus1 = 1500
local camZPlus2 = 50
local pointCamCoords = 75
local pointCamCoords2 = 0
local cam1Time = 500
local cam2Time = 1000
local PTFX_DICT = 'core'
local PTFX_ASSET = 'ent_dst_elec_fire_sp'
local PTFX_SCALE = 1.75
local PTFX_DURATION = 1500
local PTFX_AUDIONAME = 'ent_amb_elec_crackle'
local PTFX_AUDIOREF = 0
local LOOP_AMOUNT = 7
local LOOP_DELAY = 75
local lastSelectedColor = '#00A2FF'
RegisterNetEvent('ap-spawn:client:updateTheme', function(newColor)
lastSelectedColor = newColor
SendNUIMessage({ action = 'updateTheme', color = newColor })
end)
local function PlaySpawnPtfx(pedId)
CreateThread(function()
if not DoesEntityExist(pedId) then return end
RequestNamedPtfxAsset(PTFX_DICT)
while not HasNamedPtfxAssetLoaded(PTFX_DICT) do
Wait(5)
end
local particleHandles = {}
for i = 0, LOOP_AMOUNT do
UseParticleFxAsset(PTFX_DICT)
PlaySoundFromEntity(-1, PTFX_AUDIONAME, pedId, PTFX_AUDIOREF, false, 0)
local particle = StartParticleFxLoopedOnEntity(PTFX_ASSET, pedId, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, PTFX_SCALE, false, false, false)
table.insert(particleHandles, particle)
Wait(LOOP_DELAY)
end
Wait(PTFX_DURATION)
for _, particle in ipairs(particleHandles) do
if DoesParticleFxLoopedExist(particle) then
StopParticleFxLooped(particle, false)
end
end
RemoveNamedPtfxAsset(PTFX_DICT)
end)
end
local function SetDisplay(bool)
choosingSpawn = bool
SetNuiFocus(bool, bool)
SendNUIMessage({ action = 'showUi', status = bool, color = lastSelectedColor })
end
RegisterNetEvent('qb-spawn:client:openUI', function(value)
SetEntityVisible(PlayerPedId(), false)
DoScreenFadeOut(250)
Wait(1000)
DoScreenFadeIn(250)
QBCore.Functions.GetPlayerData(function(PlayerData)
cam = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', PlayerData.position.x, PlayerData.position.y, PlayerData.position.z + camZPlus1, -85.00, 0.00, 0.00, 100.00, false, 0)
SetCamActive(cam, true)
RenderScriptCams(true, false, 1, true, true)
end)
Wait(500)
SetDisplay(value)
end)
RegisterNetEvent('qb-houses:client:setHouseConfig', function(houseConfig) Houses = houseConfig end)
RegisterNetEvent('qb-spawn:client:setupSpawns', function(cData, new, apps)
if not new then
QBCore.Functions.TriggerCallback('qb-spawn:server:getOwnedHouses', function(houses)
local myHouses = {}
if houses ~= nil and #houses > 0 then
for i = 1, #houses, 1 do
myHouses[#myHouses + 1] = {house = houses[i].house, label = Houses[houses[i].house].adress}
end
end
SendNUIMessage({action = 'setupLocations', locations = QB.Spawns, houses = myHouses, isNew = new})
end, cData.citizenid)
elseif new then
SendNUIMessage({action = 'setupAppartements', locations = apps, isNew = new})
end
end)
RegisterNUICallback('exit', function(_, cb) SetDisplay(false); cb('ok') end)
local function SetCam(campos)
cam2 = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', campos.x, campos.y, campos.z + camZPlus1, 300.00, 0.00, 0.00, 110.00, false, 0)
PointCamAtCoord(cam2, campos.x, campos.y, campos.z + pointCamCoords)
SetCamActiveWithInterp(cam2, cam, cam1Time, true, true)
if DoesCamExist(cam) then DestroyCam(cam, true) end
Wait(cam1Time)
cam = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', campos.x, campos.y, campos.z + camZPlus2, 300.00, 0.00, 0.00, 110.00, false, 0)
PointCamAtCoord(cam, campos.x, campos.y, campos.z + pointCamCoords2)
SetCamActiveWithInterp(cam, cam2, cam2Time, true, true)
SetEntityCoords(PlayerPedId(), campos.x, campos.y, campos.z)
end
RegisterNUICallback('setCam', function(data, cb)
local location = tostring(data.posname); local type = tostring(data.type)
DoScreenFadeOut(200); Wait(500); DoScreenFadeIn(200)
if DoesCamExist(cam) then DestroyCam(cam, true) end
if DoesCamExist(cam2) then DestroyCam(cam2, true) end
if type == 'current' then QBCore.Functions.GetPlayerData(function(PlayerData) SetCam(PlayerData.position) end)
elseif type == 'house' then SetCam(Houses[location].coords.enter)
elseif type == 'normal' then SetCam(QB.Spawns[location].coords)
elseif type == 'appartment' then SetCam(Apartments.Locations[location].coords.enter) end
cb('ok')
end)
RegisterNUICallback('getCoords', function(data, cb)
local locationKey = tostring(data.name); local type = tostring(data.type); local dossierData = {}
if type == 'current' then
local pData = QBCore.Functions.GetPlayerData()
dossierData.coords = pData.position; dossierData.label = 'Last Location'; dossierData.district = 'UNKNOWN'; dossierData.weather = 'VARIABLE'
elseif type == 'house' then
dossierData.coords = Houses[locationKey].coords.enter; dossierData.label = Houses[locationKey].adress; dossierData.district = 'PRIVATE PROPERTY'; dossierData.weather = 'STABLE'
elseif type == 'normal' then
local spawnData = QB.Spawns[locationKey]
if spawnData then dossierData.coords = spawnData.coords; dossierData.label = spawnData.label; dossierData.district = spawnData.district or 'N/A'; dossierData.weather = spawnData.weather or 'N/A' end
elseif type == 'appartment' then
dossierData.coords = Apartments.Locations[locationKey].coords.enter; dossierData.label = Apartments.Locations[locationKey].label; dossierData.district = 'RESIDENTIAL TOWER'; dossierData.weather = 'STABLE'
end
if dossierData.coords and dossierData.label then SendNUIMessage({ action = 'updateDossierData', dossier = dossierData }) end
cb('ok')
end)
local function PreSpawnPlayer()
SetDisplay(false)
DoScreenFadeOut(500)
Wait(2000)
end
local function PostSpawnPlayer()
local ped = PlayerPedId()
FreezeEntityPosition(ped, false)
RenderScriptCams(false, true, 500, true, true)
if DoesCamExist(cam) then DestroyCam(cam, true) end
if DoesCamExist(cam2) then DestroyCam(cam2, true) end
SetEntityVisible(ped, true)
DoScreenFadeIn(1200)
PlaySpawnPtfx(ped)
Wait(PTFX_DURATION + 200)
if exports['ap_multicharacter'] then
exports['ap_multicharacter']:ToggleMulticharacterHud(true)
end
end
RegisterNUICallback('chooseAppa', function(data, cb)
local appaYeet = data.appType
SetDisplay(false)
DoScreenFadeOut(500)
Wait(5000)
TriggerServerEvent('apartments:server:CreateApartment', appaYeet, Apartments.Locations[appaYeet].label, true)
TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
TriggerEvent('QBCore:Client:OnPlayerLoaded')
PostSpawnPlayer()
cb('ok')
end)
RegisterNUICallback('spawnplayer', function(data, cb)
local location = tostring(data.spawnloc)
local type = tostring(data.typeLoc)
local ped = PlayerPedId()
if type == 'current' then
PreSpawnPlayer()
QBCore.Functions.GetPlayerData(function(pd)
SetEntityCoords(ped, pd.position.x, pd.position.y, pd.position.z)
SetEntityHeading(ped, pd.position.a)
FreezeEntityPosition(ped, false)
end)
local PlayerData = QBCore.Functions.GetPlayerData()
local insideMeta = PlayerData.metadata['inside']
if insideMeta.house ~= nil then TriggerEvent('qb-houses:client:LastLocationHouse', insideMeta.house)
elseif insideMeta.apartment.apartmentType ~= nil or insideMeta.apartment.apartmentId ~= nil then
TriggerEvent('qb-apartments:client:LastLocationHouse', insideMeta.apartment.apartmentType, insideMeta.apartment.apartmentId)
end
elseif type == 'house' then
PreSpawnPlayer()
TriggerEvent('qb-houses:client:enterOwnedHouse', location)
TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)
elseif type == 'normal' then
PreSpawnPlayer()
local pos = QB.Spawns[location].coords
SetEntityCoords(ped, pos.x, pos.y, pos.z)
Wait(500)
SetEntityCoords(ped, pos.x, pos.y, pos.z)
SetEntityHeading(ped, pos.w)
TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)
end
TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
TriggerEvent('QBCore:Client:OnPlayerLoaded')
PostSpawnPlayer()
cb('ok')
end)
CreateThread(function()
while true do
if choosingSpawn then DisableAllControlActions(0); Wait(0) else Wait(1000) end
end
end)
exports('GetHouseConfig', function() return Houses end)
exports('GetApartmentConfig', function() return Apartments end)