mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
refactor(client/progress): sync props with statebags (#515)
Co-authored-by: Linden <65407488+thelindat@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ local progress
|
|||||||
local DisableControlAction = DisableControlAction
|
local DisableControlAction = DisableControlAction
|
||||||
local DisablePlayerFiring = DisablePlayerFiring
|
local DisablePlayerFiring = DisablePlayerFiring
|
||||||
local playerState = LocalPlayer.state
|
local playerState = LocalPlayer.state
|
||||||
|
local createdProps = {}
|
||||||
|
|
||||||
---@class ProgressPropProps
|
---@class ProgressPropProps
|
||||||
---@field model string
|
---@field model string
|
||||||
@@ -23,12 +24,12 @@ local playerState = LocalPlayer.state
|
|||||||
---@field prop? ProgressPropProps | ProgressPropProps[]
|
---@field prop? ProgressPropProps | ProgressPropProps[]
|
||||||
---@field disable? { move?: boolean, sprint?: boolean, car?: boolean, combat?: boolean, mouse?: boolean }
|
---@field disable? { move?: boolean, sprint?: boolean, car?: boolean, combat?: boolean, mouse?: boolean }
|
||||||
|
|
||||||
local function createProp(prop)
|
local function createProp(ped, prop)
|
||||||
lib.requestModel(prop.model)
|
lib.requestModel(prop.model)
|
||||||
local coords = GetEntityCoords(cache.ped)
|
local coords = GetEntityCoords(ped)
|
||||||
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, true, true, true)
|
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, false, false, false)
|
||||||
|
|
||||||
AttachEntityToEntity(object, cache.ped, GetPedBoneIndex(cache.ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 0, true)
|
AttachEntityToEntity(object, ped, GetPedBoneIndex(ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 0, true)
|
||||||
SetModelAsNoLongerNeeded(prop.model)
|
SetModelAsNoLongerNeeded(prop.model)
|
||||||
|
|
||||||
return object
|
return object
|
||||||
@@ -77,17 +78,7 @@ local function startProgress(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if data.prop then
|
if data.prop then
|
||||||
if data.prop.model then
|
playerState:set('lib:progressProps', data.prop, true)
|
||||||
data.prop1 = createProp(data.prop)
|
|
||||||
else
|
|
||||||
for i = 1, #data.prop do
|
|
||||||
local prop = data.prop[i]
|
|
||||||
|
|
||||||
if prop then
|
|
||||||
data['prop'..i] = createProp(prop)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local disable = data.disable
|
local disable = data.disable
|
||||||
@@ -133,14 +124,7 @@ local function startProgress(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if data.prop then
|
if data.prop then
|
||||||
local n = #data.prop
|
playerState:set('lib:progressProps', nil, true)
|
||||||
for i = 1, n > 0 and n or 1 do
|
|
||||||
local prop = data['prop'..i]
|
|
||||||
|
|
||||||
if prop then
|
|
||||||
DeleteEntity(prop)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if anim then
|
if anim then
|
||||||
@@ -222,3 +206,48 @@ RegisterCommand('cancelprogress', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterKeyMapping('cancelprogress', locale('cancel_progress'), 'keyboard', 'x')
|
RegisterKeyMapping('cancelprogress', locale('cancel_progress'), 'keyboard', 'x')
|
||||||
|
|
||||||
|
local function deleteProgressProps(serverId)
|
||||||
|
local playerProps = createdProps[serverId]
|
||||||
|
if not playerProps then return end
|
||||||
|
for i = 1, #playerProps do
|
||||||
|
local prop = playerProps[i]
|
||||||
|
if DoesEntityExist(prop) then
|
||||||
|
DeleteEntity(prop)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
createdProps[serverId] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
RegisterNetEvent('onPlayerDropped', function(serverId)
|
||||||
|
deleteProgressProps(serverId)
|
||||||
|
end)
|
||||||
|
|
||||||
|
AddStateBagChangeHandler('lib:progressProps', nil, function(bagName, key, value, reserved, replicated)
|
||||||
|
if replicated then return end
|
||||||
|
|
||||||
|
local ply = GetPlayerFromStateBagName(bagName)
|
||||||
|
if ply == 0 then return end
|
||||||
|
|
||||||
|
local ped = GetPlayerPed(ply)
|
||||||
|
local serverId = GetPlayerServerId(ply)
|
||||||
|
|
||||||
|
if not value then
|
||||||
|
return deleteProgressProps(serverId)
|
||||||
|
end
|
||||||
|
|
||||||
|
createdProps[serverId] = {}
|
||||||
|
local playerProps = createdProps[serverId]
|
||||||
|
|
||||||
|
if value.model then
|
||||||
|
playerProps[#playerProps+1] = createProp(ped, value)
|
||||||
|
else
|
||||||
|
for i = 1, #value do
|
||||||
|
local prop = value[i]
|
||||||
|
|
||||||
|
if prop then
|
||||||
|
playerProps[#playerProps+1] = createProp(ped, prop)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user