Jump to content

[SOLVED] Apply velocity to vehicle synced with server


Recommended Posts

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 by Guest
Link to comment

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

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

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