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.Old Murgh wrote: ↑Sat Jun 04, 2022 7:00 amThank youWell, 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?
Scripters cove
Moderators: winston, another_commander
- montana05
- ---- 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
Scars remind us where we've been. They don't have to dictate where we're going.
Re: Scripters cove
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).montana05 wrote: ↑Sat Jun 04, 2022 7:25 amSpawning 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.
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. Jonny Cuba made me do it!
- montana05
- ---- 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
To take phkb's example it would look like this:Old Murgh wrote: ↑Sat Jun 04, 2022 7:57 amYes, 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).montana05 wrote: ↑Sat Jun 04, 2022 7:25 amSpawning 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.
So,Math.floor(Math.random() > 0.10
orthis.$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?
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
});
}
}
Scars remind us where we've been. They don't have to dictate where we're going.
Re: Scripters cove
Thankyou!montana05 wrote: ↑Sat Jun 04, 2022 8:44 amTo take phkb's example it would look like this:
This would add with a chance of 90% between 1 - 3 missionary ships to the system.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 }); } }
I was on a high there.
So first guess,
getRndInteger
functions 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. Jonny Cuba made me do it!
- montana05
- ---- 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
It is actually just copy & paste:Old Murgh wrote: ↑Sat Jun 04, 2022 9:19 amI was on a high there.
So first guess,getRndInteger
functions 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.
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);
};
Scars remind us where we've been. They don't have to dictate where we're going.
- phkb
- 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
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);
};
- montana05
- ---- 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
You are correct, my mistake. I mixed world- and ship-script.phkb wrote: ↑Sat Jun 04, 2022 9:57 amActually, 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); };
Scars remind us where we've been. They don't have to dictate where we're going.
Re: Scripters cove
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. Jonny Cuba made me do it!
Re: Scripters cove
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);
};
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..
Sorry to be so blank about this.
I was young, I was naïve. Jonny Cuba made me do it!
-
- Quite Grand Sub-Admiral
- Posts: 6682
- Joined: Wed Feb 28, 2007 7:54 am
Re: Scripters cove
It looks like the if (Math [...] statement has mismatched parentheses. A closing one seems to be missing.
- montana05
- ---- 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
You didn't screw up a copy & paste, I did.
Code: Select all
if (Math.floor(Math.random() * 10) > 0) // returns a random integer from 0 to 9 so there is a 90% chance
Scars remind us where we've been. They don't have to dictate where we're going.
- phkb
- 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
What you need to put in is “missionary_populator” - that’s the name of the worldscript, not the filename.
Re: Scripters cove
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. Jonny Cuba made me do it!
Re: Scripters cove
Thanksmontana05 wrote: ↑Sat Jun 04, 2022 12:23 amYou 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:
you should get a result pretty close to what you desire.Code: Select all
this.$getRndInteger = function(min, max) { return (Math.floor(Math.random() * (max - min + 1) ) + min); };
[deleted]
Last edited by szaumix on Thu Dec 14, 2023 3:57 am, edited 1 time in total.
Re: Scripters cove
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!
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!