veers

createMissionTrain crash

Recommended Posts

Hi!

The createMissionTrain command crashes the server. I don't know if it's my fault or the command's.

Share this post


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

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.