Page 54 of 118

Re: Scripters cove

Posted: Sun Nov 04, 2012 9:00 am
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]

Re: Scripters cove

Posted: Sun Nov 04, 2012 9:25 am
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...

Re: Scripters cove

Posted: Sun Nov 04, 2012 11:04 am
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.

Re: Scripters cove

Posted: Mon Nov 12, 2012 8:53 pm
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

Re: Scripters cove

Posted: Tue Nov 13, 2012 2:19 am
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.

Re: Scripters cove

Posted: Tue Nov 13, 2012 7:54 am
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!)

Re: Scripters cove

Posted: Tue Nov 13, 2012 11:44 am
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: .

Re: Scripters cove

Posted: Tue Nov 13, 2012 12:32 pm
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.

Re: Scripters cove

Posted: Tue Nov 13, 2012 12:51 pm
by Zieman
Whoa, cool! :D

I'll postpone the release until 1.77 is released as test then.

Re: Scripters cove

Posted: Tue Nov 13, 2012 2:20 pm
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.

Re: Scripters cove

Posted: Tue Nov 13, 2012 2:22 pm
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. */
	}

Re: Scripters cove

Posted: Tue Nov 13, 2012 2:24 pm
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.

Re: Scripters cove

Posted: Tue Nov 13, 2012 2:30 pm
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.

Re: Scripters cove

Posted: Tue Nov 13, 2012 5:42 pm
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.

Re: Scripters cove

Posted: Tue Nov 20, 2012 2:40 pm
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.