Scripters cove

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

Moderators: another_commander, winston

Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

Massively Locked wrote: Tue Dec 06, 2022 7:58 pm
Alnivel wrote: Tue Dec 06, 2022 1:59 pm
It seems like it can only be fully relied upon for managed OXPs…
Do you mean that it doesn't work for OXPs in the AddOns dir? I have my Station Bulletins OXP in AddOns, and it's picked up. I also have another OXP in there which is deliberately disabled and doesn't show up.
It will work, as Switeck noted, as long as the filename remains the same as in the code: if I check for the presence of the substring "Whatever v1.0.oxp", but the file with the OXP will be named something else, for example "whatever v1.2 (1).oxp", it will not notice it, even though it is a valid name and the OXP will be loaded.
However, we probably can just ask the end user to leave the OXP name recognizable enough for the code if they change it, and now it's their problem whether they notice it or not.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: Scripters cove

Post by Reval »

Does anyone happen to know the syntax for saving and loading an array?

(tried the obvious

Code: Select all

missionVariables.someArray = this.$someArray;

Code: Select all

this.$someArray = missionVariables.someArray;
but no joy of course.)
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

Reval wrote: Fri Dec 16, 2022 8:40 am
Does anyone happen to know the syntax for saving and loading an array?

(tried the obvious

Code: Select all

missionVariables.someArray = this.$someArray;

Code: Select all

this.$someArray = missionVariables.someArray;
but no joy of course.)
The missionVariables can only store numbers and strings, so to store an array or object, it need to be converted to a string on write and back on read. The simplest way to do this would be to use JSON:

Code: Select all

missionVariables.someArray = JSON.stringify(this.$someArray); // to save

Code: Select all

this.$someArray = JSON.parse(missionVariables.someArray); // to load - if there is no such mission variable, this.$someArray will be null
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: Scripters cove

Post by Reval »

That works wonderfully - thank you!
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2639
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear »

Trying to achieve a very simple effect but not sure how to go about it.

Upon exiting a wormhole/entering a system, I'd like the player ship to have an initial heading approximating that of the local star/sun instead of that of the main planet.

A little bit of randomisation thrown in so that it's always somewhere in the vicinity of rather than ever directly aimed at the star.
The the player would then both have to use the compass to target the planet and also get some sense of the system they'd just arrived in.

There's performFaceDestination but I want the player ship to be aligned immediately upon arrival, just like they currently are with regards to the planet.
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

Redspear wrote: Sat Jun 03, 2023 11:59 pm
Trying to achieve a very simple effect but not sure how to go about it.

Upon exiting a wormhole/entering a system, I'd like the player ship to have an initial heading approximating that of the local star/sun instead of that of the main planet.

A little bit of randomisation thrown in so that it's always somewhere in the vicinity of rather than ever directly aimed at the star.
The the player would then both have to use the compass to target the planet and also get some sense of the system they'd just arrived in.

There's performFaceDestination but I want the player ship to be aligned immediately upon arrival, just like they currently are with regards to the planet.
You can directly set the player's ship orientation:

Code: Select all

this.shipExitedWitchspace = function () {
    if (!system.sun)
        return;

    var rotationToSun = system.sun.position.direction().rotationTo([0, 0, 1]);

    // Rotation to the main planet from witchpoint is the identity quaternion (no rotation)
    // But the player ship has some random initial rotation
    // By multiplication we add this rotation to the rotation to the star
    var  ps = player.ship;
    ps.orientation = ps.orientation.multiply(rotationToSun);
};
If you want a more customization, you can add some randomisation manually:

Code: Select all

this.shipExitedWitchspace = function () {
    if (!system.sun)
        return;

    var rotationToSun = system.sun.position.direction().rotationTo([0, 0, 1]);

    var maxDeviationAngle = 1; // in radians, doubled

    rotationToSun = rotationToSun.rotateX((Math.random() - 0.5) * maxDeviationAngle);
    rotationToSun = rotationToSun.rotateY((Math.random() - 0.5) * maxDeviationAngle);

    player.ship.orientation = rotationToSun;
};
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2639
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear »

Alnivel wrote: Sun Jun 04, 2023 10:38 am
You can directly set the player's ship orientation:
Ah, this is yet another case where I just don't know enough of the basics...

I'll give that a try. Thanks Alnivel :)
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2639
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear »

The above works great but changing

this.shipExitedWitchspace

to

this.shipWillExitWitchspace

avoids the delay in view position changing upon entering the system.
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

Is there a way to distinguish if a player is entering a witchspace by their own hyperdrive or through someone else's wormhole? (Preferably on a ship's "playerWillEnterWitchspace" event)
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2639
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear »

Alnivel wrote: Mon Jun 12, 2023 10:55 pm
Is there a way to distinguish if a player is entering a witchspace by their own hyperdrive or through someone else's wormhole? (Preferably on a ship's "playerWillEnterWitchspace" event)
You could try adding a non-visible piece of equipment if playerStartedJumpCountdown, testing for its presence on shipWillEnterWitchspace then doing whatever you need to do, before removing when either shipWillExitWitchspace or playerCancelledJumpCountdown occurs.
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Scripters cove

Post by Alnivel »

Redspear wrote: Mon Jun 12, 2023 11:13 pm
Alnivel wrote: Mon Jun 12, 2023 10:55 pm
Is there a way to distinguish if a player is entering a witchspace by their own hyperdrive or through someone else's wormhole? (Preferably on a ship's "playerWillEnterWitchspace" event)
You could try adding a non-visible piece of equipment if playerStartedJumpCountdown, testing for its presence on shipWillEnterWitchspace then doing whatever you need to do, before removing when either shipWillExitWitchspace or playerCancelledJumpCountdown occurs.
It should work, but I'll change this solution a bit to use a world script variable instead of a piece of equipment.
Thank you!
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2639
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear »

Alnivel wrote: Mon Jun 12, 2023 11:51 pm
use a world script variable instead of a piece of equipment.
I need to learn how to do that :lol:
Alnivel wrote: Mon Jun 12, 2023 11:51 pm
Thank you!
You're very welcome. Nice to be able to return a favour :)
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2412
Joined: Mon May 31, 2010 11:11 pm

Re: Scripters cove

Post by Switeck »

Do like I do -- find an existing OXP that uses a worldscript and stuff it there, with bonus points if there's already a playerStartedJumpCountdown section in it. :P
User avatar
hiran
Theorethicist
Posts: 2056
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

Switeck wrote: Tue Jun 13, 2023 6:33 pm
Do like I do -- find an existing OXP that uses a worldscript and stuff it there, with bonus points if there's already a playerStartedJumpCountdown section in it. :P
The Oolite AddonScanner generates index pages for all expansion on the expansion manager. I think it also marks up scripts found in these expansions.

So finding a suitable OXP might just be a one line grep command.
Sunshine - Moonlight - Good Times - Oolite
Post Reply