1+ mythic_action = {
2+ name = " " , -- unique_action_name
3+ duration = 0 , -- เวลาในการทำ
4+ nameicon = " " , -- icon ข้างหน้าชื่อ https://fonts.google.com/icons?selected=Material+Symbols+Rounded:garage:FILL@1;wght@200;GRAD@200;opsz@24
5+ picURL = " " , -- รูปภาพ หากต้องการเอาไอเทมให้ใช้ nui://<inventory_resource>/html/img/<itemName>.png
6+ color = " " , -- สีหลอดโหลด rgb(0,0,0) หรือ #000000 ก็ได้
7+ label = " " , -- text บอกว่ากำลังทำอะไร
8+ useWhileDead = false ,
9+ canCancel = true ,
10+ controlDisables = {
11+ disableMovement = false ,
12+ disableCarMovement = false ,
13+ disableMouse = false ,
14+ disableCombat = false ,
15+ },
16+ animation = {
17+ animDict = nil ,
18+ anim = nil ,
19+ flags = 0 ,
20+ task = nil ,
21+ },
22+ prop = {
23+ model = nil ,
24+ bone = nil ,
25+ coords = { x = 0.0 , y = 0.0 , z = 0.0 },
26+ rotation = { x = 0.0 , y = 0.0 , z = 0.0 },
27+ },
28+ }
29+
30+ local isDoingAction = false
31+ local disableMouse = false
32+ local wasCancelled = false
33+ local isAnim = false
34+ local isProp = false
35+ local prop_net = nil
36+
37+ function Progress (action , finish )
38+ mythic_action = action
39+
40+ if not IsEntityDead (GetPlayerPed (- 1 )) or mythic_action .useWhileDead then
41+ if not isDoingAction then
42+ isDoingAction = true
43+ wasCancelled = false
44+ isAnim = false
45+ isProp = false
46+
47+ SendNUIMessage ({
48+ action = " mythic_progress" ,
49+ duration = mythic_action .duration ,
50+ color = mythic_action .color or " #d449ab" ,
51+ image = mythic_action .picURL or " https://media2.giphy.com/media/w6ECVXRl2YO3QL82j1/200w.webp" ,
52+ icon = mythic_action .nameicon or " sync_problem" ,
53+ label = mythic_action .label or " กำลังดำเนินการ..."
54+ })
55+
56+ Citizen .CreateThread (function ()
57+ while isDoingAction do
58+ Citizen .Wait (0 )
59+ if IsControlJustPressed (0 , 178 ) and mythic_action .canCancel then
60+ TriggerEvent (" mythic_progbar:client:cancel" )
61+ end
62+ end
63+ if finish ~= nil then
64+ finish (wasCancelled )
65+ end
66+ end )
67+ else
68+ print (' Action Already Performing' ) -- Replace with alert call if you want the player to see this warning on-screen
69+ end
70+ else
71+ print (' Cannot do action while dead' ) -- Replace with alert call if you want the player to see this warning on-screen
72+ end
73+ end
74+
75+ function ProgressWithStartEvent (action , start , finish )
76+ mythic_action = action
77+
78+ if not IsEntityDead (GetPlayerPed (- 1 )) or mythic_action .useWhileDead then
79+ if not isDoingAction then
80+ isDoingAction = true
81+ wasCancelled = false
82+ isAnim = false
83+ isProp = false
84+
85+ SendNUIMessage ({
86+ action = " mythic_progress" ,
87+ duration = mythic_action .duration ,
88+ color = mythic_action .color or " #d449ab" ,
89+ image = mythic_action .picURL or " https://media2.giphy.com/media/w6ECVXRl2YO3QL82j1/200w.webp" ,
90+ icon = mythic_action .nameicon or " sync_problem" ,
91+ label = mythic_action .label or " กำลังดำเนินการ..."
92+ })
93+
94+ Citizen .CreateThread (function ()
95+ if start ~= nil then
96+ start ()
97+ end
98+ while isDoingAction do
99+ Citizen .Wait (1 )
100+ if IsControlJustPressed (0 , 178 ) and mythic_action .canCancel then
101+ TriggerEvent (" mythic_progbar:client:cancel" )
102+ end
103+ end
104+ if finish ~= nil then
105+ finish (wasCancelled )
106+ end
107+ end )
108+ else
109+ TriggerEvent (" mythic_base:client:SendAlert" , { text = " Already Doing An Action" , type = " error" , layout = " topRight" , timeout = 1500 })
110+ end
111+ else
112+ TriggerEvent (" mythic_base:client:SendAlert" , { text = " Cannot Perform An Action While Dead" , type = " error" , layout = " topRight" , timeout = 1500 })
113+ end
114+ end
115+
116+ function ProgressWithTickEvent (action , tick , finish )
117+ mythic_action = action
118+
119+ if not IsEntityDead (GetPlayerPed (- 1 )) or mythic_action .useWhileDead then
120+ if not isDoingAction then
121+ isDoingAction = true
122+ wasCancelled = false
123+ isAnim = false
124+ isProp = false
125+
126+ SendNUIMessage ({
127+ action = " mythic_progress" ,
128+ duration = mythic_action .duration ,
129+ color = mythic_action .color or " #d449ab" ,
130+ image = mythic_action .picURL or " https://media2.giphy.com/media/w6ECVXRl2YO3QL82j1/200w.webp" ,
131+ icon = mythic_action .nameicon or " sync_problem" ,
132+ label = mythic_action .label or " กำลังดำเนินการ..."
133+ })
134+
135+ Citizen .CreateThread (function ()
136+ while isDoingAction do
137+ Citizen .Wait (1 )
138+ if tick ~= nil then
139+ tick ()
140+ end
141+ if IsControlJustPressed (0 , 178 ) and mythic_action .canCancel then
142+ TriggerEvent (" mythic_progbar:client:cancel" )
143+ end
144+ end
145+ if finish ~= nil then
146+ finish (wasCancelled )
147+ end
148+ end )
149+ else
150+ TriggerEvent (" mythic_base:client:SendAlert" , { text = " Already Doing An Action" , type = " error" , layout = " topRight" , timeout = 1500 })
151+ end
152+ else
153+ TriggerEvent (" mythic_base:client:SendAlert" , { text = " Cannot Perform An Action While Dead" , type = " error" , layout = " topRight" , timeout = 1500 })
154+ end
155+ end
156+
157+ function ProgressWithStartAndTick (action , start , tick , finish )
158+ mythic_action = action
159+
160+ if not IsEntityDead (GetPlayerPed (- 1 )) or mythic_action .useWhileDead then
161+ if not isDoingAction then
162+ isDoingAction = true
163+ wasCancelled = false
164+ isAnim = false
165+ isProp = false
166+
167+ SendNUIMessage ({
168+ action = " mythic_progress" ,
169+ duration = mythic_action .duration ,
170+ color = mythic_action .color or " #d449ab" ,
171+ image = mythic_action .picURL or " https://media2.giphy.com/media/w6ECVXRl2YO3QL82j1/200w.webp" ,
172+ icon = mythic_action .nameicon or " sync_problem" ,
173+ label = mythic_action .label or " กำลังดำเนินการ..."
174+ })
175+
176+ Citizen .CreateThread (function ()
177+ if start ~= nil then
178+ start ()
179+ end
180+ while isDoingAction do
181+ Citizen .Wait (1 )
182+ if tick ~= nil then
183+ tick ()
184+ end
185+ if IsControlJustPressed (0 , 178 ) and mythic_action .canCancel then
186+ TriggerEvent (" mythic_progbar:client:cancel" )
187+ end
188+ end
189+ if finish ~= nil then
190+ finish (wasCancelled )
191+ end
192+ end )
193+ else
194+ print (' Already Doing An Action' )
195+ end
196+ else
197+ print (' Cannot Perform An Action While Dead' )
198+ end
199+ end
200+
201+ RegisterNetEvent (" mythic_progbar:client:progress" )
202+ AddEventHandler (" mythic_progbar:client:progress" , function (action , finish )
203+ Progress (action , finish )
204+ end )
205+
206+ RegisterNetEvent (" mythic_progbar:client:ProgressWithStartEvent" )
207+ AddEventHandler (" mythic_progbar:client:ProgressWithStartEvent" , function (action , start , finish )
208+ ProgressWithStartEvent (action , start , finish )
209+ end )
210+
211+ RegisterNetEvent (" mythic_progbar:client:ProgressWithTickEvent" )
212+ AddEventHandler (" mythic_progbar:client:ProgressWithTickEvent" , function (action , tick , finish )
213+ ProgressWithTickEvent (action , tick , finish )
214+ end )
215+
216+ RegisterNetEvent (" mythic_progbar:client:ProgressWithStartAndTick" )
217+ AddEventHandler (" mythic_progbar:client:ProgressWithStartAndTick" , function (action , start , tick , finish )
218+ ProgressWithStartAndTick (action , start , tick , finish )
219+ end )
220+
221+ RegisterNetEvent (" mythic_progbar:client:cancel" )
222+ AddEventHandler (" mythic_progbar:client:cancel" , function ()
223+ isDoingAction = false
224+ wasCancelled = true
225+
226+ TriggerEvent (" mythic_progbar:client:actionCleanup" )
227+
228+ SendNUIMessage ({
229+ action = " mythic_progress_cancel"
230+ })
231+ end )
232+
233+ RegisterNetEvent (" mythic_progbar:client:actionCleanup" )
234+ AddEventHandler (" mythic_progbar:client:actionCleanup" , function ()
235+ local ped = PlayerPedId ()
236+ ClearPedTasks (ped )
237+ StopAnimTask (ped , mythic_action .animDict , mythic_action .anim , 1.0 )
238+ DetachEntity (NetToObj (prop_net ), 1 , 1 )
239+ DeleteEntity (NetToObj (prop_net ))
240+ prop_net = nil
241+ end )
242+
243+ -- Disable controls while GUI open
244+ Citizen .CreateThread (function ()
245+ while true do
246+ if isDoingAction then
247+ if not isAnim then
248+ if mythic_action .animation ~= nil then
249+ if mythic_action .animation .task ~= nil then
250+ TaskStartScenarioInPlace (PlayerPedId (), mythic_action .animation .task , 0 , true )
251+ elseif mythic_action .animation .animDict ~= nil and mythic_action .animation .anim ~= nil then
252+ if mythic_action .animation .flags == nil then
253+ mythic_action .animation .flags = 1
254+ end
255+
256+ local player = PlayerPedId ()
257+ if ( DoesEntityExist ( player ) and not IsEntityDead ( player )) then
258+ loadAnimDict ( mythic_action .animation .animDict )
259+ TaskPlayAnim ( player , mythic_action .animation .animDict , mythic_action .animation .anim , 3.0 , 1.0 , - 1 , mythic_action .animation .flags , 0 , 0 , 0 , 0 )
260+ end
261+ else
262+ TaskStartScenarioInPlace (PlayerPedId (), ' PROP_HUMAN_BUM_BIN' , 0 , true )
263+ end
264+ end
265+
266+ isAnim = true
267+ end
268+ if not isProp and mythic_action .prop ~= nil and mythic_action .prop .model ~= nil then
269+ RequestModel (mythic_action .prop .model )
270+
271+ while not HasModelLoaded (GetHashKey (mythic_action .prop .model )) do
272+ Citizen .Wait (0 )
273+ end
274+
275+ local pCoords = GetOffsetFromEntityInWorldCoords (GetPlayerPed (PlayerId ()), 0.0 , 0.0 , 0.0 )
276+ local modelSpawn = CreateObject (GetHashKey (mythic_action .prop .model ), pCoords .x , pCoords .y , pCoords .z , true , true , true )
277+
278+ local netid = ObjToNet (modelSpawn )
279+ SetNetworkIdExistsOnAllMachines (netid , true )
280+ NetworkSetNetworkIdDynamic (netid , true )
281+ SetNetworkIdCanMigrate (netid , false )
282+ if mythic_action .prop .bone == nil then
283+ mythic_action .prop .bone = 60309
284+ end
285+
286+ if mythic_action .prop .coords == nil then
287+ mythic_action .prop .coords = { x = 0.0 , y = 0.0 , z = 0.0 }
288+ end
289+
290+ if mythic_action .prop .rotation == nil then
291+ mythic_action .prop .rotation = { x = 0.0 , y = 0.0 , z = 0.0 }
292+ end
293+
294+ AttachEntityToEntity (modelSpawn , GetPlayerPed (PlayerId ()), GetPedBoneIndex (GetPlayerPed (PlayerId ()), mythic_action .prop .bone ), mythic_action .prop .coords .x , mythic_action .prop .coords .y , mythic_action .prop .coords .z , mythic_action .prop .rotation .x , mythic_action .prop .rotation .y , mythic_action .prop .rotation .z , 1 , 1 , 0 , 1 , 0 , 1 )
295+ prop_net = netid
296+
297+ isProp = true
298+ end
299+
300+ DisableActions (GetPlayerPed (- 1 ))
301+ end
302+ Citizen .Wait (0 )
303+ end
304+ end )
305+
306+ function loadAnimDict (dict )
307+ while (not HasAnimDictLoaded (dict )) do
308+ RequestAnimDict (dict )
309+ Citizen .Wait (5 )
310+ end
311+ end
312+
313+ function DisableActions (ped )
314+ if mythic_action .controlDisables .disableMouse then
315+ DisableControlAction (0 , 1 , true ) -- LookLeftRight
316+ DisableControlAction (0 , 2 , true ) -- LookUpDown
317+ DisableControlAction (0 , 106 , true ) -- VehicleMouseControlOverride
318+ end
319+
320+ if mythic_action .controlDisables .disableMovement then
321+ DisableControlAction (0 , 30 , true ) -- disable left/right
322+ DisableControlAction (0 , 31 , true ) -- disable forward/back
323+ DisableControlAction (0 , 36 , true ) -- INPUT_DUCK
324+ DisableControlAction (0 , 21 , true ) -- disable sprint
325+ end
326+
327+ if mythic_action .controlDisables .disableCarMovement then
328+ DisableControlAction (0 , 63 , true ) -- veh turn left
329+ DisableControlAction (0 , 64 , true ) -- veh turn right
330+ DisableControlAction (0 , 71 , true ) -- veh forward
331+ DisableControlAction (0 , 72 , true ) -- veh backwards
332+ DisableControlAction (0 , 75 , true ) -- disable exit vehicle
333+ end
334+
335+ if mythic_action .controlDisables .disableCombat then
336+ DisablePlayerFiring (ped , true ) -- Disable weapon firing
337+ DisableControlAction (0 , 24 , true ) -- disable attack
338+ DisableControlAction (0 , 25 , true ) -- disable aim
339+ DisableControlAction (1 , 37 , true ) -- disable weapon select
340+ DisableControlAction (0 , 47 , true ) -- disable weapon
341+ DisableControlAction (0 , 58 , true ) -- disable weapon
342+ DisableControlAction (0 , 140 , true ) -- disable melee
343+ DisableControlAction (0 , 141 , true ) -- disable melee
344+ DisableControlAction (0 , 142 , true ) -- disable melee
345+ DisableControlAction (0 , 143 , true ) -- disable melee
346+ DisableControlAction (0 , 263 , true ) -- disable melee
347+ DisableControlAction (0 , 264 , true ) -- disable melee
348+ DisableControlAction (0 , 257 , true ) -- disable melee
349+ end
350+ end
351+
352+ RegisterNUICallback (' actionFinish' , function (data , cb )
353+ -- Do something here
354+ isDoingAction = false
355+ TriggerEvent (" mythic_progbar:client:actionCleanup" )
356+ cb (' ok' )
357+ end )
358+
359+ RegisterNUICallback (' actionCancel' , function (data , cb )
360+ -- Do something here
361+ cb (' ok' )
362+ end )
0 commit comments