From 33868c43c46c9e17847e44fb1d027a3920e7e7ec Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 8 Jun 2025 19:40:49 -0400 Subject: [PATCH] Get/Set vehicle props --- modules/framework/es_extended/client.lua | 31 ++++++++++++++++++++++++ modules/framework/qb-core/client.lua | 31 ++++++++++++++++++++++++ modules/framework/qbx_core/client.lua | 31 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 091e342..7b42719 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -130,6 +130,37 @@ Framework.GetPlayerInventory = function() return playerData.inventory end +---This will return the vehicle properties for the specified vehicle. +---@param vehicle number +---@return table +Framework.GetVehicleProperties = function(vehicle) + if not vehicle or not DoesEntityExist(vehicle) then return {} end + local vehicleProps = ESX.Game.GetVehicleProperties(vehicle) + return vehicleProps or {} +end + +---This will set the vehicle properties for the specified vehicle. +---@param vehicle number +---@param properties table +---@return boolean +Framework.SetVehicleProperties = function(vehicle, properties) + if not vehicle or not DoesEntityExist(vehicle) then return false end + if not properties then return false end + if NetworkGetEntityIsNetworked(vehicle) then + local vehNetID = NetworkGetNetworkIdFromEntity(vehicle) + local entOwner = GetPlayerServerId(NetworkGetEntityOwner(vehNetID)) + if entOwner ~= GetPlayerServerId(PlayerId()) then + NetworkRequestControlOfEntity(vehicle) + local count = 0 + while not NetworkHasControlOfEntity(vehicle) and count < 3000 do + Wait(1) + count = count + 1 + end + end + end + return true, QBCore.Functions.SetVehicleProperties(vehicle, properties) +end + ---This will get a players dead status. ---@return boolean Framework.GetIsPlayerDead = function() diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index 43740c6..be6e3f9 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -171,6 +171,37 @@ Framework.GetPlayerInventory = function() return items end +---This will return the vehicle properties for the specified vehicle. +---@param vehicle number +---@return table +Framework.GetVehicleProperties = function(vehicle) + if not vehicle or not DoesEntityExist(vehicle) then return {} end + local vehicleProps = QBCore.Functions.GetVehicleProperties(vehicle) + return vehicleProps or {} +end + +---This will set the vehicle properties for the specified vehicle. +---@param vehicle number +---@param properties table +---@return boolean +Framework.SetVehicleProperties = function(vehicle, properties) + if not vehicle or not DoesEntityExist(vehicle) then return false end + if not properties then return false end + if NetworkGetEntityIsNetworked(vehicle) then + local vehNetID = NetworkGetNetworkIdFromEntity(vehicle) + local entOwner = GetPlayerServerId(NetworkGetEntityOwner(vehNetID)) + if entOwner ~= GetPlayerServerId(PlayerId()) then + NetworkRequestControlOfEntity(vehicle) + local count = 0 + while not NetworkHasControlOfEntity(vehicle) and count < 3000 do + Wait(1) + count = count + 1 + end + end + end + return true, QBCore.Functions.SetVehicleProperties(vehicle, properties) +end + ---This will get a players dead status. ---@return boolean Framework.GetIsPlayerDead = function() diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index 7cbe3ba..f1cadd2 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -108,6 +108,37 @@ Framework.GetPlayerInventory = function() return Framework.GetPlayerData().items end +---This will return the vehicle properties for the specified vehicle. +---@param vehicle number +---@return table +Framework.GetVehicleProperties = function(vehicle) + if not vehicle or not DoesEntityExist(vehicle) then return {} end + local vehicleProps = lib.getVehicleProperties(vehicle) + return vehicleProps or {} +end + +---This will set the vehicle properties for the specified vehicle. +---@param vehicle number +---@param properties table +---@return boolean +Framework.SetVehicleProperties = function(vehicle, properties) + if not vehicle or not DoesEntityExist(vehicle) then return false end + if not properties then return false end + if NetworkGetEntityIsNetworked(vehicle) then + local vehNetID = NetworkGetNetworkIdFromEntity(vehicle) + local entOwner = GetPlayerServerId(NetworkGetEntityOwner(vehNetID)) + if entOwner ~= GetPlayerServerId(PlayerId()) then + NetworkRequestControlOfEntity(vehicle) + local count = 0 + while not NetworkHasControlOfEntity(vehicle) and count < 3000 do + Wait(1) + count = count + 1 + end + end + end + return true, lib.setVehicleProperties(vehicle, properties) +end + ---This will return the item count for the specified item in the players inventory. ---@param item string ---@return number