-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclient.lua
More file actions
177 lines (156 loc) · 4.55 KB
/
Copy pathclient.lua
File metadata and controls
177 lines (156 loc) · 4.55 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
local ParticleViewer = {}
---@type number
ParticleViewer.ParticleHandle = nil
---@type boolean
ParticleViewer.isPlaying = false
ParticleViewer.Data = {}
---@type string
ParticleViewer.Data.Dictionary = nil
---@type string
ParticleViewer.Data.Fx = nil
---@type number
ParticleViewer.Data.Scale = nil
ParticleViewer.Data.Color = nil
ParticleViewer.Data.Evolution = {};
function ParticleViewer:Stop()
if DoesParticleFxLoopedExist(self.ParticleHandle) then
RemoveParticleFx(self.ParticleHandle, false)
end
end
function ParticleViewer:Play()
if not self.isPlaying then return end
local localPlayer = PlayerPedId()
if DoesParticleFxLoopedExist(self.ParticleHandle) then
RemoveParticleFx(self.ParticleHandle, false)
end
RequestNamedPtfxAsset(self.Data.Dictionary)
while not HasNamedPtfxAssetLoaded(self.Data.Dictionary) do
Citizen.Wait(10)
end
UseParticleFxAssetNextCall(self.Data.Dictionary)
if not DoesParticleFxLoopedExist(self.ParticleHandle) then
self.ParticleHandle = StartParticleFxLoopedOnEntity(
self.Data.Fx,
localPlayer,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
tonumber(self.Data.Scale) + 0.0,
false,
false,
false,
false
)
ParticleViewer:UpdateColor();
ParticleViewer:UpdateEvolution();
end
end
---@param state boolean
function ParticleViewer:SetPlayingState(state)
self.isPlaying = state
if self.isPlaying then
self:Play()
DisableIdleCamera(true)
else
self:Stop()
DisableIdleCamera(false)
end
end
function ParticleViewer:UpdateScale()
if not self.isPlaying then return end
if DoesParticleFxLoopedExist(self.ParticleHandle) then
SetParticleFxLoopedScale(self.ParticleHandle, tonumber(self.Data.Scale) + 0.0)
end
end
function ParticleViewer:UpdateColor()
if not self.isPlaying then return end
if DoesParticleFxLoopedExist(self.ParticleHandle) then
SetParticleFxLoopedColour(self.ParticleHandle, tonumber(self.Data.Color.r) + 0.0, tonumber(self.Data.Color.g) + 0.0, tonumber(self.Data.Color.b) + 0.0, false);
SetParticleFxLoopedAlpha(self.ParticleHandle, tonumber(self.Data.Color.a) + 0.0);
end
end
function ParticleViewer:UpdateEvolution()
if not self.isPlaying then return end
if DoesParticleFxLoopedExist(self.ParticleHandle) then
for k, v in pairs(self.Data.Evolution) do
SetParticleFxLoopedEvolution(self.ParticleHandle, k, tonumber(v) + 0.0, false);
end
end
end
function ParticleViewer:Open()
SendNUIMessage({
event = "SET_OPEN_STATE",
state = true
})
end
function ParticleViewer:Close()
SendNUIMessage({
event = "SET_OPEN_STATE",
state = false
})
end
function ParticleViewer:onOpened()
InvalidateIdleCam()
InvalidateVehicleIdleCam()
SetNuiFocus(true, true)
end
function ParticleViewer:onClosed()
SetNuiFocus(false, false)
self:Stop()
end
RegisterNUICallback("SET_PLAYING_STATE", function(data, cb)
ParticleViewer:SetPlayingState(data.state)
cb({})
end)
RegisterNUICallback("SET_PARTICLE_DATA_ON_MOUNTED", function(data, cb)
ParticleViewer.Data.Dictionary = data.dictionary
ParticleViewer.Data.Fx = data.particleFx
ParticleViewer.Data.Scale = data.scale
ParticleViewer.Data.Color = { r = 1.0, g = 1.0, b = 1.0, a = 1.0 }
cb({})
end)
RegisterNUICallback("CHANGE_PARTICLE", function(data, cb)
ParticleViewer.Data.Dictionary = data.dictionary
ParticleViewer.Data.Fx = data.particleFx
ParticleViewer:Play()
cb({})
end)
RegisterNUICallback("CHANGE_PARTICLE_SCALE", function(data, cb)
ParticleViewer.Data.Scale = data.scale
ParticleViewer:UpdateScale()
cb({})
end)
RegisterNUICallback("CHANGE_PARTICLE_COLOR", function(data, cb)
ParticleViewer.Data.Color = data.color
ParticleViewer:UpdateColor()
cb({})
end)
RegisterNUICallback("CHANGE_EVOLUTION_PROPERTY", function(data, cb)
ParticleViewer.Data.Evolution[data.name] = data.value;
ParticleViewer:UpdateEvolution();
cb({})
end)
RegisterNUICallback("SET_CURSOR_STATE", function(data, cb)
local state = data.state
if state then
ParticleViewer:onOpened()
else
ParticleViewer:onClosed()
end
cb({})
end)
RegisterCommand("pv_open", function()
ParticleViewer:Open()
end)
RegisterCommand("pv_close", function()
ParticleViewer:Close()
end)
exports("Open", function()
ParticleViewer:Open()
end)
exports("Close", function()
ParticleViewer:Close()
end)