Jump to content

[HELP] getVehicleComponents() bug?


maximumdrive

Recommended Posts

Hi all,

my question is so close to be "stupid/funny", but I wasted several hours to fight those lines.

Here is a clientside function handling an event. Element's model is viewed to *debug* if the vehicle comes from server. The problem is that the vehicle exists, model also does, but the length of *sincerely beloved* getVehicleComponents(veh) is always "0"! It only can type component's list when the function is "bouned" on a key which has to be pushed for tens of times to meet a success! The "central surprise" is that the usage example of getVehicleComponents is taken from MTA Wiki and it fails!

I've found some reports, so the components are in some way cached by MTA/GTA-single, so it could influence this simple code, but I can't even imagine what is the problem. 

I'm totally discouraged by such a mysticism and have no ideas about causes. Please, help.

function tunBaseComp(veh)
	outputChatBox(tostring(getElementModel(veh)))
	local getComponent = getVehicleComponents(veh)
	if veh then
		for k in pairs(getComponent) do
			outputChatBox(k)
		end
	end
end

 

Link to comment

So this function is triggered by an event? Because that works fine for me...
Code i've used:

Server:

addCommandHandler("gvc", function (player)
	triggerClientEvent(player, "onClientGetVehicleComp", player, getPedOccupiedVehicle(player))
end)

Client:

addEvent("onClientGetVehicleComp", true)
addEventHandler("onClientGetVehicleComp", localPlayer, function (veh)
	outputChatBox(tostring(getElementModel(veh)))
	local getComponent = getVehicleComponents(veh)
	if veh then
		for k in pairs(getComponent) do
			outputChatBox(k)
		end
	end
end)

 

Link to comment
On 16/09/2018 at 18:26, MIKI785 said:

Server:


addCommandHandler("gvc", function (player)
	triggerClientEvent(player, "onClientGetVehicleComp", player, getPedOccupiedVehicle(player))
end)

 

Oh, now it's clear: the problem is, that the getPedOccupiedVehicle() works really fine, but when I try to create another vehicle it doesn't work for a newly-created serverside vehicle. But it creates, it's model successfully outputs to chatbox, but getVehicleComponents()'s length is "0"... The clientside code is the same as yours now. 

E.g. (Server):

addCommandHandler("gvc", function (player)
	local pVeh = getPedOccupiedVehicle(player)
	local seat = getPedOccupiedVehicleSeat(player)
	if pVeh and seat == 0 then
		local px, py, pz = getElementPosition(pVeh)
		local px, py, pz = getElementRotation(pVeh)
		local v = createVehicle(405, px, py, pz-20, rx, ry, rz)
		setElementFrozen(v, true)
		setElementCollisionsEnabled(v, false)
		setVehicleLocked(v, true)
		attachElements(v, pVeh, 0, 0, -6, 0, 0, 0)

		
		triggerClientEvent(player, "onClientGetVehicleComp", player, v)
	end
end)

 

Edited by maximumdrive
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...