veers

createMissionTrain crash

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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: 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.