1
1
MSK .Progress = {}
2
2
3
- local isProgressOpen = false
3
+ local isProgressActive , progressData = false , nil
4
4
5
- MSK .Progress .Start = function (time , text , color )
6
- if isProgressOpen then
7
- MSK .Progress .Stop ()
5
+ local Controls = {
6
+ INPUT_LOOK_LR = 1 ,
7
+ INPUT_LOOK_UD = 2 ,
8
+ INPUT_SPRINT = 21 ,
9
+ INPUT_AIM = 25 ,
10
+ INPUT_MOVE_LR = 30 ,
11
+ INPUT_MOVE_UD = 31 ,
12
+ INPUT_DUCK = 36 ,
13
+ INPUT_VEH_MOVE_LEFT_ONLY = 63 ,
14
+ INPUT_VEH_MOVE_RIGHT_ONLY = 64 ,
15
+ INPUT_VEH_ACCELERATE = 71 ,
16
+ INPUT_VEH_BRAKE = 72 ,
17
+ INPUT_VEH_EXIT = 75 ,
18
+ INPUT_VEH_MOUSE_CONTROL_OVERRIDE = 106
19
+ }
20
+
21
+ local interrupted = function (data )
22
+ if not data .useWhileDead and IsEntityDead (MSK .Player .playerPed ) then return true end
23
+ if not data .allowRagdoll and IsPedRagdoll (MSK .Player .playerPed ) then return true end
24
+ if not data .allowCuffed and IsPedCuffed (MSK .Player .playerPed ) then return true end
25
+ if not data .allowFalling and IsPedFalling (MSK .Player .playerPed ) then return true end
26
+ if not data .allowSwimming and IsPedSwimming (MSK .Player .playerPed ) then return true end
27
+ end
28
+
29
+ local setProgressData = function (data )
30
+ progressData = data
31
+ local anim = data .animation
32
+
33
+ if anim then
34
+ if anim .dict then
35
+ MSK .Request .AnimDict (anim .dict )
36
+ TaskPlayAnim (MSK .Player .playerPed , anim .dict , anim .anim , anim .blendIn or 3.0 , anim .blendOut or 1.0 , anim .duration or - 1 , anim .flag or 49 , anim .playbackRate or 0 , anim .lockX , anim .lockY , anim .lockZ )
37
+ RemoveAnimDict (anim .dict )
38
+ elseif anim .scenario then
39
+ TaskStartScenarioInPlace (MSK .Player .playerPed , anim .scenario , 0 , anim .playEnter ~= nil and anim .playEnter or true )
40
+ end
41
+ end
42
+
43
+ local disable = data .disable
44
+
45
+ while isProgressActive do
46
+ if disable then
47
+ if disable .mouse then
48
+ DisableControlAction (0 , Controls .INPUT_LOOK_LR , true )
49
+ DisableControlAction (0 , Controls .INPUT_LOOK_UD , true )
50
+ DisableControlAction (0 , Controls .INPUT_VEH_MOUSE_CONTROL_OVERRIDE , true )
51
+ end
52
+
53
+ if disable .move then
54
+ DisableControlAction (0 , Controls .INPUT_SPRINT , true )
55
+ DisableControlAction (0 , Controls .INPUT_MOVE_LR , true )
56
+ DisableControlAction (0 , Controls .INPUT_MOVE_UD , true )
57
+ DisableControlAction (0 , Controls .INPUT_DUCK , true )
58
+ end
59
+
60
+ if disable .sprint and not disable .move then
61
+ DisableControlAction (0 , Controls .INPUT_SPRINT , true )
62
+ end
63
+
64
+ if disable .vehicle then
65
+ DisableControlAction (0 , Controls .INPUT_VEH_MOVE_LEFT_ONLY , true )
66
+ DisableControlAction (0 , Controls .INPUT_VEH_MOVE_RIGHT_ONLY , true )
67
+ DisableControlAction (0 , Controls .INPUT_VEH_ACCELERATE , true )
68
+ DisableControlAction (0 , Controls .INPUT_VEH_BRAKE , true )
69
+ DisableControlAction (0 , Controls .INPUT_VEH_EXIT , true )
70
+ end
71
+
72
+ if disable .combat then
73
+ DisableControlAction (0 , Controls .INPUT_AIM , true )
74
+ DisablePlayerFiring (MSK .Player .clientId , true )
75
+ end
76
+ end
77
+
78
+ if interrupted (data ) then
79
+ MSK .Progress .Stop ()
80
+ end
81
+
82
+ Wait (0 )
8
83
end
9
- isProgressOpen = true
84
+
85
+ if anim then
86
+ if anim .dict then
87
+ StopAnimTask (MSK .Player .playerPed , anim .dict , anim .clip , 1.0 )
88
+ ClearPedTasks (MSK .Player .playerPed )
89
+ else
90
+ ClearPedTasks (MSK .Player .playerPed )
91
+ end
92
+ end
93
+ end
94
+
95
+ MSK .Progress .Start = function (data , text , color )
96
+ local duration , text , color = data , text , color
97
+ local forceOverride = false
98
+
99
+ if type (data ) == ' table' then
100
+ duration = data .duration
101
+ text = data .text
102
+ color = data .color or Config .progressColor
103
+ forceOverride = data .forceOverride or forceOverride
104
+ end
105
+
106
+ if isProgressActive and not forceOverride then return end
107
+ if isProgressActive then MSK .Progress .Stop () end
108
+ isProgressActive = true
10
109
11
110
SendNUIMessage ({
12
111
action = ' progressBarStart' ,
13
- time = time ,
112
+ time = duration ,
14
113
text = text or ' ' ,
15
114
color = color or Config .progressColor ,
16
115
})
17
116
18
- SetTimeout ( time , function ()
19
- isProgressOpen = false
20
- end )
117
+ if type ( data ) == ' table ' then
118
+ return setProgressData ( data )
119
+ end
21
120
end
22
121
MSK .Progressbar = MSK .Progress .Start -- Support for old Scripts
23
122
exports (' Progressbar' , MSK .Progress .Start )
24
123
exports (' ProgressbarStart' , MSK .Progress .Start ) -- Support for old Scripts
25
124
RegisterNetEvent (" msk_core:progressbar" , MSK .Progress .Start )
26
125
27
126
MSK .Progress .Stop = function ()
127
+ if not isProgressActive then return end
128
+
28
129
SendNUIMessage ({
29
130
action = ' progressBarStop' ,
30
131
})
31
132
32
- isProgressOpen = false
133
+ isProgressActive = false
134
+ progressData = nil
33
135
end
34
136
MSK .ProgressStop = MSK .Progress .Stop -- Support for old Scripts
35
137
exports (' ProgressStop' , MSK .Progress .Stop ) -- Support for old Scripts
36
138
RegisterNetEvent (" msk_core:progressbarStop" , MSK .Progress .Stop )
37
139
38
140
MSK .Progress .Active = function ()
39
- return isProgressOpen
141
+ return isProgressActive , isProgressActive and progressData
40
142
end
41
- exports (' ProgressActive' , MSK .Progress .Active )
143
+ exports (' ProgressActive' , MSK .Progress .Active )
144
+
145
+ RegisterNUICallback (' progressEnd' , function ()
146
+ isProgressActive = false
147
+ progressData = nil
148
+ end )
149
+
150
+ RegisterCommand (' stopProgress' , function ()
151
+ if isProgressActive and progressData and progressData .canCancel then
152
+ MSK .Progress .Stop ()
153
+ end
154
+ end )
155
+ RegisterKeyMapping (' stopProgress' , ' Cancel Progressbar' , ' keyboard' , ' X' )
156
+ TriggerEvent (' chat:removeSuggestion' , ' /stopProgress' )
0 commit comments