Scripters cove

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

Moderators: winston, another_commander

User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

phkb wrote:
It's actually a pretty simple mistake, and one I often make:
Layne wrote:
system.government = 7
should read as system.government == 7. In Javascript, the "=" sign on its own is used for assigning values (ie. var x = 1;) In an "If" statement, you need to use "==" or "===". Either should do the trick.
Yep, that.

And if your choice is notepad, wordpad or word, use wordpad. Make sure it's saving as txt, not rtf.
Layne
---- E L I T E ----
---- E L I T E ----
Posts: 355
Joined: Sat Mar 28, 2015 11:14 pm

Re: Scripters cove

Post by Layne »

Ahh, that seems to be working now, thank you. I've been using wordpad all along (except once when I tried MS Word just to see if that made a difference) because I'd already read on several threads not to ever use notepad because it ruins the formatting. I also think I've gotten the constore issue working with a few older bits of scripting. Kinda a Frankenmod, but it's working mostly how I want it to...
Reports of my death have been greatly underestimated.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove

Post by Cody »

Notepad++ is very good, btw.
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
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 »

What is the best way to determine that a ship is docking at a station? Do a check on whether dockingInstructions exists and the station property of the dockingInstructions is the desired station?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

phkb wrote:
What is the best way to determine that a ship is docking at a station? Do a check on whether dockingInstructions exists and the station property of the dockingInstructions is the desired station?
Don'tcha just add an otherShipDocked function to the station's ship script and use it to pass the data through to your worldscript(s)?
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 »

phkb wrote:
What is the best way to determine that a ship is docking at a station? Do a check on whether dockingInstructions exists and the station property of the dockingInstructions is the desired station?
That's probably most straightforward, yes.
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 »

Wildeblood wrote:
Don'tcha just add an otherShipDocked function to the station's ship script and use it to pass the data through to your worldscript(s)?
I'm doing that to determine when a ship has docked, but I also want to know when a ship is trying to dock so that you can see it on the shipping news page, but also so that I can add those ships to the shipping news page in the case where the player launches while they are trying to dock. Otherwise that ship would just disappear.
User avatar
Vincentz
Deadly
Deadly
Posts: 174
Joined: Sun Mar 22, 2015 11:26 pm

Re: Scripters cove

Post by Vincentz »

Enters thread

"Hi!"

Looks around

"Is this where I can buy magic?"

Lifts up old tome, blows dust off cover. A big JS is imprinted on the cover

"... or any sufficiently advanced technology that is indistinguishable from it?"

----------------------------------------------------

I'd love to make this happen: https://bb.oolite.space/viewtopic.php?f= ... 06#p235406

If my brain circuits are working somewhat properly, it would be a fairly easy script, going something like

Code: Select all

this.name = "neweconomy.js";
this.author = "YOURNAMEHERE";
this.copyright = "April 2015";
this.description = "World Script for adding new types of economies";
this.version = "1.0";

this.setUpSystem = function()

{	
	if(system.economy < 7)
		{use indus-commodities.plist as commodities.plist}
			if(system.economy < 5)
				{use explo-commodities.plist as commodities.plist}
					if(system.economy < 3)
						{use agric-commodities.plist as commodities.plist}
							else {use finan-commodities.plist as commodities.plist}
}
The above code obviously doesn't work, which is why I need someone to sprinkle some magic dust on it, so it can fly :D

TIA
Vincentz
"There is a single light of science, and to brighten it anywhere is to brighten it everywhere." - Isaac Asimov
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripters cove

Post by Smivs »

I don't think it is possible to change any .plists via js.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Vincentz
Deadly
Deadly
Posts: 174
Joined: Sun Mar 22, 2015 11:26 pm

Re: Scripters cove

Post by Vincentz »

Smivs wrote:
I don't think it is possible to change any .plists via js.
mmm. What would be the workaround?
A single commidity.plist (for 1.80) or trade-goods.plist (for 1.81) with different entries, overriding the standard, but depending on the economy levels?
"There is a single light of science, and to brighten it anywhere is to brighten it everywhere." - Isaac Asimov
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripters cove

Post by Smivs »

This is not an area of the game I've ever tinkered with, so I'll leave trying to advise to others who know a bit more about the mechanisms.
I would certainly focus on v1.81. 1.80 won't be around for ever, and you don't want to put a lot of effort into something that could need a major overhaul quite soon.
Commander Smivs, the friendliest Gourd this side of Riedquat.
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 »

For commodities.plist - and I would also not recommend spending time working on this for a new OXP - you can define multiple market definition entries within the plist, and then in planetinfo.plist (or the JS equivalents) select different market definitions for different systems which coincidentally happen to match the economy numbers of those systems. The old [EliteWiki] BlOomberg Markets OXP uses a very similar method to create rare temporary rises or falls in prices of single commodities in single systems.

