Can I bring the palyers ship to a full stop, in a script?

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

Moderators: winston, another_commander

Post Reply
Gwydion
Average
Average
Posts: 10
Joined: Wed Oct 18, 2023 4:41 pm

Can I bring the palyers ship to a full stop, in a script?

Post by Gwydion »

I'm playing with a mission. I have a story and time line on paper and am currently checking the things I can and cannot do and tweaking the story to suit. I found this quicker than writing the code in full then have to test from the beginning again, or jump through stages.

Anyway, I have a part when the player is most likely heading at full speed towards a space station and I pop up a message for them to read. Since I don't want to crash the player into the station and well, err um, kill them I thought I could stop the players ship or divert it off course. Because crashing into the station would be annoying.

So far I cannot find any entity or ship or player.ship methods to do that. I did find performFlee(), performFlyToRangeFromDestination(), these need a target but that might not be set to the station yet, and they only seem to be for NPC. There was also performHold() and perfomStop() but these appear to be for NPC ships and do nothing for the player.ship when used from the debug console or JS script. I also played around with player.ship.thrust and maxThrust, speed and maxSpeed.

Since I don't want to kill the commander doing the mission any solution that stops a crash would work.

Any ideas?
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Can I bring the players ship to a full stop, in a script?

Post by Cholmondely »

Another mission! Gosh!!



That's you, Killer Wolf (maybe something involving both his Isis Interstellar company and Zaonce), and possibly Phkb (HIMSN?).



Does it involve Raxxla?



For Oolite, generally, I feel that missions can be very important (I've not played too many of them).

Several of the Galaxies are "fleshed out" by missions. I'm thinking particularly of The Assassins Guild and G7, and The Iron Raven and G8. But Ionics rebuilds the North East of G2 and Resistance Commander rejigs the South of G6.

So! More power to both your elbows and those of KW & Phkb!
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Gwydion
Average
Average
Posts: 10
Joined: Wed Oct 18, 2023 4:41 pm

Re: Can I bring the palyers ship to a full stop, in a script?

Post by Gwydion »

Sorry, it's in Galaxy 2, so nothing to do with Zaonce or Isis Interstellar or even HIMSN. No not even in Raxxla. :lol:

I have only done a few those from Galaxy 1 and I loved them.
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Can I bring the players ship to a full stop, in a script?

Post by Cholmondely »

Gwydion wrote: Sat Dec 23, 2023 6:24 pm
Sorry, it's in Galaxy 2, so nothing to do with Zaonce or Isis Interstellar or even HIMSN. No not even in Raxxla. :lol:

I have only done a few those from Galaxy 1 and I loved them.
Don't know if it is relevant, but DGill is doing some absolutely wonderful things with his updating of the Feudal States.oxp, so if matters Feudal are involved it might be worth dropping him a line.


Also, you might wish to exclude some OXPs which you feel might ruin the plot (https://wiki.alioth.net/index.php/Cheating contains a list of these)


And - since you seem to understand this sort of stuff, Library.oxp is jam-packed with goodies for people writing missions. It is not all properly documented (premature death of author), but the older predecessor, CCL, has some of the missing documentation. NPC mugshots, medals, animations & star-maps, music/sound organisation, etc. CCL contained other stuff - which I presume is still tucked away inside Library.OXP - including a script for analysing whether the player is up to the challenge - and another for managing in-flight missions screens.

Sadly, the only OXP written which used this stuff was Vector (only works on v.1.77.1 or earlier) - Svengali died before he was able to update it for Library.oxp

Svengali did write some proof-of-concept oxps which you will find linked to the Library.oxp & CCL.oxp wiki pages.


Dear old phkb has managed to decipher some of the workings of some of the above...
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Gwydion
Average
Average
Posts: 10
Joined: Wed Oct 18, 2023 4:41 pm

Re: Can I bring the palyers ship to a full stop, in a script?

Post by Gwydion »

And - since you seem to understand this sort of stuff, Library.oxp is jam-packed with goodies for people writing missions.
Ah, thanks for the pointer to library.oxp I have as it install as it was needed by some OXP's I but never looked inside. Something to do tomorrow instead of dusting and vacuuming yay!

I tend to read a lot and there is a lot of documentation for Oolite, before you even get to the forums :D I've been trawling through a lot of OXP's by or supported by phkb Norby and Thargoid. Mainly as they have created missions I've completed or OXP's that are generating random ships and using mission screens. Don't get me wrong there have been many others but I like the way they write code. It's the same style as I was brought up with and I'm too old to change my style now.

Thanks again, Choimondely.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Can I bring the palyers ship to a full stop, in a script?

Post by Switeck »

In the OXZ called:
oolite.oxp.Thargoid.RetroRockets.oxz

Inside it, in its retroRockets.js file, on line 38.
There seems to be a line you're interested in:

player.ship.velocity = player.ship.velocity.subtract(player.ship.vectorForward.multiply(player.ship.maxSpeed*3));

Stands to reason if that value can be changed in that way, it can also be set to 0, like so:

player.ship.velocity = 0;

For even more cleverness, you could save the velocity into a temporary variable before changing it and reinstate that same velocity after the mission screen is done being displayed.

var a = player.ship.velocity;
player.ship.velocity = 0;

(sometime later...)

player.ship.velocity = a;

(I'm not sure this will all work, but hopefully this helps!)

[...In hindsight, player.ship.velocity is probably a vector array of sorts, so setting it to a simple 0 may not work!]
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Can I bring the palyers ship to a full stop, in a script?

Post by phkb »

You can do it a couple of ways.

Code: Select all

player.ship.maxSpeed = 0;
will bring the player ship to an immediate stop. You'll need to make a note of what the maxSpeed was beforehand, though, because you'll need to change it back again, otherwise the player won't be able to move.
You can also do this:

Code: Select all

player.ship.thrust = 0;
player.ship.velocity = [0,0,0];
Again, make a note of what the values were beforehand, so you can set them back again when you're ready.

It's also worth noting, that while mission screens are now permitted during flight (in Oolite 1.91), you can't lock out the player. That is, you can't use allowInterrupt: false on your mission screen. If you want to present a choice to the player, they *will* be able to skip the choice, press F1 and get back to flying.
Gwydion
Average
Average
Posts: 10
Joined: Wed Oct 18, 2023 4:41 pm

Re: Can I bring the palyers ship to a full stop, in a script?

Post by Gwydion »

Thank you for the replies and answers, I can now stop the ship when the mission screen is displayed and get going again when it goes away. (I think I was having a Friday afternoon after coming back from the pub, moment).
It's also worth noting, that while mission screens are now permitted during flight (in Oolite 1.91), you can't lock out the player. That is, you can't use allowInterrupt: false on your mission screen. If you want to present a choice to the player, they *will* be able to skip the choice, press F1 and get back to flying.
That will not be a problem as the message screen only has an "OK" option.
[...In hindsight, player.ship.velocity is probably a vector array of sorts, so setting it to a simple 0 may not work!]
Thanks for the warning, I found that Thargoid was using something along the lines of:

ps.velocity = ps.velocity.subtract(ps.vectorForward.multiply(maxspeed * 3));

This changes the forward vector to a new value and keeps the vector valid.

Thanks for all the help, and I hope every one had a good mid winter break.
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Can I bring the players ship to a full stop, in a script?

Post by Cholmondely »

Gwydion wrote: Tue Dec 26, 2023 10:58 am
... I hope every one had a good mid winter break.
How was yours?
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Post Reply