Scripters cove

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

Moderators: another_commander, winston

User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4646
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Hmm. The wiki says the subEntities property is read only, which would seem to limit that method. But it wouldn't be the first time the wiki is out of date. I'll have a go and see what I can break!

In any case, I have a fallback position where I define both of those sub-entities in the shipdata, and then remove the appropriate one based on active/inactive status.
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 »

That should work, overlaying 2 models (active and inactive) and remove or restore the active one when needed. I tired another approach by setting the max_energy to 0, needless to say the turret keep on firing. :lol:
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted »

I'm experiencing a problem (I think it's a problem) with the equipmentAdded event handler. The argument ("equipmentKey") isn't being passed consistently.

Here is the code that doesn't work:

Code: Select all

this.equipmentAdded = function(equipment) {this._CD_addEquipment(equipment);}

this._CD_addEquipment(equipment)
{
  var cOS = "_CD_checkOnStuff", iR = "isRunning", s = "start", t = "timer";
  if(equipment === "EQ_TRUMBLE")
  {
    if(!this[cOS][t]) {this[cOS][t] = new Timer(this, this[cOS], 60, 90);}
    else if(!this[cOS][t][iR]) {this[cOS][t][s]();}
  }
}
Oolite starts barfing up reference errors:

Code: Select all

21:13:19.422 [script.javaScript.exception.notDefined]: ***** JavaScript exception (CD_change-difficulty): ReferenceError: equipment is not defined
21:13:19.422 [script.javaScript.load.failed]: ***** Error loading JavaScript script ../AddOns/ChangeDifficulty.oxp/Scripts/CD_change-difficulty.js -- could not run script
21:13:19.422 [script.load.notFound]: ***** ERROR: Could not find script file CD_change-difficulty.js.
But when I take the function body from this._CD_addEquipment and attach it directly to the event handler, it works fine...

I'd rather not do it that way (I think that event handlers should be nice, neat one-liners...), but it's the only way that seems to work...

Is this.equipmentAdded broken somehow? Or am I just missing something?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4646
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

I'm not JS expert, but shouldn't this line:

Code: Select all

this._CD_addEquipment(equipment)
be this?:

Code: Select all

this._CD_addEquipment = function(equipment)
I just tested this form and that seems to work OK.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted »

phkb wrote: Fri Aug 16, 2019 4:16 am
I'm not JS expert, but shouldn't this line:

Code: Select all

this._CD_addEquipment(equipment)
be this?:

Code: Select all

this._CD_addEquipment = function(equipment)
I just tested this form and that seems to work OK.
Bingo! Dead on the money!

It's amazing how you look right at something and not see it... :oops:
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 »

A simple task, or so I thought, however the result is not exactly as expected. I created a new commodity:

Code: Select all

"holy_artifacts" = 
{	
	"name" = "[commodity-name holy_artifacts]";
	"classes" = ("oolite-consumer", "oolite-luxury");
	"comment" = "religious Artifacts, good luck charms and protection chants";
	"quantity_unit" = 1;  // kg
	"peak_export" = 0;  // Mainly Industrial
	"peak_import" = 7;  // Poor Agricultural
	"price_average" = 3500;  // decicredits
	"price_economic" = 0.48;
	"price_random" = 0.03;
	"quantity_average" = 13.5;
	"quantity_economic" = 0.52;
	"quantity_random" = 1.15;
	"legality_export" = 0.0;
	"legality_import" = 0.0;
	"trumble_opinion" = 0.0;
	"market_script" = "SGNS-dictator_clergy_market.js";
	"sort_order" = 1695;
};
and added a simple market script to it:

Code: Select all

this.updateGeneralCommodityDefinition = function(goodDefinition, station, systemID)
{
	if (station && station.allegiance != "pirate" && station.allegiance != "chaotic" && system.info.government === 4)
	{
		goodDefinition.capacity = "0";
		goodDefinition.legality_export = "2";
		goodDefinition.legality_import = "2";
	}
	return goodDefinition;
}
While I receive some errors in the log:

16:57:26.666 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (Artifacts 0.5.0): TypeError: station is null
16:57:26.666 [script.commodityScript.error]: Could not update general commodity definition for [commodity-name holy_artifacts] - unable to call updateLocalCommodityDefinition

I could say after some testing that it seems to work, exception is the main station where all my updates are ignored. Anybody has an idea what I missed or did simply wrong ?
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: 4646
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: Tue Dec 03, 2019 10:08 am
I created a new commodity
Just a quick check: you need to put your commodity definition inside another set of braces, like this:

Code: Select all

{
    "holy_artifacts" = 
    {
    	...
    };
 }
You might be doing this already, and just copied the definition code, but it's worth checking.
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: Tue Dec 03, 2019 9:18 pm
You might be doing this already, and just copied the definition code, but it's worth checking.
Thanks phkb, since I still find typos and copy & past errors in code I checked several times before it was a good hint, however, this time unfortunatly not the solution. Here the complete code:

Code: Select all

