mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(vehicleProperties): add statebag handler and server setter
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
|
import type { VehicleProperties } from 'shared';
|
||||||
|
|
||||||
export * from './acl';
|
export * from './acl';
|
||||||
export * from './locale';
|
export * from './locale';
|
||||||
export * from './callback';
|
export * from './callback';
|
||||||
export * from './version';
|
export * from './version';
|
||||||
export * from './addCommand';
|
export * from './addCommand';
|
||||||
|
|
||||||
|
export function setVehicleProperties(vehicle: number, props: VehicleProperties) {
|
||||||
|
Entity(vehicle).state.set('ox_lib:setVehicleProperties', props, true)
|
||||||
|
}
|
||||||
|
|||||||
@@ -99,20 +99,26 @@ RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[ Alternative to NetEvent - disabled (at least for now?)
|
AddStateBagChangeHandler('ox_lib:setVehicleProperties', '', function(bagName, _, value)
|
||||||
AddStateBagChangeHandler('setVehicleProperties', '', function(bagName, _, value)
|
|
||||||
if not value or not GetEntityFromStateBagName then return end
|
if not value or not GetEntityFromStateBagName then return end
|
||||||
|
|
||||||
local entity = GetEntityFromStateBagName(bagName)
|
local entity = lib.waitFor(function()
|
||||||
local networked = not bagName:find('localEntity')
|
local entity = GetEntityFromStateBagName(bagName)
|
||||||
|
|
||||||
if networked and NetworkGetEntityOwner(entity) ~= cache.playerId then return end
|
if entity > 0 then return entity end
|
||||||
|
end)
|
||||||
|
|
||||||
if lib.setVehicleProperties(entity, value) then
|
|
||||||
Entity(entity).state:set('setVehicleProperties', nil, true)
|
lib.setVehicleProperties(entity, value)
|
||||||
|
Wait(200)
|
||||||
|
|
||||||
|
-- this delay and second-setting of vehicle properties hopefully counters the
|
||||||
|
-- weird sync/ownership/shitfuckery when setting props on server-side vehicles
|
||||||
|
if NetworkGetEntityOwner(entity) == cache.playerId then
|
||||||
|
lib.setVehicleProperties(entity, value)
|
||||||
|
Entity(entity).state:set('ox_lib:setVehicleProperties', nil, true)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
]]
|
|
||||||
|
|
||||||
local gameBuild = GetGameBuildNumber()
|
local gameBuild = GetGameBuildNumber()
|
||||||
|
|
||||||
|
|||||||
6
resource/vehicleProperties/server.lua
Normal file
6
resource/vehicleProperties/server.lua
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---@param vehicle number
|
||||||
|
---@param props VehicleProperties
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
|
function lib.setVehicleProperties(vehicle, props)
|
||||||
|
Entity(vehicle).state:set('ox_lib:setVehicleProperties', props, true)
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user