Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions resource/interface/client/progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local DisableControlAction = DisableControlAction
local DisablePlayerFiring = DisablePlayerFiring
local playerState = LocalPlayer.state
local createdProps = {}
local maxProps = GetConvarInt('ox:progressPropLimit', 2)

---@class ProgressPropProps
---@field model string
Expand All @@ -34,13 +35,16 @@ local createdProps = {}
---@field disable? { move?: boolean, sprint?: boolean, car?: boolean, combat?: boolean, mouse?: boolean }

local function createProp(ped, prop)
lib.requestModel(prop.model)
local ok, result = pcall(lib.requestModel, prop.model)

if not ok then return lib.print.error(result) end

local coords = GetEntityCoords(ped)
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, false, false, false)
local object = CreateObject(result, coords.x, coords.y, coords.z, false, false, false)

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, prop.rotOrder or 0, true)
SetModelAsNoLongerNeeded(prop.model)
SetModelAsNoLongerNeeded(result)

return object
end
Expand Down Expand Up @@ -90,7 +94,7 @@ local function startProgress(data)
end

if data.prop then
playerState:set('lib:progressProps', data.prop, true)
TriggerServerEvent('ox_lib:progressProps', data.prop)
end

local disable = data.disable
Expand Down Expand Up @@ -137,7 +141,7 @@ local function startProgress(data)
end

if data.prop then
playerState:set('lib:progressProps', nil, true)
TriggerServerEvent('ox_lib:progressProps', nil)
end

if anim then
Expand Down Expand Up @@ -225,14 +229,18 @@ end

local function deleteProgressProps(serverId)
local playerProps = createdProps[serverId]

if not playerProps then return end

createdProps[serverId] = nil

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)
Expand All @@ -248,22 +256,29 @@ AddStateBagChangeHandler('lib:progressProps', nil, function(bagName, key, value,
local ped = GetPlayerPed(ply)
local serverId = GetPlayerServerId(ply)

if not value then
if not value or createdProps[serverId] then
return deleteProgressProps(serverId)
end

createdProps[serverId] = {}
local playerProps = createdProps[serverId]
local playerProps = {}

if value.model then
playerProps[#playerProps + 1] = createProp(ped, value)
local prop = createProp(ped, value)

if prop then
playerProps[#playerProps + 1] = createProp(ped, value)
end
else
for i = 1, #value do
local prop = value[i]
local propCount = math.min(maxProps, #value)

for i = 1, propCount do
local prop = createProp(ped, value[i])

if prop then
playerProps[#playerProps + 1] = createProp(ped, prop)
playerProps[#playerProps + 1] = prop
end
end
end
end)

createdProps[serverId] = playerProps
end)
12 changes: 12 additions & 0 deletions resource/interface/server/progress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local maxProps = GetConvarInt('ox:progressPropLimit', 2)

---@param props ProgressPropProps | ProgressPropProps[] | nil
RegisterNetEvent('ox_lib:progressProps', function(props)
if type(props) == 'table' then
props = #props > maxProps and { table.unpack(props, 1, maxProps) } or props
else
props = nil
end

Player(source).state:set('lib:progressProps', props, true)
end)