Jump to content

Recommended Posts

Posted

Ok, I got it. Wait a little bit, I will give you a working solution.

16 минут назад, veers сказал:

Type error: setTrainSpeed is not a function.

Because createMissionTrain returns a handle. I found the solution, will record video, wait ~10 minutes

Posted (edited)
38 минут назад, veers сказал:

Type error: setTrainSpeed is not a function.

You need to call mp.game.invoke('0xAA0BC91BE0B796E3', train, speed) (SET_TRAIN_SPEED) where train is your train handle (you got it from createMissionTrain()) and speed is your speed. But when I use 

const speed = 5.0 it works, but if I will write speed = parseFloat(args[1]), It crashes the game.

Also after you set train speed, it will accelerate back to cruise speed, so you need to call mp.game.invoke("0x16469284DB8C62B5", train, speed) (SET_TRAIN_CRUISE_SPEED) to make train speed static.

Will write back when I will get  solution for this crash.

Edited by Hanvod
Posted (edited)

UPD: -1 makes train go backwards very fast 🤣

Also It seems that I really need to restart my game

bsZTLM8.jpg

Ok, Im just wasted 2 hours trying to figure it out. I'll try again later.

Edited by Hanvod
Posted

Still getting "is not function" error.

mp.events.add("playerCommand", (command) => {
	const args = command.split(/[ ]+/);
	const commandName = args[0];
	
	args.shift();
	
	if (commandName === "train")
	{
		if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freight")))
			mp.game.streaming.requestModel(mp.game.joaat("freight"));
		while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freight")))
			mp.game.wait(0);
		
		if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcar")))
			mp.game.streaming.requestModel(mp.game.joaat("freightcar"));
		while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcar")))
			mp.game.wait(0);
		
		if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightgrain")))
			mp.game.streaming.requestModel(mp.game.joaat("freightgrain"));
		while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightgrain")))
			mp.game.wait(0);
		
		if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont1")))
			mp.game.streaming.requestModel(mp.game.joaat("freightcont1"));
		while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont1")))
			mp.game.wait(0);
		
		if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont2")))
			mp.game.streaming.requestModel(mp.game.joaat("freightcont2"));
		while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont2")))
			mp.game.wait(0);
		
		if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freighttrailer")))
			mp.game.streaming.requestModel(mp.game.joaat("freighttrailer"));
		while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freighttrailer")))
			mp.game.wait(0);
		
		const speed = 5.0;
		
		train = mp.game.vehicle.createMissionTrain(15, 2693.93408203125, 3067.782958984375, 41.46901321411133, false);
		mp.game.invoke('0xAA0BC91BE0B796E3', train, speed);
		mp.game.invoke('0x16469284DB8C62B5', train, speed);
		train.setTrainSpeed(speed);
		train.setTrainCruiseSpeed(speed);
	}
});

I don't know what can be the problem.

Posted

mp.game.invoke calls a native, you dont need train.setTrainSpeed. 

var train
mp.events.add("playerCommand", (command) => {
    const args = command.split(/[ ]+/);
    const commandName = args[0];
    
    args.shift();
    
    if (commandName === "train")
    {
        if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freight")))
            mp.game.streaming.requestModel(mp.game.joaat("freight"));
        while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freight")))
            mp.game.wait(0);
        
        if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcar")))
            mp.game.streaming.requestModel(mp.game.joaat("freightcar"));
        while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcar")))
            mp.game.wait(0);
        
        if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightgrain")))
            mp.game.streaming.requestModel(mp.game.joaat("freightgrain"));
        while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightgrain")))
            mp.game.wait(0);
        
        if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont1")))
            mp.game.streaming.requestModel(mp.game.joaat("freightcont1"));
        while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont1")))
            mp.game.wait(0);
        
        if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont2")))
            mp.game.streaming.requestModel(mp.game.joaat("freightcont2"));
        while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freightcont2")))
            mp.game.wait(0);
        
        if(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freighttrailer")))
            mp.game.streaming.requestModel(mp.game.joaat("freighttrailer"));
        while(!mp.game.streaming.hasModelLoaded(mp.game.joaat("freighttrailer")))
            mp.game.wait(0);
    }
    if(commandName === "trainSpeed") {
        const speed = 5.0;
        mp.game.invoke('0xAA0BC91BE0B796E3', train, speed);
        mp.game.invoke('0x16469284DB8C62B5', train, speed);
    }
});

Result: 

Posted

That code works with very low speed, but nothing happens if it greater that something near 3.0

https://streamable.com/mi505

if(commandName === "trainSpeed") {
		
		mp.game.invoke('0xAA0BC91BE0B796E3', train, 1.5);
		mp.game.invoke('0x16469284DB8C62B5', train, 1.5);
	}

 

Value -0.25 makes it slowly go backwards

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