Jump to content

Vehicle Component Sync Question


rfmx

Recommended Posts

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. 

Link to comment

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)

 

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