Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Scripters cove

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

Moderators: winston, another_commander

User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: World scripts and shipdata

Post by jh145 »

cim wrote:
Okay, slight modification needed, then: ...
I looked it up and decided to go with:

Code: Select all

this._myCallbackFunction = function() {
  // ...
  this._score += 1;
}.bind(this)    // within the function, "this" is the worldscript
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Dynamic ship customisation

Post by jh145 »

I'm spawning random ships, but would like to get them alone, without escorts. More generally, I'd like to pick a random ship type, edit the attributes I don't like (e.g. ensure escorts=0), then spawn. Is this possible? I definitely want to make these customisations at runtime, not hard-coded into a shipdata file.

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

Re: Dynamic ship customisation

Post by cim »

jh145 wrote:
More generally, I'd like to pick a random ship type, edit the attributes I don't like (e.g. ensure escorts=0), then spawn. Is this possible?
No. What you can often do is spawn the ship, and then edit the attributes on the next line before anything is done with it (more so in the current nightly builds where a lot more of the ship attributes are writable, than in 1.80), but you can't - in effect - define shipdata.plist entries at run-time.

To remove escorts, look at ship.escortGroup, and ship.remove() all the members of that which aren't the original ship.
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Dynamic ship customisation

Post by jh145 »

cim wrote:
you can't - in effect - define shipdata.plist entries at run-time.
I can probably hack round it as you suggest but, still, I'm curious: does the code need to forbid runtime customisation before spawning, or is that just the way it happens to work today?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

jh145 wrote:
I can probably hack round it as you suggest but, still, I'm curious: does the code need to forbid runtime customisation before spawning, or is that just the way it happens to work today?
It would require a fair bit of reorganisation to make it possible, and both of the obvious ways it could be done would probably cause problems for other OXPs. Which properties are you wanting to edit?
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Dynamic ship customisation

Post by jh145 »

cim wrote:
It would require a fair bit of reorganisation to make it possible, and both of the obvious ways it could be done would probably cause problems for other OXPs. Which properties are you wanting to edit?
I've no burning desire to change any one particular thing; I just felt uncomfortable that the current design is open to race conditions whereby escorts spawn, or an AI activates, or whatever, before I've had a chance to get in there and "correct" my newly-spawned ship. Before being pointed at the docs, I suppose I'd assumed I'd be able to do something like

Code: Select all

myship = new Ship("[asp]");
myship.setScript("myai.js");
myship.setScript("myscript.js");
myship.someparam = 4.669201609;
System.addShips(myship,1);
But, like I said, this is just mild newbie discomfort. I'll get used to it :D
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripters cove

Post by Smivs »

Is there a way to stop a rotating sub-entity from rotating via script?
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Smivs wrote:
Is there a way to stop a rotating sub-entity from rotating via script?
Not a nice one - using a frame callback to reset its orientation is probably about all that you can do, and that's not perfect. I'll add it to the list for 1.82.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripters cove

Post by Smivs »

Ah, OK. No worries. Good to know it's on the to-do list - thanks.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

I want to limit docking and to achieve that have

Code: Select all

requires_docking_clearance = yes;
in shipdata.plist and a ship script attached to a station with this:

Code: Select all

this.stationReceivedDockingRequest = function(whom) {
	if (whom === player.ship) {
		this.ship.subEntities[2].allowsDocking = false;
		this.ship.subEntities[2].disallowedDockingCollides = true;
	}
}
All is working docking wise ok, but the station sends a standard message saying for example "Due to an emergency your docking clearance has been revoked. Please clear the station approach immediately". Is there some simple way to suppress that message in this particular case to communicate with something more suitable.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Probably the better approach in this case is a script on the dock subentity (or subentities) using acceptDockingRequestFrom.

Code: Select all

this.acceptDockingRequestFrom = function(ship)
{
     return !ship.isPlayer;
}
That way the player being disallowed to dock won't kick everyone else out of the queue too. It should also give a better message.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

cim wrote:
Probably the better approach in this case is a script on the dock subentity (or subentities) using acceptDockingRequestFrom.

Code: Select all

this.acceptDockingRequestFrom = function(ship)
{
     return !ship.isPlayer;
}
That way the player being disallowed to dock won't kick everyone else out of the queue too. It should also give a better message.
Thanks. Better messages indeed. However, if I request docking while there is a queue, I get a note that I'm in a queue and after the queue resolves nothing seems to happen. I added logging to the acceptDockingRequestFrom of the dock and it appears that the game is in a loop and keeps on hammering the function 20 times in a second. After canceling the request and requesting again the game correctly denies docking.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

You'll probably run across a few bugs like that as you start using those functions, but that one will be fixed in tonight's build. It wasn't handling the case where no docks are eligible for docking properly.
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: Scripters cove

Post by Diziet Sma »

Trying to implement this:
Disembodied wrote:
It might be useful to consider whether the game could benefit from some sort of "incoming message" sound effect, to alert players to the fact.
I've run into a wee snag.. looking through the Oolite Javascript Reference (for both Player and Ship) I don't see any easy way to detect when commsMessage or consoleMessage is called by the game or an OXP script.

Can anyone suggest a method for doing so, or am I going to have to make a feature request?
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Diziet Sma wrote:
I've run into a wee snag.. looking through the Oolite Javascript Reference (for both Player and Ship) I don't see any easy way to detect when commsMessage or consoleMessage is called by the game or an OXP script.

Can anyone suggest a method for doing so, or am I going to have to make a feature request?
For now, you want the commsMessageReceived ship script event (which is as usual also a world script event for messages received by the player ship)

If this turns out to be a good idea (and it sounds like it is) it should probably get a customsounds.plist entry and a default sound in the core game.
Post Reply