Scripters cove

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

Moderators: another_commander, winston

User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

cim wrote:
Is there a way to set a ship's lasers from script?................................................................but I thought I'd better ask before I started massively expanding shipdata.plist.
Unfortunately not, you can check for what lasers are installed from script but not change them. Your only choice is 'like_ship'ing, and it sounds like your setting yourself a real PITA task. If you were just to include the core ships it is worth doing two sets (one for Griff's and one for the standard model names), with a very very low probablity attached to the role for the standard model names. If you do that players with Griff's installed will see Griff's ships, players without, the standard model or the retextured version if say Smiv's or Neolite's are installed.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2275
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post by Wildeblood »

Capt. Murphy wrote:
I could well be missing something because I have not looked into this at all closely, but...
Yes, I think we both missed something: that you were replying to something I posted months ago. As an answer to the literal request I made back then, you are correct. I replied from the context of my current concerns. Please accept my apology if my reply seemed ungrateful, dismissive or just plain odd.
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 »

To avoid counting beyond the 2048 systems in Galaxy Charts 1-8, you could also add this simple check:

Code: Select all

if(galaxyNumber >7 || galaxyNumber <0) {
// DIRE warnings about being off-the-charts.
	player.commsMessage("Outside known space! No matching Star Charts found!",6);
}
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

Wildeblood wrote:
Capt. Murphy wrote:
I could well be missing something because I have not looked into this at all closely, but...
Yes, I think we both missed something: that you were replying to something I posted months ago. As an answer to the literal request I made back then, you are correct. I replied from the context of my current concerns. Please accept my apology if my reply seemed ungrateful, dismissive or just plain odd.
No worries - what I'm actually doing is an achievements/mile-stones module for explorers' club, and I don't want to spam alternative Ooniverse users with nonsense mile-stones (Oresrati, Great Rift etc.) - they get a 'Wow! Far-out! You are exploring a parallel Ooniverse......Boldly go......" message (or something along those lines :wink: ) instead.

Switeck -I'll add that to my Switch as a default if galaxyNumber is beyond 7, and as a check at start-up.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

Wildeblood wrote:
I want to create a group of asteroids which behave as one object when the player is trying to target them with the ident computer. One will be the core, and there will be several others around it. If the player targets one of the outlying ones, target should be immediately re-directed to the core one, so the player can't get a target lock on the outliers. Suggestions, please?
With apologies if this got answered and I missed it, but couldn't see any reply. It depends what you mean by target - if you mean the missile/ident lock, then that can be set simply by scripting (player.ship.target is read/write) all you need to do is check when the player targets something (there are worldscript events for that) and if it's the appropriate entity (the satellite asteroids) then set the target to the main entity.

That does of course require that they are both on the scanner together, as if you try and set the target to something off-scanner then you'll of course lose lock immediately. If you want a guide to this kind of thing, look at my target autolock OXP.
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 »

Capt. Murphy wrote:
Unfortunately not, you can check for what lasers are installed from script but not change them. Your only choice is 'like_ship'ing, and it sounds like your setting yourself a real PITA task.
Thought so - thanks for confirming. It's not that bad, as it goes - I can do a bit of preprocessing to generate most of the shipdata.plist automatically since the changes from the base ship spec will be minimal - so all I really need to do is keep a list of hunters.
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

Wildeblood wrote:
Capt. Murphy wrote:
I could well be missing something because I have not looked into this at all closely, but...
Yes, I think we both missed something: that you were replying to something I posted months ago. As an answer to the literal request I made back then, you are correct. I replied from the context of my current concerns. Please accept my apology if my reply seemed ungrateful, dismissive or just plain odd.
Well, you were quite right to express concerns about checking position of systemID '0'. Some testing with galaxy_seeds close to the original reveals that it can be in the same place very often. However same testing shows that systemID 255 is in a wildly different position. I've edited the code snippet to reflect the better test.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2275
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post by Wildeblood »

Capt. Murphy wrote:
Well, you were quite right to express concerns about checking position of systemID '0'. Some testing with galaxy_seeds close to the original reveals that it can be in the same place very often. However same testing shows that systemID 255 is in a wildly different position. I've edited the code snippet to reflect the better test.
It seems to me you're just making work for yourself. If you're just after a coding challenge, I have a long list of OXP ideas that are beyond my ability to implement yet (all brilliant ideas, obviously). I could send you a list and you could just pick out any that appeal to you.

Put my mind at ease by telling me exactly why you feel the need to verify you're in the traditional ooniverse (hereinafter referred to as 'elite-0')? In my view, you never need such a test for any mission intended for elite-0, because it's not something the player can accidentally exit from. A player knows if they're using an alternative ooniverse, and if they are, they know it won't start at Lave and end at Oresrati. (By way of experiment last night, I tossed in some 'random' numbers, hopped around the eight to see if they looked interesting, and ended up on planet "User". Spooky. True.) OTOH, you do need such a test for any mission intended for any other ooniverse, because sure enough someone - not understanding what it is - will expect it to work in elite-0 and complain when it doesn't.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: Scripters cove

Post by Kaks »

While on the subject of alternate ooniverses, a shorter version of Capt. Murphy's test could be:

Code: Select all

this.alternateOoniverse = function(){
  var testCoords=[[4.8,40.6,0],[9.6,30.4,0],[31.2,42.4,0],[62.4,34.2,0],[51.2,28.8,0],[86.4,27.6,0],[70.8,4.6,0],[90.8,39.8,0]];
  if (galaxyNumber < 0 || galaxyNumber > 7) return true;
  return (System.infoForSystem(galaxyNumber, 255).coordinates.distanceTo(testCoords[galaxyNumber]) > 0.00001);
}
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

That's quite a lot shorter :wink: - thanks Kaks.

Wildeblood - not particularly after coding challenges but if there is anything you'd like me to have a look at either to advise or to consider putting some script together then shout. I won't promise anything as time is often not on my side, but always happy to try and help.

I've done this for a particular reason for the next version of Explorers' Club. I probably wouldn't have done it except for the knowledge that at least one likely user (who could that be :wink: ) does like to play in alternative Ooniverses. Having found a (with Kak's optimisation) relatively small function that should reliably tell an OXP if it's in the standard Ooniverse or not, I thought it worth sharing as some other scripters may feel the need to do the same thing.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

