Getting the current engine thrust level

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
streb2001
Competent
Competent
Posts: 53
Joined: Sat Aug 16, 2014 12:06 pm

Getting the current engine thrust level

Post by streb2001 »

I am trying to modify a script to change the volume of an engine sound according to the current engine thrust level (w and s keys). I am reading the player.ship.thrust property but it always seems to return the ship's maximum thrust (=32 for the Cobra III).

Is there a property that will return the actual engine level, in this case somewhere between 0 and 32 presumably?

The sound plays OK, I just cannot change the volume.

Here are my code snippets:

Code: Select all

	this.sprTimer = new Timer(this,this.sprTick,0,0.25); this.sprTimer.stop();
	this.sprEngineSound = new SoundSource;
	sprEngineSound.sound = "sprEngine.ogg";
	sprEngineSound.loop = true;


this.sprTick = function()
{
	//normalise to produce volume 0 - 1
	sprEngineSound.volume = player.ship.thrust/player.ship.maxThrust;

	//debug output
	log(this.name,"Current Level: "+player.ship.thrust); //always gives 32

	return;
};

this.shipWillLaunchFromStation = function(station)
{
	 // ... other code

	this.sprTimer.start();
	sprEngineSound.play();

};
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Getting the current engine thrust level

Post by cim »

The thrust property measures the ability of the ship to accelerate. While it could in theory change, it doesn't tend to. (I'm not sure there are any circumstances in which the JS value changes for the player ship)

You probably want player.ship.speed and player.ship.maxSpeed instead (noting that speed will exceed maxSpeed under injectors or torus drive, but the SoundSource will treat any volume > 1 as equal to 1 anyway, so you probably don't need to worry about that here)
User avatar
streb2001
Competent
Competent
Posts: 53
Joined: Sat Aug 16, 2014 12:06 pm

Re: Getting the current engine thrust level

Post by streb2001 »

Excellent! Thank you, that works nicely. I now have a custom engine roar whose volume is proportional to my speed.

btw I have done this by hacking the main script in the BGS expansion along with stealing the engine sound from the XR2 in Orbiter.

ed. top tip for other newbie script hackers: Hold the Shift key down when starting Oolite! It seems that scripts are cached and changes will not register even after a reboot.
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Getting the current engine thrust level

Post by dertien »

Welcome to the boards streb2001

Nice job on the script, I was thinking about missing engine sound for the player only yesterday.
streb2001 wrote:
Excellent! Thank you, that works nicely. I now have a custom engine roar whose volume is proportional to my speed.

btw I have done this by hacking the main script in the BGS expansion along with stealing the engine sound from the XR2 in Orbiter.

ed. top tip for other newbie script hackers: Hold the Shift key down when starting Oolite! It seems that scripts are cached and changes will not register even after a reboot.

Yes, or you can always add the line

Code: Select all

"always-flush-cache" = YES;
to the .GNUstepDefaults file like so:

Code: Select all

{
    NSGlobalDomain = {
    };
    oolite = {
	"Commander Gordts-humbletrash" = "-6792";
	"Jameson-humbletrash" = "-29624";
	JoystickAxes = {
	    0 = {
		isAxis = 1;
		stickAxBt = 0;
		stickNum = 0;
	    };
	    1 = {
		isAxis = 1;
		stickAxBt = 1;
		stickNum = 0;
	    };
	};
	JoystickButs = {
	    0 = {
		isAxis = 0;
		stickAxBt = 3;
		stickNum = 0;
	    };
	    1 = {
		isAxis = 0;
		stickAxBt = 1;
		stickNum = 0;
	    };
	    12 = {
		isAxis = 0;
		stickAxBt = 11;
		stickNum = 0;
	    };
	    13 = {
		isAxis = 0;
		stickAxBt = 7;
		stickNum = 0;
	    };
	    14 = {
		isAxis = 0;
		stickAxBt = 10;
		stickNum = 0;
	    };
	    15 = {
		isAxis = 0;
		stickAxBt = 67;
		stickNum = 0;
	    };
	    16 = {
		isAxis = 0;
		stickAxBt = 65;
		stickNum = 0;
	    };
	    17 = {
		isAxis = 0;
		stickAxBt = 6;
		stickNum = 0;
	    };
	    19 = {
		isAxis = 0;
		stickAxBt = 5;
		stickNum = 0;
	    };
	    21 = {
		isAxis = 0;
		stickAxBt = 4;
		stickNum = 0;
	    };
	    23 = {
		isAxis = 0;
		stickAxBt = 2;
		stickNum = 0;
	    };
	    32 = {
		isAxis = 0;
		stickAxBt = 64;
		stickNum = 0;
	    };
	    33 = {
		isAxis = 0;
		stickAxBt = 66;
		stickNum = 0;
	    };
	    8 = {
		isAxis = 0;
		stickAxBt = 9;
		stickNum = 0;
	    };
	    9 = {
		isAxis = 0;
		stickAxBt = 8;
		stickNum = 0;
	    };
	};
	PitchAxisProfile = {
	    Deadzone = 0.05;
	    Parameter = 1;
	    Power = 1;
	    Type = Standard;
	};
	RollAxisProfile = {
	    Deadzone = 0.05;
	    Parameter = 1;
	    Power = 1;
	    Type = Standard;
	};
	YawAxisProfile = {
	    Deadzone = 0.05;
	    Parameter = 1;
	    Power = 1;
	    Type = Standard;
	};
	"always-flush-cache" = YES;
	"debug-settings-override" = {
	};
	fullscreen = YES;
	"music mode" = off;
	"save-directory" = "C:\\games/Oolite-1.81-blue ownbuild/oolite.app/oolite-saves";
	"show-ship-model-in-status-screen" = YES;
    };
}
Open file with notepad ++ and not notepad since it leaves garbage (carriage returns)

Then you won't have to worry about the shift key again ever.
Alpha Backer of Elite Dangerous
With 250 GBP :D
Post Reply