kulos Posted July 23, 2023 Share Posted July 23, 2023 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
Shady1 Posted July 24, 2023 Share Posted July 24, 2023 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
kulos Posted July 25, 2023 Author Share Posted July 25, 2023 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
#!_A7M8D Posted July 26, 2023 Share Posted July 26, 2023 Hello you have client.lua and server.lua so this is the meta.xml file <meta> <script src="client.lua" type="client"/> <script src="server.lua" type="server"/> </meta> You can read more about meta.xml file : https://wiki.multitheftauto.com/wiki/Meta.xml Cheers! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now