Scripters cove

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

Moderators: winston, another_commander

User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters' cove: station interfaces, the mystery thereof

Post by cim »

Wildeblood wrote:
I want an unfriendly station, where dockside services are not available. How do I prevent or undo your OXP setting an interface on my station? Is there an array I can loop through and null them all? If not, why not? Is there a way to prevent them being set in the first place? Basically, the problem is this: you've installed the It's Not For Everyone OXP, when you dock at INFE Station, you should see only the interfaces set by the INFE OXP, and no others.
You can do station.setInterface("interface-name",null) to remove an interface.

The only core game interface which appears outside main stations is the "manage primable equipment" one - the logic being that it's not a station interface, it's a ship control, so it doesn't matter where you dock. Its key is "oolite-primable-equipment-manager" if you want to disable it anyway.
Wildeblood wrote:
Do interfaces have to be set from a world script [...] Are there any restrictions on the callback function of an interface?
No, and no.
Wildeblood wrote:
Lastly, if I have a reference to a station object, can I execute the callback function of an interface on that station while player.ship.docked === false or while docked at another station?
Yes, provided you retain a reference to the callback function somewhere you can reach.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

Or the other option (depending on what you want to offer instead) could be to intercept opening the Interfaces screen for your station and then reroute it to a mission screen where you make your station-specific offers. It's perhaps not quite as elegant, but it works (see the Lave Academy station course offer screen for example, which intercepts the market screen).
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

I'm trying to write a js AI for a hoopy casino station that would make the ship do circles around the main station. I'm obviously not getting something, so maybe someone can help me here. This script just makes the ship zig-zag away from the main station.

Code: Select all

"use strict";

this.name = "hOopy Casino AI";

this.aiStarted = function() {
	var ai = new worldScripts["oolite-libPriorityAI"].PriorityAIController(this.ship);
	ai.setWaypointGenerator(ai.waypointsStationPatrol);
	ai.setPriorities([
		/* Cruise around the main station*/
		{
			condition: ai.conditionHasWaypoint,
			configuration: ai.configurationSetDestinationToWaypoint,
			behaviour: ai.behaviourApproachDestination,
			reconsider: 30
		},
		{
			configuration: ai.configurationSetWaypoint,
            behaviour: ai.behaviourApproachDestination,
            reconsider: 30
		}
	]);
}
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 »

The waypointsStationPatrol method picks the station to patrol around by:
1) if the ship is in a group, and the group has a leader, and the leader is a station, use that station
2) otherwise use the main station

The casino is a station, and likely the leader of its group by default. So it's probably trying to patrol in circles around itself.

You'll need to define your own waypoint method.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

cim wrote:
The waypointsStationPatrol method picks the station to patrol around by:
1) if the ship is in a group, and the group has a leader, and the leader is a station, use that station
2) otherwise use the main station

The casino is a station, and likely the leader of its group by default. So it's probably trying to patrol in circles around itself.

You'll need to define your own waypoint method.
Ok. I was suspecting that was the case.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

I'm tackling with priorityAI and trying to understand things. If I shoot at the station this code just keeps printing "test2" messages to the log:

Code: Select all

		{
			preconfiguration: ai.configurationStationValidateTarget,
			condition: ai.conditionInCombat,
			behaviour: function() {
				log("test","test1");
			},
			reconsider: 5
		},
		{
			configuration: ai.configurationStationReduceAlertLevel,
			behaviour: function() {
				log("test","test2");
				},
			reconsider: 60
		},
But this code:

Code: Select all

		{
			preconfiguration: ai.configurationStationValidateTarget,
			condition: ai.conditionInCombat,
			behaviour: function() {
				log("test","test1");
			},
			reconsider: 5
		},
		{
			configuration: ai.configurationStationReduceAlertLevel,
			behaviour: function() {
				log("test","test2");
				ai.behaviourStationManageTraffic();
				},
			reconsider: 60
		},
produces "test1" too. It looks like running behaviourStationManageTraffic (or any other behaviour function?) does something that enables ai.conditionInCombat to be true. If I write my own finishing behaviour function, is there something that needs to be there for things to work? Something that initializes something?
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 »

spara wrote:
It looks like running behaviourStationManageTraffic (or any other behaviour function?) does something that enables ai.conditionInCombat to be true. If I write my own finishing behaviour function, is there something that needs to be there for things to work? Something that initializes something?
It's the event handlers which need setting up. Response definition functions and components.

Without these, the station won't have a "shipBeingAttacked" event handler, which means that it won't target its attacker, which means that conditionInCombat won't be true.

To begin with this will give you the standard station event handlers.

Code: Select all

var handlers = {}; // new handler object
this.responsesAddStation(handlers); // add standard response set
this.applyHandlers(handlers);
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

