Jump to content
RAGE Multiplayer Community

player.vehicle.engine returning undefined


MrPancakers
 Share

Recommended Posts

Pretty brand new to scripting and I starting learning Javascript for web development not too long ago and thought I'd try to make some things in Rage

My command is this

mp.events.addCommand('engine', (player) => 
{
    if(player.vehicle){
        player.call("engineStatusHandler", player);
    } else {
        player.outputChatBox("You're not in a vehicle");
    }
});

And my event is this

mp.events.add(
{
    "engineStatusHandler": player =>
    {
        let engineStatus = player.vehicle.engine; //Showing as undefined
        if(!engineStatus)
        {
            player.vehicle.setEngineOn(false, true, true);
            mp.gui.chat.push("Engine off.");
            mp.gui.chat.push("Engine Status: " + engineStatus);
        } 
        else 
        {
            player.vehicle.setEngineOn(true, true, true);
            mp.gui.chat.push("Engine on.");
            mp.gui.chat.push("Engine Status: " + engineStatus);
        }   
    }
});

engineStatus is returning undefined when I'm in a vehicle and I'm unsure why it is.

SOLUTION

Use the getIsEngineRunning client side function.

Edited by MrPancakers
Link to comment
Share on other sites

14 hours ago, ragempdev said:

That would work server-side, but your event is client-side. Client-side scripting has different API.

Yeah when I started I realised the difference in Client side and server side, I was attempting to use client side API on server side, after realising that I've understood that.

20 hours ago, Rick said:

because player is undefined 

Replace player.vehicle = mp.players.local.vehicle

I might be missing something, but when I add mp.players.local.vehicle.engine it's still undefined.

Edited by MrPancakers
Link to comment
Share on other sites

Solved this issue, I found that there's a getIsEngineRunning Client Side function and I'm using that to see if the engine is running.

mp.events.add(
{
    "engineStatusHandler": player =>
    {
        let engineStatus = player.vehicle.getIsEngineRunning(); //Showing as undefined
        if(engineStatus)
        {
            player.vehicle.setEngineOn(false, true, true);
            mp.gui.chat.push("Engine off.");
            mp.gui.chat.push("Engine Status: " + engineStatus);
        } 
        else 
        {
            player.vehicle.setEngineOn(true, true, true);
            mp.gui.chat.push("Engine off.");
            mp.gui.chat.push("Engine Status: " + engineStatus);
        }   
    }
});

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...