Page 112 of 118

Re: Scripters cove

Posted: Wed Dec 07, 2022 9:11 am
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.

Re: Scripters cove

Posted: Fri Dec 16, 2022 8:40 am
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.)

Re: Scripters cove

Posted: Fri Dec 16, 2022 1:33 pm
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

Re: Scripters cove

Posted: Fri Dec 16, 2022 2:13 pm
by Reval
That works wonderfully - thank you!

Re: Scripters cove

Posted: Sat Jun 03, 2023 11:59 pm
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.

Re: Scripters cove

Posted: Sun Jun 04, 2023 10:38 am
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;
};

Re: Scripters cove

Posted: Sun Jun 04, 2023 10:51 am
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 :)

Re: Scripters cove

Posted: Sun Jun 04, 2023 1:14 pm
by Redspear
The above works great but changing

this.shipExitedWitchspace

to

this.shipWillExitWitchspace

avoids the delay in view position changing upon entering the system.

Re: Scripters cove

Posted: Mon Jun 12, 2023 10:55 pm
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)

Re: Scripters cove

Posted: Mon Jun 12, 2023 11:13 pm
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.

Re: Scripters cove

Posted: Mon Jun 12, 2023 11:51 pm
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!

Re: Scripters cove

Posted: Tue Jun 13, 2023 2:32 pm
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 :)

Re: Scripters cove

Posted: Tue Jun 13, 2023 6:33 pm
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

Re: Scripters cove

Posted: Tue Jun 13, 2023 7:23 pm
by Redspear
Top tip :lol:

Re: Scripters cove

Posted: Tue Jun 13, 2023 9:02 pm
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.