feat(client/progress): add interrupt options (#70)

Add the ability to specify if an action can be interrupted. Options that I've thought of off the bat are ped going ragdoll or ped being handcuffed.

Co-authored-by: Linden <65407488+thelindat@users.noreply.github.com>
This commit is contained in:
Jag
2022-08-16 00:22:05 -07:00
committed by GitHub
parent 953673690c
commit c6250b6d5a

View File

@@ -11,6 +11,13 @@ local function createProp(prop)
return object return object
end end
local function interruptProgress(data)
if not data.useWhileDead and IsEntityDead(cache.ped) then return true end
if not data.allowRagdoll and IsPedRagdoll(cache.ped) then return true end
if not data.allowCuffed and IsPedCuffed(cache.ped) then return true end
if not data.allowFalling and IsPedFalling(cache.ped) then return true end
end
local function startProgress(data) local function startProgress(data)
playerState.invBusy = true playerState.invBusy = true
progress = data progress = data
@@ -40,22 +47,24 @@ local function startProgress(data)
end end
end end
if data.disable then local disable = data.disable
while progress do while progress do
if data.disable.mouse then if disable then
if disable.mouse then
DisableControlAction(0, 1, true) DisableControlAction(0, 1, true)
DisableControlAction(0, 2, true) DisableControlAction(0, 2, true)
DisableControlAction(0, 106, true) DisableControlAction(0, 106, true)
end end
if data.disable.move then if disable.move then
DisableControlAction(0, 21, true) DisableControlAction(0, 21, true)
DisableControlAction(0, 30, true) DisableControlAction(0, 30, true)
DisableControlAction(0, 31, true) DisableControlAction(0, 31, true)
DisableControlAction(0, 36, true) DisableControlAction(0, 36, true)
end end
if data.disable.car then if disable.car then
DisableControlAction(0, 63, true) DisableControlAction(0, 63, true)
DisableControlAction(0, 64, true) DisableControlAction(0, 64, true)
DisableControlAction(0, 71, true) DisableControlAction(0, 71, true)
@@ -63,18 +72,18 @@ local function startProgress(data)
DisableControlAction(0, 75, true) DisableControlAction(0, 75, true)
end end
if data.disable.combat then if disable.combat then
DisableControlAction(0, 25, true) DisableControlAction(0, 25, true)
DisablePlayerFiring(cache.playerId, true) DisablePlayerFiring(cache.playerId, true)
end end
end
if interruptProgress(progress) then
progress = false
end
Wait(0) Wait(0)
end end
elseif data.canCancel then
while progress do Wait(0) end
else
Wait(data.duration)
end
if data.anim then if data.anim then
ClearPedTasks(cache.ped) ClearPedTasks(cache.ped)
@@ -107,7 +116,7 @@ end
function lib.progressBar(data) function lib.progressBar(data)
while progress ~= nil do Wait(100) end while progress ~= nil do Wait(100) end
if data.useWhileDead or not IsEntityDead(cache.ped) then if not interruptProgress(data) then
SendNUIMessage({ SendNUIMessage({
action = 'progress', action = 'progress',
data = { data = {
@@ -123,7 +132,7 @@ end
function lib.progressCircle(data) function lib.progressCircle(data)
while progress ~= nil do Wait(100) end while progress ~= nil do Wait(100) end
if data.useWhileDead or not IsEntityDead(cache.ped) then if not interruptProgress(data) then
SendNUIMessage({ SendNUIMessage({
action = 'circleProgress', action = 'circleProgress',
data = { data = {