Jump to content

Automatically turning on the engine of the vehicle OnPlayerEnterVehicle


Recommended Posts

Posted

So I created a vehicle engine system on my server side combined to a client side key bind. But the problem is that when a player enters the vehicle, the engine turns on automatically and it's annoying for RP gameplay. Can someone give me a client side method wich disables the automatic vehicle engine on ? 

Thank you

Posted

Tried this and the problem is that when the player enters the vehicle, he triggers the engine automatically on, and also when I turn off the engine with 2 key press(0x32) the player turns on the engine after it again ! please help dude

 

My client side code
mp.keys.bind(0x32, true, function() { 
    let player = mp.players.local;
    let vehicle = player.vehicle;

    if (vehicle) {
        let isEngineRunning = vehicle.getIsEngineRunning();
        vehicle.setEngineOn(!isEngineRunning, false, true); 
        mp.events.callRemote('serverToggleEngine', vehicle); 
    }
});

My Server side code: 
mp.events.add('serverToggleEngine', (player, vehicle) => {
    if (vehicle) {
        let currentEngineState = vehicle.engine;
        vehicle.engine = !currentEngineState; 
    }
});
 

  • Xabi locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...