mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

setTrainSpeed vs getTrainSpeed

Open KWKSND opened this issue 2 years ago • 4 comments

Describe the bug

When you use setTrainSpeed( ) you are able to set it to a positive or negative number.

When using getTrainSpeed( ) it will not return a negative number. When the speed is set below 0 getTrainSpeed() will only return 0.

To be able to make a train that is reversible and have all cars match the engine speed this function must return the negative value that was set to the train using setTrainSpeed( )

Steps to reproduce

create train set speed to a negative value using setTrainSpeed( ) output value using getTrainSpeed( ) to see only a 0.

Version

No response

Additional context

No response

Relevant log output

No response

Security Policy

  • [X] I have read and understood the Security Policy and this issue is not security related.

KWKSND avatar Sep 11 '22 09:09 KWKSND

Can be fixed via script for temporary. Use getTrainDirection and custom function to calculate train speed. Didn't test this, but should be work:

function getTrainSpeedCustom(train)
	return (getTrainDirection(train) and -getTrainSpeed(train) or getTrainSpeed(train))
end

Xenius97 avatar Sep 15 '22 06:09 Xenius97

Can be fixed via script for temporary. Use getTrainDirection and custom function to calculate train speed. Didn't test this, but should be work:

function getTrainSpeedCustom(train)
	return (getTrainDirection(train) and -getTrainSpeed(train) or getTrainSpeed(train))
end

does not work and it can't in this case. getTrainDirection simply tells you what way the train is facing. setTrainSpeed(train,1) would make the train travel clockwise around the map regardless of which way the train faces. setTrainSpeed(train,-1) would make the train travel counter clockwise around the map regardless of which way the train faces.

also when the speed is set below 0 getTrainSpeed(train) only returns 0 not a positive value

KWKSND avatar Sep 17 '22 13:09 KWKSND

So #2741 won't be right too. Does Train have gearbox with 'Reverse' shift? This will not work? https://wiki.multitheftauto.com/wiki/GetVehicleCurrentGear

Allerek avatar Sep 18 '22 21:09 Allerek