Einheit-101 Posted March 23, 2014 Share Posted March 23, 2014 (edited) Hello Community. I have created a drivable Trailer and i want a function that rotates this trailer while pressing A or D to the left or to the right because it is not possible to rotate the trailer without scripting. I found "setVehicleTurnVelocity", it should work, but is client-side "setVehicleTurnVelocity" synced with the server/other clients or is it even possible to set the velocity client side while the vehicle exists for all clients? Edited March 23, 2014 by Guest Link to comment
WhoAmI Posted March 23, 2014 Share Posted March 23, 2014 You have to use this function serverside, then all sever could see it. Link to comment
Einheit-101 Posted March 23, 2014 Author Share Posted March 23, 2014 So i have to do something like: onClientRender() if getKeyState( "d" ) == true then triggerServerEvent(....) I hope the lag wont be so much due to the triggerServerEvent Link to comment
arezu Posted March 23, 2014 Share Posted March 23, 2014 So i have to do something like:onClientRender() if getKeyState( "d" ) == true then triggerServerEvent(....) I hope the lag wont be so much due to the triggerServerEvent You can use bindKey server sided instead. Link to comment
Einheit-101 Posted March 23, 2014 Author Share Posted March 23, 2014 But bindKey will not make a "smooth" movement of the vehicle, or is there a way to do this? onClientRender allows a smooth rotation of the vehicle. Link to comment
WhoAmI Posted March 23, 2014 Share Posted March 23, 2014 For example bindKey ( player, "d", "down", function () --trailer turns right end ) bindKey ( player, "d", "up", function () --trailer ends turning right end ) Link to comment
Spajk Posted March 23, 2014 Share Posted March 23, 2014 If the driver is the syncer of the trailer then you could use the function client-side. Link to comment
Einheit-101 Posted March 23, 2014 Author Share Posted March 23, 2014 There is just one person in the Trailer and this is the Driver. So i could just use the velocity client side? Thanks for the tip with bindKey but i got some problems at the moment with that velocity stuff. It is not easy to rotate the vehicle into the right direction. €DIT::: setElementRotation seems to work fine. I report back later. €DIT 2::: Here is it. It works but i dont know if it is synced (i am alone.) function aim() local veh = getPedOccupiedVehicle ( localPlayer ) if veh and getElementModel ( veh ) == 611 then if getKeyState( "a" ) == true then local rx, ry, rz = getElementRotation(veh) setElementRotation(veh, rx, ry, rz+0.1) end if getKeyState( "d" ) == true then local rx, ry, rz = getElementRotation(veh) setElementRotation(veh, rx, ry, rz-0.1) end end addEventHandler("onClientRender", root, aim) Link to comment
arezu Posted March 23, 2014 Share Posted March 23, 2014 Client-side functions setElementPosition, setElementRotation, setElementVelocity and setVehicleTurnVelocity (and a few more functions) automatically sync with server if the element was created server sided. Link to comment
Einheit-101 Posted March 23, 2014 Author Share Posted March 23, 2014 Thank you. This information may be useful for the future. Link to comment
xXMADEXx Posted March 23, 2014 Share Posted March 23, 2014 I would do something similar to this: local ButtonStates = { a = false, d = false } function bindKeys( k, s) if ( k == "a" ) then if ( s == "down" ) then if ( ButtonStates.a ) then return end ButtonStates.a = true addEventHandler("onClientRender",root,onRender_a) else endButtStates.a = false end elseif ( k == "d" ) then if ( s == "down" ) then if ( ButtonStates.d ) then return end ButtonStates.d = true addEventHandler("onClientRender",root,onRender_d) else endButtStates.d = false end end end bindKey ( "A", "both", bindKeys) bindKey ( "D", "both", bindKeys) function onRender_a ( ) if ( not ButtonStates.a or not isPedInVehcle(localPlayer) ) then ButtonStates.a = false return removeEventHandler("onClientRender",root,onRender_a ) end local c = getPedOccupiedVehicle ( localPlayer ) local sx, sy, sz = getElementRotation ( c ) setElementRotation ( c, sx, sy + 0.1, sz ) end function onRender_d ( ) if ( not ButtonStates.d or not isPedInVehcle(localPlayer) ) then ButtonStates.d = false return removeEventHandler("onClientRender",root,onRender_d) end local c = getPedOccupiedVehicle ( localPlayer ) local sx, sy, sz = getElementRotation ( c ) setElementRotation ( c, sx, sy - 0.1, sz ) end Link to comment
WhoAmI Posted March 23, 2014 Share Posted March 23, 2014 You have to get vehicle server side to make it works. Link to comment
Spajk Posted March 23, 2014 Share Posted March 23, 2014 As far as I know, every function used client side on an element whose streamer is the local player should be synced. That's how MTA works. The player "reports" every action for the elements he's streaming to the server. Link to comment
xXMADEXx Posted March 24, 2014 Share Posted March 24, 2014 As far as I know, every function used client side on an element whose streamer is the local player should be synced. That's how MTA works. The player "reports" every action for the elements he's streaming to the server. Yea you're right... I recommend using getTickCount() and sending the event every about 3 seconds to prevent major lag. Link to comment
arezu Posted March 24, 2014 Share Posted March 24, 2014 As far as I know, every function used client side on an element whose streamer is the local player should be synced. That's how MTA works. The player "reports" every action for the elements he's streaming to the server. Not exactly all functions are synced, it would be good to have a list of functions that sync though.. I recommend using getTickCount() and sending the event every about 3 seconds to prevent major lag. MTA already uses a timer to sync with server, so it shouldn't matter if you spam them onClientRender. Link to comment
Spajk Posted March 24, 2014 Share Posted March 24, 2014 It's not about functions, it's about states of the element that are synced. 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