Jump to content

Vehicle Component Sync Question


rfmx

Recommended Posts

Posted

I am using vehicle component functions (for custom visual tuning) but they are client side only.

What is the best way to sync vehicle component manipulation (position, visibility) between players?

Posted
addCommandHandler("vcp", 
    function()
        local theVeh = getPedOccupiedVehicle(localPlayer)
        
        local x, y, z = getVehicleComponentPosition(theVeh, "wheel_rf_dummy")
        setVehicleComponentPosition(theVeh, "wheel_rf_dummy", x+0.15, y, z)
        
        local x, y, z = getVehicleComponentPosition(theVeh, "wheel_rb_dummy")
        setVehicleComponentPosition(theVeh, "wheel_rb_dummy", x+0.15, y, z)
        
        local x, y, z = getVehicleComponentPosition(theVeh, "wheel_lf_dummy")
        setVehicleComponentPosition(theVeh, "wheel_lf_dummy", x-0.15, y, z)
        
        local x, y, z = getVehicleComponentPosition(theVeh, "wheel_lb_dummy")
        setVehicleComponentPosition(theVeh, "wheel_lb_dummy", x-0.15, y, z)
        

    end
)

It is just a simple test script. I thought about using setElementData  for vehicles and onClientElementStreamIn for clients to sync it.

I'm just not shure if it's a good aproach or is there a better way of doing this. 

Posted

Server side:

addCommandHandler("vcp",
function(player)
	local vehicle = getPedOccupiedVehicle(player)
	if isElement(vehicle) then
		triggerClientEvent(root, "syncVehicleComponents", vehicle)
	end
end)

Client side:

addEvent("syncVehicleComponents", true)
addEventHandler("syncVehicleComponents", root,
function()
	if isElement(source) and getElementType(source) == "vehicle" then	    
            local x, y, z = getVehicleComponentPosition(source, "wheel_rf_dummy")
            setVehicleComponentPosition(source, "wheel_rf_dummy", x+0.15, y, z)

            local x, y, z = getVehicleComponentPosition(source, "wheel_rb_dummy")
            setVehicleComponentPosition(source, "wheel_rb_dummy", x+0.15, y, z)

            local x, y, z = getVehicleComponentPosition(source, "wheel_lf_dummy")
            setVehicleComponentPosition(source, "wheel_lf_dummy", x-0.15, y, z)

            local x, y, z = getVehicleComponentPosition(source, "wheel_lb_dummy")
            setVehicleComponentPosition(source, "wheel_lb_dummy", x-0.15, y, z)
	end
end)

 

Posted

This should work.

--Add to client side in meta file
addEventHandler("onClientVehicleEnter", getRootElement(),
function()
theVeh = getPedOccupiedVehicle(thePlayer)
--Your following code
end
)

 

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...