Jump to content

Co-Driver can control car?


ChisleLP

Recommended Posts

Posted

Hey... I currently a little new. Or I would say, I'm not anymore new. So it started 2 days MTA Scripting (I can before Lua/Java) so its feel for me really easy. but now I'm thinking about:

 

Is it there a way to make co-drivers can control the cars? 

I couldn't find the Events/Function for it. :/

 

Thanks.

 

 

  • Moderators
Posted

You can take over the controls of the driver. But the driver remains to be the syncer of the vehicle. Which means that the delay of the action depends on the driver and co-driver their internet speed.

https://wiki.multitheftauto.com/wiki/SetControlState

https://wiki.multitheftauto.com/wiki/BindKey

(serverside)

  • Like 1

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted (edited)

 

function driverAccelerate (keyPresser, key, keyState)
  
  if key == "W" and getPedOccupiedVehicleSeat(keyPresser) and getPedOccupiedVehicleSeat(keyPresser) ~= 0 then
   
    local veh = getPedOccupiedVehicle(keyPresser)
    local driver = getVehicleController(veh)
    
    if driver then
        if keyState == "down" then 
            setControlState (driver,"accelerate",true)
        else
            setControlState (driver,"accelerate",false)
        end
    else
      
      return
      
    end
    
  end
  
end

bindKey ( player, "W", "both", driverAccelerate) 


Untested :)

Edited by Zorgman
tweaked code
  • Thanks 1

BHgi29I.png
  Dystopia alpha 0.75
DOWNLOAD

Posted (edited)

You should be looking into the better ways of detecting acceleration and the clients preferred key set, as for some players use different keys or controllers.
It's somewhere in the wiki.
MTA Wiki

Edited by Justin|X5|
  • Moderators
Posted

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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