Jump to content

How to synchronize vehicle component rotation


kulos

Recommended Posts

I want to synchronize this script with server so every player sees when vehicle component rotates

 

function headLightsOpen()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if (theVeh) then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       setVehicleComponentRotation(theVeh, "misc_a", rx+5, ry, rz)
   end
end
--bindKey ( "Num_9", "down", headLightsOpen )
addCommandHandler("lamp1", headLightsOpen)


function headLightsClose()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if (theVeh) then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       setVehicleComponentRotation(theVeh, "misc_a", rx-5, ry, rz)       
   end
end
--bindKey ( "Num_3", "down", headLightsClose )
addCommandHandler("lamp2", headLightsClose)

Link to comment
17 hours ago, kulos said:

I want to synchronize this script with server so every player sees when vehicle component rotates

 

function headLightsOpen()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if (theVeh) then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       setVehicleComponentRotation(theVeh, "misc_a", rx+5, ry, rz)
   end
end
--bindKey ( "Num_9", "down", headLightsOpen )
addCommandHandler("lamp1", headLightsOpen)


function headLightsClose()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if (theVeh) then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       setVehicleComponentRotation(theVeh, "misc_a", rx-5, ry, rz)       
   end
end
--bindKey ( "Num_3", "down", headLightsClose )
addCommandHandler("lamp2", headLightsClose)

server-side : 
 

-- server-side
addEvent("onHeadLightsRotate", true)

addEventHandler("onHeadLightsRotate", root, function(rx, ry, rz)
    local theVeh = getPedOccupiedVehicle(source)
    if theVeh then
        setVehicleComponentRotation(theVeh, "misc_a", rx, ry, rz)
    end
end)

client-side :
 

-- client.lua

local function headLightsOpen()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if theVeh then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       rx = rx + 5
       triggerServerEvent("onHeadLightsRotate", localPlayer, rx, ry, rz)
   end
end

local function headLightsClose()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if theVeh then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       rx = rx - 5
       triggerServerEvent("onHeadLightsRotate", localPlayer, rx, ry, rz)
   end
end

addCommandHandler("lamp1", headLightsOpen)
addCommandHandler("lamp2", headLightsClose)

Now, when a player triggers the "lamp1" or "lamp2" command, the client will send the updated rotation values to the server using the "onHeadLightsRotate" remote event. The server will then receive these values and update the vehicle component rotation for all players, ensuring that the rotation is synchronized across the network.

Link to comment
13 hours ago, Shady1 said:

server-side : 
 

-- server-side
addEvent("onHeadLightsRotate", true)

addEventHandler("onHeadLightsRotate", root, function(rx, ry, rz)
    local theVeh = getPedOccupiedVehicle(source)
    if theVeh then
        setVehicleComponentRotation(theVeh, "misc_a", rx, ry, rz)
    end
end)

client-side :
 

-- client.lua

local function headLightsOpen()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if theVeh then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       rx = rx + 5
       triggerServerEvent("onHeadLightsRotate", localPlayer, rx, ry, rz)
   end
end

local function headLightsClose()
   local theVeh = getPedOccupiedVehicle(localPlayer)
   if theVeh then
       local rx, ry, rz = getVehicleComponentRotation(theVeh, "misc_a")
       rx = rx - 5
       triggerServerEvent("onHeadLightsRotate", localPlayer, rx, ry, rz)
   end
end

addCommandHandler("lamp1", headLightsOpen)
addCommandHandler("lamp2", headLightsClose)

Now, when a player triggers the "lamp1" or "lamp2" command, the client will send the updated rotation values to the server using the "onHeadLightsRotate" remote event. The server will then receive these values and update the vehicle component rotation for all players, ensuring that the rotation is synchronized across the network.

What should be in .xml file?

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