Scripters cove

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

Moderators: winston, another_commander

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

Personally I would use

Code: Select all

if(this.ship.missiles && ((this.ship.missiles.length / 2) === Math.floor(this.ship.missiles.length / 2))
   {missile.position.x = missile.position.x - 20;}
else
   {missile.position.x = missile.position.x + 20;}
or something similar (untested code above). But along those lines yes.

One thing to remember if you're looking at positioning them to a specific point on the ship is that the position on the ship is local (the origin is the centre of the ship, or wherever you put it on the model) and for the launched missile it will be universal (the origin is the witchpoint). You may need to do a "local to global" conversion, such as the one in the griff sub-ent cobra script.

But in the above case that won't matter as you're just moving the missile relative to its current position. I just include the comment for completeness.[/color]
User avatar
Rorschachhamster
---- E L I T E ----
---- E L I T E ----
Posts: 274
Joined: Sun Aug 05, 2012 11:46 pm
Contact:

Re: Scripters cove

Post by Rorschachhamster »

Thank you, and someday I will tackle this beast that is called JS. But as this will involve quite some learning, wich my old brain isn't suited to, I just post the "standard" version with just the config .plist files to define it.

Here you can find the amphisbaena

EDIT: renamed it, because there is already a copperhead...
Last edited by Rorschachhamster on Sun Nov 04, 2012 11:12 am, edited 1 time in total.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post by Eric Walch »

or

Code: Select all

if(this.ship.missiles && (this.ship.missiles.length & 0x01))
   {missile.position.x = missile.position.x - 20;}
else
   {missile.position.x = missile.position.x + 20;}
Just do a logical AND at bit level to check the oven/odd bit :D

The missile position calculation above is wrong though. You need to change it relative to the ship. e.g. like this:

Code: Select all

var missilePosition;

if(this.ship.missiles && (this.ship.missiles.length & 0x01))
   {missilePosition = new Vector3D(x1,y1,z1);}
else
   {missilePosition = new Vector3D(x2,y2,z2);}

missile.position = this.ship.position.add(missilePosition.rotateBy(this.ship.orientation));
In this, the x,y,z are the local positions in ship coordinates. That the last line converts it to system positions.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2479
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Scripters cove

Post by Griff »

Is the example code for has_shipyard on the wiki correct? - http://wiki.alioth.net/index.php/Shipda ... s_shipyard
the given example:

Code: Select all

"has_shipyard" = (
                  systemGovernment_number morethan 3,
                  systemEconomy_number lessthan 4
                 )
just game me syntax errors, after a bit of trial and error Oolite seemed happy if i wrote it out as

Code: Select all

"has_shipyard" = (
                 "systemGovernment_number morethan 3", 
                 "systemEconomy_number lessthan 4"
                    );
is that the proper way to do it? if so i can edit the wiki page if you like
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post by Wildeblood »

Griff wrote:
Is the example code for has_shipyard on the wiki correct?
No, it wasn't.
Griff wrote:
Oolite seemed happy if i wrote it out as
Code:
"has_shipyard" = (
"systemGovernment_number morethan 3",
"systemEconomy_number lessthan 4"
);

is that the proper way to do it?
Yes. I've just changed the wiki.
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 »

I suppose this having been a feature for over 6 years, I can't just remove it, but I do wonder why anyone would want to give complex conditions to the has_shipyard key.

Does anyone actually use this? (If not, it can go. If so, it needs a non-legacy equivalent adding!)
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: Scripters cove

Post by Zieman »

Is there a way (in 1.76.x), and if there isn't, could it be added (to 1.77.x): to change player-ship's cargo space on the fly by script?

Why I'm asking?

Because I have a ship design that has two subentities that look very much like cargo spaces. So, to add some extra flavour to this ship, I'd like to make it frangible, and script it so that if one of those aforementioned subents gets shot off, you lose 40% of your cargo capacity. And if the other one gets also shot off, you lose another 40% of the original cargo capacity. That "40%" should IMHO of course be any number of TC one can define in the script.

A bonus feature would be some kind of safeguard against Gold/Platinum/Gem-stones being lost this way (unless cargo space gets reduced to zero or an amount small enough that it becomes smaller than Gold/Platinum amount in 1000s of kgs). Maybe Gem-stones would always be safe (takes several top-tier contracts to even get many kgs of them, let alone 1000s) and Gold & Platinum up to ~100 kg combined would alway be safe too.

AFAIK now you can have this happen once, by scripting the subent's destruction to trigger cargo bay extension failure. And of course I had to design a ship with two such subentities :roll: .
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
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 »

1.76, no. 1.77 it will be possible (with the functionality already in 1.77).

Set the ship's original cargo space to the full amount it can carry with both subents attached.
Define two (invisible and undamageable) entries in equipment.plist, each of which has a requires_cargo_space equal to the size of the subent it represents. When the subent is destroyed, remove cargo by script to make room, and install the equipment item. When the subent is repaired, remove the equipment item to free up the cargo space again.
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: Scripters cove

Post by Zieman »

Whoa, cool! :D

I'll postpone the release until 1.77 is released as test then.
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Scripters cove

Post by Commander McLane »

Zieman wrote:
AFAIK now you can have this happen once, by scripting the subent's destruction to trigger cargo bay extension failure.
Yep, that's what's doable in 1.76 and prior already.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post by Wildeblood »

How do I scan worldScriptNames for particular scripts; what goes in place of my /* comment */ here? Can I do it immediately from startUp like this, or do I need a delay?

Code: Select all

this.startUp = function()
	{
	this.$checkForIncompatibleScripts();
	}

this.$checkForIncompatibleScripts = function()
	{
	/* Check worldScriptNames for similar scripts. */
	}
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Scripters cove

Post by Commander McLane »

cim wrote:
I suppose this having been a feature for over 6 years, I can't just remove it, but I do wonder why anyone would want to give complex conditions to the has_shipyard key.

Does anyone actually use this? (If not, it can go. If so, it needs a non-legacy equivalent adding!)
I don't know off the top of my head which OXPs use this, but yes, the possibility to make the availability of a shipyard in a station dependent on conditions was an explicit request at some time. Thus I guess that it's actually used somewhere.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Scripters cove

Post by Commander McLane »

Wildeblood wrote:
How do I scan worldScriptNames for particular scripts; what goes in place of my /* comment */ here? Can I do it immediately from startUp like this, or do I need a delay?
StartUp should be fine, and you just need to check for the existence of the script:

Code: Select all

this.startUp = function()
{
	this.$checkForIncompatibleScripts();
}

this.$checkForIncompatibleScripts = function()
{
	if(worldScripts["oolite-constrictor-hunt"])
	{
		/* your code here */
	}
}
Of course you have to know all possible culprits by name before in order to check for each one of them.

See Image here.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

And to clarify the original a little bit, worldScriptNames is just an array, so you'd scan through it or check it like any other array.

Specifically the simplest way is worldScriptNames.indexOf("<yourscriptnamehere>"). If that returns -1 then the script isn't loaded, and anything 0 or higher is the location of the script name in the array.

Either way will work. If you want to look for a specific function within the scripts, that can also be done by extending McLane's way. If you want an example look in the code for Planetary Compass.
User avatar
superbatprime
Dangerous
Dangerous
Posts: 120
Joined: Tue Oct 09, 2012 10:09 am
Location: Location, Location.

Re: Scripters cove

Post by superbatprime »

What is needed to get an equipment plist to randomly choose a word from a descriptions plist dictionary as the equipment's displayed name?

I want the name string in equipment plist to be a variable taken from descriptions plist.

I read Oolite will try to replace words with [square brackets], but I'm not having much luck with that.

atm it's like this.

Code: Select all

(
   (
      0,
      5000,
      "Equip Name: [serial_number]",
      "EQ_MY_EQUIP",
      "blah blah blah",
       {
          "available_to_all" = yes;
		  "portable_between_ships" = yes;
       }
    )
)
and my description plist is like this.

Code: Select all

{
  serial_number = ("two", "three", "four", "five", "six");
}
Obviously that's not working, I've tried various combos of [] inside and outside the name string quotation marks but no joy.
Last edited by superbatprime on Tue Nov 20, 2012 3:35 pm, edited 1 time in total.
So then I says to him, I says "naw dude, Oolite ain't no Space Opera... Oolite is Space Rock and Roll!"
Post Reply