Is there a better way than this to determine if one array is a subset or equal to another array (ordering doesn't matter)?

I also tried an esoteric combination of .filter with an .indexOf based function in the callback but suffered a failure to get the syntax right or get my head round why it was failing.

This works though.

this.isArray1_subsetOfArray2 = function (array1,array2)
{
if (!array1 || !array2)
{return false;}
if (array1.length > array2.length)
{return false;}
var tempArray = new Array;
var counter = 0;
for (counter = 0; counter < array1.length; counter++)
{
if (array2.indexOf(array1[counter]) !== -1)
{tempArray.push(array1[counter]);}
}
if (tempArray.length === array1.length)
{return true;}
else {return false;}
}
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: Scripters cove

Post by Kaks »

This should work:

Code: Select all

this.isArray1_subsetOfArray2 = function (array1,array2)
{
  if (!(typeof array1 == 'object' && array1 instanceof Array) || !(typeof array2 == 'object' && array2 instanceof Array) || array1.length > array2.length)
    {return false;}
  
  return  array1.length == array2.filter(function(value){return this.indexOf(value) >= 0},array1).length;
}
note: I tend to be 'a bit' paranoid about what parameters a function's been fed, but I'm not too fussed about my logical expression evaluations ("I remember the days === woud give you a syntax error")! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Scripters cove

Post by Svengali »

If you only want to see if elements in arr2 are in arr1 you could use .arrDiff(arr1,arr2) in CCL (order independent).
For a real subset order matters though.
User avatar
RyanHoots
---- E L I T E ----
---- E L I T E ----
Posts: 958
Joined: Fri May 20, 2011 8:10 pm
Location: Nowhere
Contact:

Re: Scripters cove

Post by RyanHoots »

I'm working on learning JavaScript, so I'm modifying some of the scripts that come with the game. I'm working on a Borg script, just for fun, but I need help. Here's what I have:

Code: Select all

this.shipDied = function ()
{
	this.ship.commsMessage(expandDescription("We are Borg. You will be assimilated. Resistance is futile."));
};
The problem is that with the above script, the Borg ship will tell you that you will be assimilated after the Borg ship dies. What do I replace this.shipDied with so that the borg ship sends the comm message as soon as the player encounters it?
Image
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: Scripters cove

Post by Kaks »

What about:

Code: Select all

this.shipTargetAcquired = this.shipBeingAttacked = function ()
{
   this.ship.commsMessage("We are Borg. You will be assimilated. Resistance is futile.");
};
Every time the borg ship targets anything, or every time they get shot with a laser they'll say the same sentence.

The command expandDescription wasn't doing anything useful - there was nothing to expand inside your sentence. However, it's a very useful command if you want them to be slightly less boring!

You'll need some alternative phrases inside a descriptions.plist first. If you have:

Code: Select all

RH-borg-banter = ("We are Borg.", "Resistance is futile.", "You will be assimilated.", "We'll add your distinctivness to our own", "Resistance is futile, you will be assimilated.", "We are Borg, resistance is futile.");
then every time you do:

Code: Select all

this.ship.commsMessage(expandDescription("[RH-borg-banter]"));
you'll get a different random borg phrase, picked from the ones you wrote in the descriptions.plist above.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Post Reply