feat(vehicleProperties): add statebag handler and server setter

This commit is contained in:
Linden
2024-07-13 00:25:30 +10:00
parent 6ffc5afd0f
commit c45aa0d893
3 changed files with 27 additions and 9 deletions

View File

@@ -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)
}

View File

@@ -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 = lib.waitFor(function()
local entity = GetEntityFromStateBagName(bagName) local entity = GetEntityFromStateBagName(bagName)
local networked = not bagName:find('localEntity')
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()

View 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