veers

createMissionTrain crash

Recommended Posts

mp.events.add("playerCommand", (command) => {
	const args = command.split(/[ ]+/);
	const commandName = args[0];

	args.shift();
		
	if (commandName === "train")
	{
		mp.game.vehicle.createMissionTrain(15, 1838.1046142578125, 3528.820556640625, 38.384864807128906, true);
	}
});

 

Share this post


Link to post
Share on other sites

I solved the problem but there is another one. When i try to use the 'vehicle.setTrainSpeed' script command i get an error that 'vehicle.setTrainSpeed' is not a function. I do not know how to stop the train. What's the problem with that command?

Share this post


Link to post
Share on other sites

Train models have to be loaded before you use the script command.

 

mp.game.streaming.requestModel(mp.game.joaat("freight"));
mp.game.streaming.requestModel(mp.game.joaat("freightcar"));
mp.game.streaming.requestModel(mp.game.joaat("freightgrain"));
mp.game.streaming.requestModel(mp.game.joaat("freightcont1"));
mp.game.streaming.requestModel(mp.game.joaat("freightcont2"));
mp.game.streaming.requestModel(mp.game.joaat("freighttrailer"));

 

  • Like 1

Share this post


Link to post
Share on other sites

 

2 часа назад, veers сказал:

So anyone could help with vehicle.setTrainSpeed error?

createMissionTrain returns you a vehicle object. You need to write it to variable or constant, and then call setTrainSpeed method.

var train
mp.events.add("playerCommand", (command) => {
	const args = command.split(/[ ]+/);
	const commandName = args[0];

	args.shift();
		
	if (commandName === "train")
	{
		train = mp.game.vehicle.createMissionTrain(15, 1838.1046142578125, 3528.820556640625, 38.384864807128906, true);
	}
  if(commandName === "setTrainSpeed") {
   if(train) {
    train.setTrainSpeed(parseInt(args[1])) 
   }
  }
});

//then

 

 

Edited by Hanvod

Share this post


Link to post
Share on other sites
5 минут назад, veers сказал:

But mp.events.add is client-side, mp.events.addCommand is server-side.

opps, thats true. BTW

mp.events.add("playerCommand", (command) => {
	const args = command.split(/[ ]+/);
	const commandName = args[0];
const speed = parseInt(args[1])

	args.shift();
		
	if (commandName === "setTrainSpeed")
	{
		train.setTrainSpeed(speed)
	}
});
Edited by Hanvod

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.