{
	"holy_artifacts" = 
	{
		"name" = "[commodity-name holy_artifacts]";
		"classes" = ("oolite-consumer", "oolite-luxury");
		"comment" = "religious Artifacts, good luck charms and protection chants";
		"quantity_unit" = 1;  // kg
		"peak_export" = 0;  // Mainly Industrial
		"peak_import" = 7;  // Poor Agricultural
		"price_average" = 3500;  // decicredits
		"price_economic" = 0.48;
		"price_random" = 0.03;
		"quantity_average" = 13.5;
		"quantity_economic" = 0.52;
		"quantity_random" = 1.15;
		"legality_export" = 0.0;
		"legality_import" = 0.0;
		"trumble_opinion" = 0.0;
		"market_script" = "SGNS-dictator_clergy_market.js";
		"sort_order" = 1695;
	};
}

Code: Select all

this.name			= "Artifacts";
this.author		= "Montana05";
this.description	= "Artifact restrictions";
this.version		= "0.5.0";
this.copyright		= "Creative Commons: attribution, non-commercial, share-alike.";
this.licence   		= "CC BY-NC-SA";
"use strict";

// Feel free to use in any way you like as long as its non-commercial

// Communists just hate them
this.updateGeneralCommodityDefinition = function(goodDefinition, station, systemID)
{
	if (station && station.allegiance != "pirate" && station.allegiance != "chaotic" && system.info.government === 4)
	{
		goodDefinition.capacity = "0";
		goodDefinition.legality_export = "2";
		goodDefinition.legality_import = "2";
	}
	
        return goodDefinition;
}
Basic idea is to ban import and export in communist systems and make sure that no stock is available at stations. Excluded are only "sleezy" stations.

Edit:
Btw I think I found a solution to put the loaders of the imperial freighters to work, I am using it now for shuttles and didn't run in any errors for a while now. I intend to fix a logical error (prison ships and astrofactories never meet) by introducing an inter-dictator-traffic, probably including clerics as well.
Scars remind us where we've been. They don't have to dictate where we're going.
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 »

Happy New Year, no preassure ment but any ideas yet what could be the reason for the problem ? :oops:
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: 4646
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

I’m going on a family holiday and won’t have access to do debugging until the end of the month. I will look at this more closely then.
User avatar
tsoj
Deadly
Deadly
Posts: 199
Joined: Wed May 18, 2016 8:19 pm
Location: Berlin
Contact:

Re: Scripters cove

Post by tsoj »

Hi,
I was wondering why the timeAccelerationFactor (http://wiki.alioth.net/index.php/Oolite ... tionFactor) is only writeable in the dev-version of Oolite. Are there some side effects other than speeding up the game that one should know about before using it in an OXP?
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16060
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove

Post by Cody »

The TAF is seen as a dev tool, and not for normal gameplay (it was disabled in Oolite 1.77), but I'm not aware of any side effects.
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!
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander »

I think the main issue with enabling TAF unconditionally was that we could not guarantee that AI routines, especially ones like attacking, docking and sun-skimming, would continue to function exactly as expected at high time accelerations. Having said that, I think that most work fine up to a TAF of x4. Time deceleration could also be used for creating bullet time effects, but that would probably fit more with story-driven OXPs.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4646
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: Wed Jan 01, 2020 12:36 pm
any ideas yet what could be the reason for the problem ?
OK, back in the saddle! Sorry the the break in transmission!

Right, market scripts for new commodities. If I understand the logic correctly, you're trying to make the main station (or any neutral or GalCop station) deal with artefacts as illegal goods, and also making sure these stations don't have any units available for purchase. The trick I found was that, in the updateGeneralCommodityDefinition function, it's never called for the main station. It's called for every other station, but, from the games point of view, the system definition for a commodity is the same thing as the main station's definition. So, in your case, because your exception is the main station, you need to do something slightly different to achieve what you want.

Here's something I prepared earlier: Artefacts.zip (Apologies for changing "artifacts" to "artefacts". Australian spelling). In this zip is an OXP which has the Holy Artefacts implemented in the way I think you want them: illegal to import or export in communist systems, except at pirate or chaotic stations, and with 0 units at those stations where they're illegal. What I did was add a world script that calls "systemWillPopulate". The main station should be accessible at this point during, so I'm just setting the quantity to zero at this point. All other stations will be handled by the market script.

I've done some limited testing on this, and it seems to work OK, but let me know if you run into problems.
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: Wed Feb 19, 2020 1:08 pm
Here's something I prepared earlier: Artefacts.zip (Apologies for changing "artifacts" to "artefacts". Australian spelling). In this zip is an OXP which has the Holy Artefacts implemented in the way I think you want them: illegal to import or export in communist systems, except at pirate or chaotic stations, and with 0 units at those stations where they're illegal. What I did was add a world script that calls "systemWillPopulate". The main station should be accessible at this point during, so I'm just setting the quantity to zero at this point. All other stations will be handled by the market script.

I've done some limited testing on this, and it seems to work OK, but let me know if you run into problems.
Welcome back phkb, I hope you had a great time with your family.
Thank you very much for your help, I got frustrated already because actually it was a simple idea. However, after some hours of testing today, I didn't find any problems, your code got exactly the result I had in mind. Some tuning will be required (pirate coves for example needed to be addressed by main-role) but finally the basic is working. Thank you again. :)
Scars remind us where we've been. They don't have to dictate where we're going.
Post Reply