mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01935adf8e | ||
|
|
220c0c91ec | ||
|
|
855e1e4a36 | ||
|
|
a2f6b9a9e9 | ||
|
|
13a24baee4 | ||
|
|
df7a6b9c21 |
@@ -6,7 +6,7 @@ rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aw
|
|||||||
|
|
||||||
name 'ox_lib'
|
name 'ox_lib'
|
||||||
author 'Overextended'
|
author 'Overextended'
|
||||||
version '3.31.4'
|
version '3.32.1'
|
||||||
license 'LGPL-3.0-or-later'
|
license 'LGPL-3.0-or-later'
|
||||||
repository 'https://github.com/communityox/ox_lib'
|
repository 'https://github.com/communityox/ox_lib'
|
||||||
description 'A library of shared functions to utilise in other resources.'
|
description 'A library of shared functions to utilise in other resources.'
|
||||||
|
|||||||
@@ -47,13 +47,10 @@ end
|
|||||||
---@return boolean
|
---@return boolean
|
||||||
---Compares if two values are equal, iterating over tables and matching both keys and values.
|
---Compares if two values are equal, iterating over tables and matching both keys and values.
|
||||||
local function table_matches(t1, t2)
|
local function table_matches(t1, t2)
|
||||||
local tabletype1 = table.type(t1)
|
local type1, type2 = type(t1), type(t2)
|
||||||
|
|
||||||
if not tabletype1 then return t1 == t2 end
|
if type1 ~= type2 then return false end
|
||||||
|
if type1 ~= 'table' and type2 ~= 'table' then return t1 == t2 end
|
||||||
if tabletype1 ~= table.type(t2) or (tabletype1 == 'array' and #t1 ~= #t2) then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
for k, v1 in pairs(t1) do
|
for k, v1 in pairs(t1) do
|
||||||
local v2 = t2[k]
|
local v2 = t2[k]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@communityox/ox_lib",
|
"name": "@communityox/ox_lib",
|
||||||
"author": "Overextended",
|
"author": "Overextended",
|
||||||
"version": "3.31.4",
|
"version": "3.32.1",
|
||||||
"description": "JS/TS wrapper for ox_lib exports",
|
"description": "JS/TS wrapper for ox_lib exports",
|
||||||
"main": "./shared/index.js",
|
"main": "./shared/index.js",
|
||||||
"types": "./shared/index.d.ts",
|
"types": "./shared/index.d.ts",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ local DisableControlAction = DisableControlAction
|
|||||||
local DisablePlayerFiring = DisablePlayerFiring
|
local DisablePlayerFiring = DisablePlayerFiring
|
||||||
local playerState = LocalPlayer.state
|
local playerState = LocalPlayer.state
|
||||||
local createdProps = {}
|
local createdProps = {}
|
||||||
|
local maxProps = GetConvarInt('ox:progressPropLimit', 2)
|
||||||
|
|
||||||
---@class ProgressPropProps
|
---@class ProgressPropProps
|
||||||
---@field model string
|
---@field model string
|
||||||
@@ -34,13 +35,16 @@ local createdProps = {}
|
|||||||
---@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(ped, prop)
|
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 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,
|
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)
|
true, false, true, prop.rotOrder or 0, true)
|
||||||
SetModelAsNoLongerNeeded(prop.model)
|
SetModelAsNoLongerNeeded(result)
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
@@ -90,7 +94,7 @@ local function startProgress(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if data.prop then
|
if data.prop then
|
||||||
playerState:set('lib:progressProps', data.prop, true)
|
TriggerServerEvent('ox_lib:progressProps', data.prop)
|
||||||
end
|
end
|
||||||
|
|
||||||
local disable = data.disable
|
local disable = data.disable
|
||||||
@@ -137,7 +141,7 @@ local function startProgress(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if data.prop then
|
if data.prop then
|
||||||
playerState:set('lib:progressProps', nil, true)
|
TriggerServerEvent('ox_lib:progressProps', nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
if anim then
|
if anim then
|
||||||
@@ -225,14 +229,18 @@ end
|
|||||||
|
|
||||||
local function deleteProgressProps(serverId)
|
local function deleteProgressProps(serverId)
|
||||||
local playerProps = createdProps[serverId]
|
local playerProps = createdProps[serverId]
|
||||||
|
|
||||||
if not playerProps then return end
|
if not playerProps then return end
|
||||||
|
|
||||||
|
createdProps[serverId] = nil
|
||||||
|
|
||||||
for i = 1, #playerProps do
|
for i = 1, #playerProps do
|
||||||
local prop = playerProps[i]
|
local prop = playerProps[i]
|
||||||
|
|
||||||
if DoesEntityExist(prop) then
|
if DoesEntityExist(prop) then
|
||||||
DeleteEntity(prop)
|
DeleteEntity(prop)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
createdProps[serverId] = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent('onPlayerDropped', function(serverId)
|
RegisterNetEvent('onPlayerDropped', function(serverId)
|
||||||
@@ -248,22 +256,29 @@ AddStateBagChangeHandler('lib:progressProps', nil, function(bagName, key, value,
|
|||||||
local ped = GetPlayerPed(ply)
|
local ped = GetPlayerPed(ply)
|
||||||
local serverId = GetPlayerServerId(ply)
|
local serverId = GetPlayerServerId(ply)
|
||||||
|
|
||||||
if not value then
|
if not value or createdProps[serverId] then
|
||||||
return deleteProgressProps(serverId)
|
return deleteProgressProps(serverId)
|
||||||
end
|
end
|
||||||
|
|
||||||
createdProps[serverId] = {}
|
local playerProps = {}
|
||||||
local playerProps = createdProps[serverId]
|
|
||||||
|
|
||||||
if value.model then
|
if value.model then
|
||||||
playerProps[#playerProps + 1] = createProp(ped, value)
|
local prop = createProp(ped, value)
|
||||||
|
|
||||||
|
if prop then
|
||||||
|
playerProps[#playerProps + 1] = prop
|
||||||
|
end
|
||||||
else
|
else
|
||||||
for i = 1, #value do
|
local propCount = math.min(maxProps, #value)
|
||||||
local prop = value[i]
|
|
||||||
|
for i = 1, propCount do
|
||||||
|
local prop = createProp(ped, value[i])
|
||||||
|
|
||||||
if prop then
|
if prop then
|
||||||
playerProps[#playerProps + 1] = createProp(ped, prop)
|
playerProps[#playerProps + 1] = prop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
createdProps[serverId] = playerProps
|
||||||
end)
|
end)
|
||||||
|
|||||||
12
resource/interface/server/progress.lua
Normal file
12
resource/interface/server/progress.lua
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user