For trade-goods.plist there are several ways to do it. In the general case, I would use the market_script key in [wiki]planetinfo.plist[/wiki] to set a global market script across all systems, and then use that script to set up whatever algorithm was desired for goods prices based on the economy.

That said, depending on how complex what you want is, you might be able to do it entirely in [wiki]trade-goods.plist[/wiki] by using the peak_export and peak_import properties. In the core game they're set to 0 and 7 (or 7 and 0) for all goods, so the prices line up between Rich Industrial and Poor Agricultural - but you could set them to something else, so a trade good has the highest quantities and lowest price at economy 3, the lowest quantities and highest price at economy 6, and everywhere else will automatically end up somewhere in the middle. You then just rename the economies in descriptions.plist so that the peak import/export you've set up makes thematic sense.
User avatar
Vincentz
Deadly
Deadly
Posts: 174
Joined: Sun Mar 22, 2015 11:26 pm

Re: Scripters cove

Post by Vincentz »

cim wrote:
For commodities.plist - and I would also not recommend spending time working on this for a new OXP - you can define multiple market definition entries within the plist, and then in planetinfo.plist (or the JS equivalents) select different market definitions for different systems which coincidentally happen to match the economy numbers of those systems. The old [EliteWiki] BlOomberg Markets OXP uses a very similar method to create rare temporary rises or falls in prices of single commodities in single systems.

For trade-goods.plist there are several ways to do it. In the general case, I would use the market_script key in [wiki]planetinfo.plist[/wiki] to set a global market script across all systems, and then use that script to set up whatever algorithm was desired for goods prices based on the economy.

That said, depending on how complex what you want is, you might be able to do it entirely in [wiki]trade-goods.plist[/wiki] by using the peak_export and peak_import properties. In the core game they're set to 0 and 7 (or 7 and 0) for all goods, so the prices line up between Rich Industrial and Poor Agricultural - but you could set them to something else, so a trade good has the highest quantities and lowest price at economy 3, the lowest quantities and highest price at economy 6, and everywhere else will automatically end up somewhere in the middle. You then just rename the economies in descriptions.plist so that the peak import/export you've set up makes thematic sense.
While tempting to do the peaks, which would work for most of the markets, I think I would have to go for the market_script, as my plan was to let the Financial economy be a more randomized market with possibilities of making good purchases and sells (within reasonable outswings).

So... (sorry for being so code illiterate) how would a market_script.js look like, and how would it be able to differentiate from different economiy levels?
"There is a single light of science, and to brighten it anywhere is to brighten it everywhere." - Isaac Asimov
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 »

Vincentz wrote:
So... (sorry for being so code illiterate) how would a market_script.js look like, and how would it be able to differentiate from different economiy levels?
You'd set a market script on the system (through planetinfo.plist, most likely) with something like this in:

Code: Select all

this.updateLocalCommodityDefinition = function(marketdef, station, system) {
    var systemInfo = System.infoForSystem(galaxyNumber,system); // get the system info
    var economyNumber = systemInfo.economy; // get the economy number for the system
    // you can also get other system properties or variables at this point

    // the precalculated details for the tradegood are in the marketdef object at this point
    // so you can still use the plist to set up a lot of the basic calculations, and only need
    // to adjust the result here

    var price = ...; // calculation of price based on economy
    var quantity = ...; // calculation of price based on economy

    // set the calculated price and quantity back onto the market definition
    marketdef.price = price;
    marketdef.quantity = quantity;
    // and give the market definition back to Oolite to use
    return marketdef;
};
User avatar
Vincentz
Deadly
Deadly
Posts: 174
Joined: Sun Mar 22, 2015 11:26 pm

Re: Scripters cove

Post by Vincentz »

cim wrote:
Vincentz wrote:
So... (sorry for being so code illiterate) how would a market_script.js look like, and how would it be able to differentiate from different economiy levels?
You'd set a market script on the system (through planetinfo.plist, most likely) with something like this in:

Code: Select all

this.updateLocalCommodityDefinition = function(marketdef, station, system) {
    var systemInfo = System.infoForSystem(galaxyNumber,system); // get the system info
    var economyNumber = systemInfo.economy; // get the economy number for the system
    // you can also get other system properties or variables at this point

    // the precalculated details for the tradegood are in the marketdef object at this point
    // so you can still use the plist to set up a lot of the basic calculations, and only need
    // to adjust the result here

    var price = ...; // calculation of price based on economy
    var quantity = ...; // calculation of price based on economy

    // set the calculated price and quantity back onto the market definition
    marketdef.price = price;
    marketdef.quantity = quantity;
    // and give the market definition back to Oolite to use
    return marketdef;
};
Thanks, I'll have a look at it tomorrow.
Actually my request shouldn't even have been in this thread, but in this one : https://bb.oolite.space/viewtopic.php?f=6&t=3296
Sorry for the mistake :oops:
"There is a single light of science, and to brighten it anywhere is to brighten it everywhere." - Isaac Asimov
Post Reply