Ah. That explains a lot. Thanks.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

I've got things pretty much working the way I want, so it's up to finer details. This one gives me nothing but "null" to the log and I don't understand why.

Code: Select all

		{
			preconfiguration: ai.configurationCheckScanner,
			condition: ai.conditionScannerContainsCleanShip,
			behaviour: function() {
				log("test", ai.getParameter("oolite_scanResultsSpecific"));
			},
			reconsider: 30
		}
The way I understand it, oolite_scanResultsSpecific should never be "null" in this case.


Found it. It's a typo in the wiki. It should be oolite_scanResultSpecific. Wiki fixed.

Another question about the "has_npc_traffic" in shipdata.plist. Wiki states that only rotating stations will launch traders. Is this correct and is there some simple reason for it? Is it also correct, if I assume that the moving casino cruiser will never get any NPC visitors by the populator?
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 546
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: Scripters cove

Post by Lone_Wolf »

I'm currently working on making shieldcycler devices breakable, and got a question about the worldScritps equipmentDestroyed event handler.
oolite worldscripts event handler entry wrote:
equipmentDestroyed

The equipmentDestroyed handler is called when equipment gets destroyed completely beyond repair. (in strict mode) (world script only)

this.equipmentDestroyed = function(equipment)
{
// Your code here
}
Announcing Oolite v1.80 wrote:
* Strict mode now only disables OXPs rather than making other gameplay
changes
Do oxps need an equipmentDestroyed handler, or is this event only triggered for core game scripts when the game is in strict mode ?
OS : Arch Linux 64-bit - rolling release

OXPs : My user page

Retired, reachable at [email protected]
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 »

Lone_Wolf wrote:
Do oxps need an equipmentDestroyed handler, or is this event only triggered for core game scripts when the game is in strict mode ?
It shouldn't be necessary.
spara wrote:
Another question about the "has_npc_traffic" in shipdata.plist. Wiki states that only rotating stations will launch traders. Is this correct and is there some simple reason for it?
This is a leftover in the docs from 1.77's populator. In 1.80 the core populator determines whether to launch ships of any sort based just on the "has_npc_traffic" value, with the station's allegiance property used to determine which ships to launch. I'll update the docs.
spara wrote:
Is it also correct, if I assume that the moving casino cruiser will never get any NPC visitors by the populator?
This also depends on its allegiance. "private" is the correct value for a station which shouldn't get any normal NPCs docking (this doesn't stop you writing specific AIs which will dock with it anyway, though)
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 546
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: Scripters cove

Post by Lone_Wolf »

cim wrote:
Lone_Wolf wrote:
Do oxps need an equipmentDestroyed handler, or is this event only triggered for core game scripts when the game is in strict mode ?
It shouldn't be necessary.
Thanks, maybe you could clarify the text for the equipmentDestroyed handler on the wiki ?

(I don't feel comfortable editing pages that are the closest to official documentation we got).
OS : Arch Linux 64-bit - rolling release

OXPs : My user page

Retired, reachable at [email protected]
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 »

Done. (Indeed, checking more closely, there is no longer any code in the core game which will call that handler)
User avatar
Rese249er
---- E L I T E ----
---- E L I T E ----
Posts: 647
Joined: Thu Jun 07, 2012 2:19 pm
Location: Well, I WAS in G3...

Re: Scripters cove

Post by Rese249er »

Two questions and a sidenote...

First question: can the player's ship be referenced in a shipdata.plist so that it would adjust to any ship the player is flying?
Second Question: Could someone point out a ship script to remove the ship after X seconds without affecting the AI?
Sidenote: While tweaking the OXP this will go towards, I did a little... combat testing, so to speak, at Ceesxe. G1. I undocked from the main station and swung around to point myself at the nearrby Super Hub to fire upon it. A single burst got me a sternly worded message to offline my weapons if I couldn't keep them from firing. Sustained fire... Well, Vipers launched from the main station, and along with the usual messages calling me out Vipers also started firing on the SuperHub! [shameless tease]I was simply flabbergasted and probably would've popped in a second if it weren't for my OXP![/shameless tease] As it was they got around to me in about ten seconds...
Got all turned around, lost my nav connection... Where am I now?
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 »

Rese249er wrote:
First question: can the player's ship be referenced in a shipdata.plist so that it would adjust to any ship the player is flying?
No.
Rese249er wrote:
Second Question: Could someone point out a ship script to remove the ship after X seconds without affecting the AI?
Easiest way is to use a timer.

Code: Select all

this.$removeTimer = new Timer(this,function() { this.ship.remove(); },delay);
and put that in whatever event handler you want in the ship script.

(The AI will be removed along with the ship - I'm not sure what you mean by that bit)
Post Reply