ivan8065 Posted December 26, 2021 Posted December 26, 2021 Hello, I am trying to do working side doors on van through setComponentPosition and trying to sync it with other players with triggerClientEvent but it's not working, what I have got wrong? Thank you for reply. CLIENT function scp() local theVeh = getPedOccupiedVehicle(localPlayer) local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle if (theVeh) then local x, y, z = getVehicleComponentPosition(theVeh, "bocne_dvere") --get the position of the component setVehicleComponentPosition(theVeh, "bocne_dvere", x+0.1, y-1, 0) -- increases by 1 unit end end addEvent("scp", true) addEventHandler("scp", localPlayer, scp) function scp2() local theVeh = getPedOccupiedVehicle(localPlayer) local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle if (theVeh) then local x, y, z = getVehicleComponentPosition(theVeh, "bocne_dvere") --get the position of the component setVehicleComponentPosition(theVeh, "bocne_dvere", x-0.1, y+1, 0) -- increases by 1 unit end end addEvent("scp2", true) addEventHandler("scp2", localPlayer, scp2) function scpreset() local theVeh = getPedOccupiedVehicle(localPlayer) local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle if (theVeh) then local x, y, z = getVehicleComponentPosition(theVeh, "bocne_dvere") --get the position of the component setVehicleComponentPosition(theVeh, "bocne_dvere", 0, 0, 0) -- increases by 1 unit end end addEvent("scpreset", true) addEventHandler("scpreset", localPlayer, scpreset) SERVER function scp ( thePlayer, commandName ) local x, y, z = getElementPosition(thePlayer) local nearbyPlayers = getElementsWithinRange(x, y, z, 100, "player") triggerClientEvent (nearbyPlayers,"scp",thePlayer) end addCommandHandler ("scp", scp) function scp2 ( thePlayer, commandName ) local x, y, z = getElementPosition(thePlayer) local nearbyPlayers = getElementsWithinRange(x, y, z, 100, "player") triggerClientEvent (nearbyPlayers,"scp2",thePlayer) end addCommandHandler ("scp2", scp2) function scpreset ( thePlayer, commandName ) local x, y, z = getElementPosition(thePlayer) local nearbyPlayers = getElementsWithinRange(x, y, z, 100, "player") triggerClientEvent (nearbyPlayers,"scpreset",thePlayer) end addCommandHandler ("scpreset", scpreset)
Moderators IIYAMA Posted December 26, 2021 Moderators Posted December 26, 2021 1 hour ago, ivan8065 said: function scp() local theVeh = getPedOccupiedVehicle(localPlayer) Try this: function scp(thePlayer) local theVeh = getPedOccupiedVehicle(thePlayer) Be aware that this code does not sync the state of the component, it only syncs the adjustment. But it is a good start, keep it up!
The_GTA Posted December 26, 2021 Posted December 26, 2021 Hello ivan8065, I would like to amend the statement by IIYAMA which I think does lead you in the right direction. The way that you have written your clientside code the "synchronization" is only happening for the player that requested the action, not all the players. This way it causes a desync where other players cannot see changing of the components between each other. Consider changing... ... addEventHandler("scp", localPlayer, scp) ... to ... ... addEventHandler("scp", root, scp) ... I am not sure if IIYAMA is aware but the source variable in ivan8065's code event handlers is already containing the player, so there is no need to put a "thePlayer" parameter to the event handler. You should consider doing... function scp() local theVeh = getPedOccupiedVehicle(source) Also please consider naming your events strongly and picking different function names than the event names. Keep up the good work with those interesting ideas! 2
ivan8065 Posted December 27, 2021 Author Posted December 27, 2021 @The_GTA I did changes you written and it works, thank you very much for help!
The_GTA Posted December 27, 2021 Posted December 27, 2021 (edited) 2 minutes ago, ivan8065 said: @The_GTA I did changes you written and it works, thank you very much for help! You're welcome! I am glad to have helped you. We are a community that care about each other. Edited December 27, 2021 by The_GTA 1
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