Scripters cove

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

Moderators: winston, another_commander

User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Old Murgh wrote: Sat Jun 04, 2022 7:00 am
Thank you :D
phkb wrote: Sat Jun 04, 2022 3:45 am
The only things you'd need to define is the rules which cover what systems to put your missionaries in (if there are any), and what the role will be of the ships.
Well, for starters I wanted to have the role as common as trader or pirate, galaxy-wide (without "stealing" from the trader quota). They might not last long in an anarchy but they are crazy enough to try their luck anywhere. –I don't suppose there is any common seed word that justifies an increase of spiritual activity. For now, if the system description contains the word "is", then I'd like there to be a 90% chance of spawning a* missionary.

*Does asking the engine to randomly choose between 0, 1 or 2 spawns factor into this?
Spawning the role trader will add any ship with this role, not only yours. You will need a unique role. If you like the missionaries to have the role trader, you still could change the primary role later in this.shipSpawned. For a 90% chance in any system, you can use Math.floor(Math.random() > 0.10, or you can utilize the function I mentioned earlier with this.$getRndInteger(1, 10) > 1. :wink:
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

montana05 wrote: Sat Jun 04, 2022 7:25 am
Spawning the role trader will add any ship with this role, not only yours. You will need a unique role. If you like the missionaries to have the role trader, you still could change the primary role later in this.shipSpawned. For a 90% chance in any system, you can use Math.floor(Math.random() > 0.10, or you can utilize the function I mentioned earlier with this.$getRndInteger(1, 10) > 1. :wink:
Yes, I was meaning to explain that I want the game/this script to request the unique role "missionary", and I would like to avoid use of the role "trader" (unlike the other two missionaries.oxps).

So, Math.floor(Math.random() > 0.10 or this.$getRndInteger(1, 10) > 1. are both .js equivalents of the old "d100_number greater than 10" ? Would it then merit its own line in the beginning or get squeezed into some appropriate spot?
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Old Murgh wrote: Sat Jun 04, 2022 7:57 am
montana05 wrote: Sat Jun 04, 2022 7:25 am
Spawning the role trader will add any ship with this role, not only yours. You will need a unique role. If you like the missionaries to have the role trader, you still could change the primary role later in this.shipSpawned. For a 90% chance in any system, you can use Math.floor(Math.random() > 0.10, or you can utilize the function I mentioned earlier with this.$getRndInteger(1, 10) > 1. :wink:
Yes, I was meaning to explain that I want the game/this script to request the unique role "missionary", and I would like to avoid use of the role "trader" (unlike the other two missionaries.oxps).

So, Math.floor(Math.random() > 0.10 or this.$getRndInteger(1, 10) > 1. are both .js equivalents of the old "d100_number greater than 10" ? Would it then merit its own line in the beginning or get squeezed into some appropriate spot?
To take phkb's example it would look like this:

Code: Select all

this.systemWillPopulate = function ()
{
	let dice = this.$getRndInteger(1, 3);  // random number between 1 and 3
	
	if (Math.floor(Math.random() > 0.10)  // 90% chance
	 {
		system.setPopulator("missionaries_ship", 
		{
			callback: function(pos)
			{			
				system.addShips(missionaries, dice, pos); // spawns 1 - 3 ships with role missionaries
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}
This would add with a chance of 90% between 1 - 3 missionary ships to the system. Please don't forget to add the actual getRndInteger functions as well, its not core-game.
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

montana05 wrote: Sat Jun 04, 2022 8:44 am
To take phkb's example it would look like this:

Code: Select all

this.systemWillPopulate = function ()
{
	let dice = this.$getRndInteger(1, 3);  // random number between 1 and 3
	
	if (Math.floor(Math.random() > 0.10)  // 90% chance
	 {
		system.setPopulator("missionaries_ship", 
		{
			callback: function(pos)
			{			
				system.addShips(missionaries, dice, pos); // spawns 1 - 3 ships with role missionaries
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}
This would add with a chance of 90% between 1 - 3 missionary ships to the system.
Thankyou! :D
montana05 wrote: Sat Jun 04, 2022 8:44 am
Please don't forget to add the actual getRndInteger functions as well, its not core-game.
:cry: I was on a high there.
So first guess, getRndIntegerfunctions is another (–"as well"..) different .js script file that should be found in the Scripts folder? I was clinging to the hope that this would be a simple copy/paste to the working format that is established in the hOopy Casino.OXP.

You see the gap in programming comprehension clearly illustrated here. My experience is essentially limited to typing in some BASIC bouncing ball on the C64, mid80s. That I was able to play with Giles' XML Legacy setup at all is quite the miracle.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Old Murgh wrote: Sat Jun 04, 2022 9:19 am
:cry: I was on a high there.
So first guess, getRndIntegerfunctions is another (–"as well"..) different .js script file that should be found in the Scripts folder? I was clinging to the hope that this would be a simple copy/paste to the working format that is established in the hOopy Casino.OXP.

You see the gap in programming comprehension clearly illustrated here. My experience is essentially limited to typing in some BASIC bouncing ball on the C64, mid80s. That I was able to play with Giles' XML Legacy setup at all is quite the miracle.
It is actually just copy & paste:

Code: Select all

this.systemWillPopulate = function ()
{
	let dice = this.$getRndInteger(1, 3);  // random number between 1 and 3
	
	if (Math.floor(Math.random() > 0.10)  // 90% chance
	 {
		system.setPopulator("missionaries_ship", 
		{
			callback: function(pos)
			{			
				system.addShips(missionaries, dice, pos); // spawns 1 - 3 ships with role missionaries
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}

this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
Same world-script, just one function more. :wink:
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

montana05 wrote: Sat Jun 04, 2022 9:35 am
It is actually just copy & paste:
Actually, I don't think the code sample you've provided will work. The value for "dice" is calculated in the systemWillPopulate function. However, all the functions that are sent to the populator run independently of the originating worldScript. So "dice" won't be present in that context and will have no value when the populator actually runs.

To keep the dice roll function as is, you'd need to do this:

Code: Select all

this.systemWillPopulate = function ()
{
	if (Math.floor(Math.random() > 0.10)  // 90% chance
	 {
		system.setPopulator("missionaries_ship", 
		{
			callback: function(pos)
			{			
				system.addShips("missionaries", worldScripts["myWorldScriptName"].$getRndInteger(1, 3), pos); // spawns 1 - 3 ships with role missionaries
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}

this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

phkb wrote: Sat Jun 04, 2022 9:57 am
montana05 wrote: Sat Jun 04, 2022 9:35 am
It is actually just copy & paste:
Actually, I don't think the code sample you've provided will work. The value for "dice" is calculated in the systemWillPopulate function. However, all the functions that are sent to the populator run independently of the originating worldScript. So "dice" won't be present in that context and will have no value when the populator actually runs.

To keep the dice roll function as is, you'd need to do this:

Code: Select all

this.systemWillPopulate = function ()
{
	if (Math.floor(Math.random() > 0.10)  // 90% chance
	 {
		system.setPopulator("missionaries_ship", 
		{
			callback: function(pos)
			{			
				system.addShips("missionaries", worldScripts["myWorldScriptName"].$getRndInteger(1, 3), pos); // spawns 1 - 3 ships with role missionaries
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}

this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
You are correct, my mistake. I mixed world- and ship-script. :oops:
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

montana05 wrote: Sat Jun 04, 2022 9:35 am
It is actually just copy & paste:
..
Same world-script, just one function more. :wink:
phkb wrote: Sat Jun 04, 2022 9:57 am
Actually..
Again, thank you both. Immense educational value for me, this has.
Very excited to see what will happen when I get to try in a few hours.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

montana05 wrote: Sat Jun 04, 2022 9:35 am
It is actually just copy & paste:
..
Same world-script, just one function more. :wink:
phkb wrote: Sat Jun 04, 2022 9:57 am
Actually..
So I'm into it, trying real hard.
This is the file missionary_populator.js in its entirety:

Code: Select all

"use strict";

this.name = "missionary_populator";
this.author = "Paul Wilkins, updated by Eric Walch, spara, modified by phkb, montana";
this.copyright = "(C) 2009 Paul Wilkins";
this.license     = "CC BY-NC-SA 3.0"; 

//add missionary to system
this.systemWillPopulate = function ()
{
	if (Math.floor(Math.random() > 0.10)  // 90% chance
	 {
		system.setPopulator("missionary_ship", 
		{
			callback: function(pos)
			{			
				system.addShips("missionary", worldScripts["missionary_populator.js"].$getRndInteger(1, 3), pos); // spawns 1 - 3 ships with role missionary
			}.bind(this),
			location: "LANE_WP",
			locationSeed: 0 
			// 0 = completely random position on the lane, otherwise use a specific seed number to have them in the same position each time
		});
	}
}

this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
There is also a world-scripts.plist file in the Config that names only this file.. I've tried with a few versions of where the code you gave me had "myWorldScriptName", I assumed I needed to change to the used filename, along with the role to accommodate my shipdata.

But the log gives this response:

Code: Select all

16:02:52.164 [script.javaScript.exception.parenAfterCond]: ***** JavaScript exception (missionary_populator.js.anon-script): SyntaxError: missing ) after condition
16:02:52.164 [script.javaScript.load.failed]: ***** Error loading JavaScript script /Users/murgh/Library/Application Support/Oolite/AddOns/IronAssMissionaries_b1.oxp/Scripts/missionary_populator.js -- compilation failed
16:02:52.164 [script.load.notFound]: ***** ERROR: Could not find script file missionary_populator.js..
Did I manage to screw up a cut&paste or do you see a parenthesis-shaped hole, or is it something else?
Sorry to be so blank about this.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander »

It looks like the if (Math [...] statement has mismatched parentheses. A closing one seems to be missing.
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1166
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Scripters cove

Post by montana05 »

Old Murgh wrote: Sat Jun 04, 2022 2:24 pm
Did I manage to screw up a cut&paste or do you see a parenthesis-shaped hole, or is it something else?
You didn't screw up a copy & paste, I did. :roll:

Code: Select all

if (Math.floor(Math.random() * 10) > 0)  // returns a random integer from 0 to 9 so there is a 90% chance
Please try this and my apologies for causing you a headache.
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Old Murgh wrote: Sat Jun 04, 2022 2:24 pm
I assumed I needed to change to the used filename,
Old Murgh wrote: Sat Jun 04, 2022 2:24 pm

Code: Select all

this.name = "missionary_populator";
What you need to put in is “missionary_populator” - that’s the name of the worldscript, not the filename.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Scripters cove

Post by Old Murgh »

phkb wrote: Sat Jun 04, 2022 3:31 pm
What you need to put in is “missionary_populator” - that’s the name of the worldscript, not the filename.
Thank you.

I appear to be good to go. These guys are popping up at last. Triumph. I am very grateful for all the support.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
User avatar
szaumix
Deadly
Deadly
Posts: 171
Joined: Sun Apr 24, 2022 4:23 am

Re: Scripters cove

Post by szaumix »

montana05 wrote: Sat Jun 04, 2022 12:23 am
You can use accuracy in js: https://wiki.alioth.net/index.php/Oolit ... p#accuracy

If you use a random number with a minimum and a maximum function like:

Code: Select all

this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
you should get a result pretty close to what you desire.
Thanks
[deleted]
Last edited by szaumix on Thu Dec 14, 2023 3:57 am, edited 1 time in total.
User avatar
szaumix
Deadly
Deadly
Posts: 171
Joined: Sun Apr 24, 2022 4:23 am

Re: Scripters cove

Post by szaumix »

OK so another question for those who know.
Can anyone briefly expound on auto_weapons and auto_ai in the shipdata plist? What kinds of overrides -- specifically -- can I expect with them flagged as true? I'm in the middle of a shipdata_overrides.plist rebalance of core ship specs and, more significantly, their roles. And I just want to make sure of how exact I should be.

Actually a better question might be, what is the benefit of auto_weapons and auto_ai flagged as true?
Thanks!
Post Reply