Iron Ass OXP

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

Moderators: winston, another_commander

User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass OXP

Post by Old Murgh »

phkb wrote: Sat Jul 09, 2022 7:33 am
The method I’m using in the example should be agnostic when it comes to connecting to the ships you create, so it should be applicable to any arrangement.
That's promising.

So I'm trying it out with baby steps,

Code: Select all

"use strict";

this.name = "xpatComms"; // the name of your script, not necessarily the name of the file
this.author = "phkb"; 
this.description = "Add Xpat broadcast comms functions";
this.version   = "1.0";

this._bcc = null; // holds a reference to BCC

this.startUp = function() {
	// grab a reference to the bcc worldscript, if it's installed
	if (worldScripts.BroadcastCommsMFD) this._bcc = worldScripts.BroadcastCommsMFD;
	// if BCC isn't installed, remove our shipSpawned function, as it doesn't need to run
	if (!this._bcc) delete this.shipSpawned;
}

this.shipSpawned = function(ship) {
	// look for a ship with a particular primary role being spawned
	if (ship.primaryRole == "xpat") {
		// found one!
		this._bcc.$createMessage({
			messageName: "myXpatMessage_status" + clock.adjustedSeconds, // a unique ID for this message
			displayText: "Inquire status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmittionTarget: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$transmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 2, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		};
	}
}

this.$transmitCallback = function $transmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Kind Commander, we are indeed in a sorry state and in desperate need of help.", player.ship);
}
Unfortunately, in comms interactions, I'm only offered to greet, taunt and demand 5T cargo from it, and it has the regular cute and cocky responses.

But the log shows an error:

Code: Select all

 [script.javaScript.exception.parenAfterArgs]: ***** JavaScript exception (xpatComms.js.anon-script): SyntaxError: missing ) after argument list
so it never loaded.

Is that ) something I managed to delete from the original? I can't fnd it. I did try to insert one by guessing :roll: , which did in fact remove the error, but it didn't make anything happen.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Iron Ass OXP

Post by Alnivel »

Old Murgh wrote: Sat Jul 09, 2022 5:26 pm
But the log shows an error:

Code: Select all

 [script.javaScript.exception.parenAfterArgs]: ***** JavaScript exception (xpatComms.js.anon-script): SyntaxError: missing ) after argument list
so it never loaded.

Is that ) something I managed to delete from the original? I can't fnd it. I did try to insert one by guessing :roll: , which did in fact remove the error, but it didn't make anything happen.
The closing brace should be on line 31:

Code: Select all

			delayCallback: 2, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		}); // <-- The closing bracket here
	}
}
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass OXP

Post by Old Murgh »

Alnivel wrote: Sat Jul 09, 2022 7:05 pm
The closing brace should be on line 31:
:shock: :D :?
Thankyou! That is at the same time both uplifting and demoralising. It is to my amazement exactly what I guessed and tried, but thus.. then the script did not have any effect.

I have to assume there is some other aspect of the template I haven't understood and filled out. Since no error is reported in the log, I can't say anything more useful.. :(

For all you puzzle-loving folks out there too curious to keep on walking, these are the files XpatXperiment.zip. (5MB)
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Iron Ass OXP

Post by Cholmondely »

I was wondering if it might make more sense to use the AI as the ID for the difference in Broadcast Comms communications. If the Refugee Adders were tagged as "Refugees" (rather than as pirates, NPC's Thargoids, etc) and then their own set of communications was devised by a chap/tribble with a lo-o-ong beard over in Scandinavia...
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass OXP

Post by Old Murgh »

Cholmondely wrote: Sat Jul 09, 2022 9:30 pm
I was wondering if it might make more sense to use the AI as the ID for the difference in Broadcast Comms communications. If the Refugee Adders were tagged as "Refugees" (rather than as pirates, NPC's Thargoids, etc) and then their own set of communications was devised by a chap/tribble with a lo-o-ong beard over in Scandinavia...
I don't quite follow, the context in which you mention AI.. but maybe..

True, right now they are viewed as offenders by GalCop, and police warn them of fines if they try to dock. I'm not sure I don't feel that's ok.
Are you saying you think I ought to find a way to remove it, and then by smoke and mirrors introduce a new legal status (Refugee) through the custom RSN loophole?

We'll see how this own set of comms goes. :cry:
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Iron Ass OXP

Post by Alnivel »

Old Murgh wrote: Sat Jul 09, 2022 7:33 pm
I have to assume there is some other aspect of the template I haven't understood and filled out. Since no error is reported in the log, I can't say anything more useful.. :(
The main problem was a simple typo - "transmittionTarget" instead of "transmissionTarget" (line 33 or 34). Also, if several ships appeared in a short period of time, messages could get the same ID and only one of them was added.

Code: Select all

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	// look for a ship with a particular primary role being spawned
	if (ship.primaryRole == "xpat") {
		// found one!		
		this._bcc.$createMessage({
			messageName: "myXpatMessage_status" + this._IDcounter++, // a unique ID for this message
			displayText: "Inquire Xpat status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$transmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 2, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
	}
}
And one more problem, only more global than just with comms: only one of the group of ships that appeared has the role of "xpat", the rest - "escort". They won't get the desired communication option, nor will they get any "harmless" behavior - for example, they even fight back (I'm guessing they shouldn't).
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: Iron Ass OXP

Post by phkb »

Apologies, that was my fault! Should have tested the code, rather than just written straight into the reply window. Lesson learnt.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass comms

Post by Old Murgh »

Alnivel wrote: Sat Jul 09, 2022 10:59 pm
The main problem was a simple typo - "transmittionTarget" instead of "transmissionTarget" (line 33 or 34). Also, if several ships appeared in a short period of time, messages could get the same ID and only one of them was added.
Thank you!
phkb wrote: Sat Jul 09, 2022 11:06 pm
Apologies, that was my fault! Should have tested the code, rather than just written straight into the reply window. Lesson learnt.
Ah you guys. I would play chess without a board if I could too.
Alnivel wrote: Sat Jul 09, 2022 10:59 pm
And one more problem, only more global than just with comms: only one of the group of ships that appeared has the role of "xpat", the rest - "escort". They won't get the desired communication option, nor will they get any "harmless" behavior - for example, they even fight back (I'm guessing they shouldn't).
Yes, thanks for pointing out the broader aspect of this problem.
I have them set up like this because I was getting a warning (a catastrophic time-continuum loop, apparently) about having a ship be its own designated escort when all I want is the illusion of a small group of equals travelling together.
I was wondering if there was a way to make the above script apply equally to both primary roles xpat and xpatesc, or if I should ditch the plan and risk the loop, or a find a smarter solution.

[edit:Later]
Well, the first step WORKS. Very satisfying.
I then looked to how I would continue the conversation or offer different paths, but I didn't do it quite right.
Simply increasing the IDcounter evidently isn't enough.

Code: Select all

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	// look for a ship with a particular primary role being spawned
	if (ship.primaryRole == "xpat") {
		// found one!		
		this._bcc.$createMessage({
			messageName: "myXpatMessage_status" + this._IDcounter++, // a unique ID for this message
			displayText: "Inquire Xpat status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$transmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 2, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
	}
}

this.$transmitCallback = function $transmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Kind Commander, we ware indeed in a sorry state and in need of help.", player.ship);
}

this._IDcounter = 2; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	// look for a ship with a particular primary role being spawned
	if (ship.primaryRole == "xpat") {
		// found one!		
		this._bcc.$createMessage({
			messageName: "myXpatMessage_slavedemand" + this._IDcounter++, // a unique ID for this message
			displayText: "Demand slave offering", // what to show in the BCC MFD
			messageText: "Vulnerable Xpat, select your healthiest specimens and eject to my custody, and I will let the rest of you live", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$transmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 5, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
	}
}

this.$transmitCallback = function $transmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("You lowlife! We sacrifice nobody and would sooner die together!", player.ship);
}
This ended up with comm#2 eclipsing #1, so still just one option in addition to the greet, taunt and 5Tdemand..
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Iron Ass comms

Post by Alnivel »

Old Murgh wrote: Sat Jul 09, 2022 11:27 pm
I was wondering if there was a way to make the above script apply equally to both primary roles xpat and xpatesc, or if I should ditch the plan and risk the loop, or a find a smarter solution.
This slight change to the if condition should help:

Code: Select all

if (ship.primaryRole == "xpat" || ship.primaryRole == "xpatesc")
Old Murgh wrote: Sat Jul 09, 2022 11:27 pm
I then looked to how I would continue the conversation or offer different paths, but I didn't do it quite right.
Simply increasing the IDcounter evidently isn't enough.
...
This ended up with comm#2 eclipsing #1, so still just one option in addition to the greet, taunt and 5Tdemand..
Here you didn't add new shipSpawned and $transmitCallback, but replaced them. There should be only one shipSpawned and each transmitCallback must be stored in a separate variable. You are not limited the "transmitCallback" name and can use more descriptive names if you like. If many dialogues are planned, I would recommend to do this, it can help in the long run.

Returning to the topic of adding new comms:

This code will add two custom available communication options at the start of a conversation:

Code: Select all

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	if (ship.primaryRole == "xpat" || ship.primaryRole == "xpatesc") {
		this._bcc.$createMessage({
			messageName: "myXpatMessage_status" + this._IDcounter++, // a unique ID for this message
			displayText: "Inquire Xpat status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$inquireStatusTransmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 2, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
		
		this._bcc.$createMessage({
			messageName: "myXpatMessage_slavedemand" + this._IDcounter++, // one counter stiil should be enough
			displayText: "Demand slave offering", 
			messageText: "Vulnerable Xpat, select your healthiest specimens and eject to my custody, and I will let the rest of you live",
			ship: ship, 
			transmissionType: "target",
			callbackFunction: this.$demandSlavesTransmitCallback.bind(this, ship), 
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 5, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
		
		// You can add more here! (But they will also be available immediately)
	}
}

// Variable naming is my passion, so feel free to change those names for better ones
this.$inquireStatusTransmitCallback = function $InquireStatusTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Kind Commander, we ware indeed in a sorry state and in need of help.", player.ship);
	
	// Add one or more $createMessage here and they will appear after status inquring
}

this.$demandSlavesTransmitCallback = function $demandSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("You lowlife! We sacrifice nobody and would sooner die together!", player.ship);
}
This code will add one custom available communication option after using which another one will appear:

Code: Select all

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	if (ship.primaryRole == "xpat" || ship.primaryRole == "xpatesc") {
		this._bcc.$createMessage({
			messageName: "myXpatMessage_status" + this._IDcounter++, // a unique ID for this message
			displayText: "Inquire Xpat status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$inquireStatusTransmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 2, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
		
		// You can add more here! (But they will also be available immediately)
	}
}

// Variable naming is my passion, so feel free to change those names for better ones
this.$inquireStatusTransmitCallback = function $InquireStatusTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Kind Commander, we ware indeed in a sorry state and in need of help.", player.ship);
	
	this._bcc.$createMessage({
		messageName: "myXpatMessage_slavedemand" + this._IDcounter++, // one counter stiil should be enough
		displayText: "Demand slave offering", 
		messageText: "Vulnerable Xpat, select your healthiest specimens and eject to my custody, and I will let the rest of you live",
		ship: ship, 
		transmissionType: "target",
		callbackFunction: this.$demandSlavesTransmitCallback.bind(this, ship), 
		deleteOnTransmit: true, 
		delayCallback: 5, 
		hideOnConditionRed: false
	});
	
	// Add more here and they will appear after status inquring
}

this.$demandSlavesTransmitCallback = function $demandSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("You lowlife! We sacrifice nobody and would sooner die together!", player.ship);
}
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass comms

Post by Old Murgh »

Alnivel wrote: Sun Jul 10, 2022 8:12 am
Here you didn't add new shipSpawned and $transmitCallback, but replaced them. There should be only one shipSpawned and each transmitCallback must be stored in a separate variable. You are not limited the "transmitCallback" name and can use more descriptive names if you like. If many dialogues are planned, I would recommend to do this, it can help in the long run.
Great! This looks like a the path forward. I shall plug away.

I think the top puzzle for me now is how I bundle this with prepared alternate responses to the generic Comms inquiries: the greeting, taunt and 5Tcargo kickback demand. The standard ones are of such a different character than Xpats would be.

Or if I can't piggyback on those, then I suppose I must clear them somehow and replace them with new versions?

My dream of a dieroll of responses – for instance prompting a chance that an Xpat resigns to actually sacrifice a few passengers into slavery is too ambitious to think about right now. :mrgreen:
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
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: Iron Ass OXP

Post by phkb »

It might require a couple of changes in BCC. Don’t get too caught up with those for the moment while I cook something up.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass comms

Post by Old Murgh »

Alnivel wrote: Sun Jul 10, 2022 8:12 am
This slight change to the if condition should help:

Code: Select all

if (ship.primaryRole == "xpat" || ship.primaryRole == "xpatesc")
Featuring both inquiries now works like a charm, but the added "xpatesc" role isn't heeded/included. I have a mind to try your add role method onto the customRSN script. Maybe that will jig something? Or make the naming scheme work for them?

[edit, a little later]
No, didn't manage to sneak that in there so it worked. Is there an obvious to tag on a role or does it need a script of its own?

Code: Select all

this.name = "xpatNamer";

this.startUp = function() {
	var rsn = worldScripts.randomshipnames;
	if (rsn) {
		rsn.$externalNameEngine(this.name, "xpat", 1);
		// the "1" in the function all above is the probability that the routine will be called. 1 means always. 
	}
}
phkb wrote: Sun Jul 10, 2022 11:13 am
It might require a couple of changes in BCC. Don’t get too caught up with those for the moment while I cook something up.
No worries. I'll be patiently floating about.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Iron Ass comms

Post by Alnivel »

Old Murgh wrote: Sun Jul 10, 2022 11:54 am
Alnivel wrote: Sun Jul 10, 2022 8:12 am
This slight change to the if condition should help:

Code: Select all

if (ship.primaryRole == "xpat" || ship.primaryRole == "xpatesc")
Featuring both inquiries now works like a charm, but the added "xpatesc" role isn't heeded/included.
As it turns out, if a ship spawns as an escort, their primary role will be, well, escort.

Code: Select all

if (ship.hasRole("xpat") || ship.hasRole("xpatesc"))
The code above should work correctly.
Old Murgh wrote: Sun Jul 10, 2022 10:02 am
My dream of a dieroll of responses – for instance prompting a chance that an Xpat resigns to actually sacrifice a few passengers into slavery is too ambitious to think about right now. :mrgreen:
It sounds even easier than replacing the standard answers... if do it in js. You just need to add a few ifs with Math.random() in condition in your transmit callbacks.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Iron Ass comms

Post by Old Murgh »

Alnivel wrote: Sun Jul 10, 2022 1:52 pm
The code above should work correctly.
It does. They now behave the same commswise. If I could get them equal role rights in the naming script too all would be well with appearances.

I carried on with expansions as per your template above, expanding to 3 comms options worked well, and only when I tried a follow-up comm to the third did I get into trouble.

Code: Select all

this._bcc = null; // holds a reference to BCC

this.startUp = function() {
	// grab a reference to the bcc worldscript, if it's installed
	if (worldScripts.BroadcastCommsMFD) this._bcc = worldScripts.BroadcastCommsMFD;
	// if BCC isn't installed, remove our shipSpawned function, as it doesn't need to run
	if (!this._bcc) delete this.shipSpawned;
}

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	if (ship.hasRole("xpat") || ship.hasRole("xpatesc")) {
		this._bcc.$createMessage({
			messageName: "askXpat_status" + this._IDcounter++, // a unique ID for this message
			displayText: "Inquire Xpat status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$askXpatStatusTransmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 5, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
		
		this._bcc.$createMessage({
			messageName: "offerXpat_encourage" + this._IDcounter++, // one counter still should be enough
			displayText: "Offer Xpat encouraging words", 
			messageText: "Noble refugees, keep faith in that your plight is just, and that all shall surely be well in the end.",
			ship: ship, 
			transmissionType: "target",
			callbackFunction: this.$offerXpatEncourageTransmitCallback.bind(this, ship), 
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 8, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});

		this._bcc.$createMessage({
			messageName: "demandXpat_slaves" + this._IDcounter++, // one counter still should be enough
			displayText: "Demand slave offering", 
			messageText: "Vulnerable Xpat, select your 10 healthiest specimens and eject them into my custody, and I will let the rest of you live",
			ship: ship, 
			transmissionType: "target",
			callbackFunction: this.$demandXpatSlavesTransmitCallback.bind(this, ship), 
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 5, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});

		// You can add more here! (But they will also be available immediately)
	}
}

// Variable naming is my passion, so feel free to change those names for better ones
this.$askXpatStatusTransmitCallback = function $askXpatStatusTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Kind Commander, we ware indeed in a sorry state and in need of help.", player.ship);
	
	// Add one or more $createMessage here and they will appear after status inquiring
}
this.$offerXpatEncourageTransmitCallback = function $offerXpatEncourageTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Thank you for your gracious words, gentle spacefarer. We endeavour to keep up our spirits.", player.ship);
}
this.$demandXpatSlavesTransmitCallback = function $demandXpatSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("You heinous lowlife! We will sacrifice nobody and would sooner die together!", player.ship);
}

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	if (ship.hasRole("xpat") || ship.hasRole("xpatesc")) {
	this._bcc.$createMessage({
		messageName: "InsistXpat_slaves" + this._IDcounter++, // one counter still should be enough
		displayText: "Insist on slave offering", 
		messageText: "Puny Xpat, you don't understand. Give me my slaves or I will melt your flesh!",
		ship: ship, 
		transmissionType: "target",
		callbackFunction: this.$insistXpatSlavesTransmitCallback.bind(this, ship), 
		deleteOnTransmit: true, 
		delayCallback: 10, 
		hideOnConditionRed: false
	});
}
this.$insistXpatSlavesTransmitCallback = function $insistXpatSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("We understand, cretin. Do your worst, you will never break our spirit.", player.ship);
}
I wish the error log was a little more specific so I could spot the offender

Code: Select all

[script.javaScript.exception.curlyAfterBody]: ***** JavaScript exception (xpatComms.js.anon-script): SyntaxError: missing } after function body
Possibly I misunderstood the placement architecture of how to insert a followup, but I definitely killed a bracket somewhere in the process.
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Iron Ass comms

Post by Alnivel »

Old Murgh wrote: Sun Jul 10, 2022 4:10 pm
I carried on with expansions as per your template above, expanding to 3 comms options worked well, and only when I tried a follow-up comm to the third did I get into trouble.

Code: Select all

this._bcc = null; // holds a reference to BCC

this.startUp = function() {
	// grab a reference to the bcc worldscript, if it's installed
	if (worldScripts.BroadcastCommsMFD) this._bcc = worldScripts.BroadcastCommsMFD;
	// if BCC isn't installed, remove our shipSpawned function, as it doesn't need to run
	if (!this._bcc) delete this.shipSpawned;
}

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	if (ship.hasRole("xpat") || ship.hasRole("xpatesc")) {
		this._bcc.$createMessage({
			messageName: "askXpat_status" + this._IDcounter++, // a unique ID for this message
			displayText: "Inquire Xpat status", // what to show in the BCC MFD
			messageText: "Rickety Xpat, are you in need of assistance?", // the actual text of the transmission,
			ship: ship, // pass the reference to the ship that has just spawned
			transmissionType: "target", // this message is for a particular ship, not a general broadcast
			callbackFunction: this.$askXpatStatusTransmitCallback.bind(this, ship), // the function that is called once the player sends the message, and includes the ship reference as a parameter
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 5, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});
		
		this._bcc.$createMessage({
			messageName: "offerXpat_encourage" + this._IDcounter++, // one counter still should be enough
			displayText: "Offer Xpat encouraging words", 
			messageText: "Noble refugees, keep faith in that your plight is just, and that all shall surely be well in the end.",
			ship: ship, 
			transmissionType: "target",
			callbackFunction: this.$offerXpatEncourageTransmitCallback.bind(this, ship), 
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 8, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});

		this._bcc.$createMessage({
			messageName: "demandXpat_slaves" + this._IDcounter++, // one counter still should be enough
			displayText: "Demand slave offering", 
			messageText: "Vulnerable Xpat, select your 10 healthiest specimens and eject them into my custody, and I will let the rest of you live",
			ship: ship, 
			transmissionType: "target",
			callbackFunction: this.$demandXpatSlavesTransmitCallback.bind(this, ship), 
			deleteOnTransmit: true, // true here means the message option will disappear from the BCC MFD after transmission
			delayCallback: 5, // number of seconds to wait after transmission before sending the reply
			hideOnConditionRed: false // false here means that the message option will always be available, regardless of any combat
		});

		// You can add more here! (But they will also be available immediately)
	}
}

// Variable naming is my passion, so feel free to change those names for better ones
this.$askXpatStatusTransmitCallback = function $askXpatStatusTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Kind Commander, we ware indeed in a sorry state and in need of help.", player.ship);
	
	// Add one or more $createMessage here and they will appear after status inquiring
}
this.$offerXpatEncourageTransmitCallback = function $offerXpatEncourageTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("Thank you for your gracious words, gentle spacefarer. We endeavour to keep up our spirits.", player.ship);
}
this.$demandXpatSlavesTransmitCallback = function $demandXpatSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("You heinous lowlife! We will sacrifice nobody and would sooner die together!", player.ship);
}

this._IDcounter = 1; // several ships can be spawned in one second, so clock.adjustedSeconds is not enough for ID uniqueness
this.shipSpawned = function(ship) {
	if (ship.hasRole("xpat") || ship.hasRole("xpatesc")) {
	this._bcc.$createMessage({
		messageName: "InsistXpat_slaves" + this._IDcounter++, // one counter still should be enough
		displayText: "Insist on slave offering", 
		messageText: "Puny Xpat, you don't understand. Give me my slaves or I will melt your flesh!",
		ship: ship, 
		transmissionType: "target",
		callbackFunction: this.$insistXpatSlavesTransmitCallback.bind(this, ship), 
		deleteOnTransmit: true, 
		delayCallback: 10, 
		hideOnConditionRed: false
	});
}
this.$insistXpatSlavesTransmitCallback = function $insistXpatSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("We understand, cretin. Do your worst, you will never break our spirit.", player.ship);
}
I wish the error log was a little more specific so I could spot the offender

Code: Select all

[script.javaScript.exception.curlyAfterBody]: ***** JavaScript exception (xpatComms.js.anon-script): SyntaxError: missing } after function body
Possibly I misunderstood the placement architecture of how to insert a followup, but I definitely killed a bracket somewhere in the process.
Yep, there is no closing bracket for if after last $createMessage call. But also with this code this.shipSpawned will be overwrited and only "Insist on slave offering" will be displayed on top level of conversation.
this._IDcounter also shouldn't be reasigned again - this will not break anything (the code inside the functions is executed after the entire script top level code), but it confusing.

To add an option after a previous response, add a call to $createMessage right inside the callback.

Code: Select all

this.$demandXpatSlavesTransmitCallback = function $demandXpatSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("You heinous lowlife! We will sacrifice nobody and would sooner die together!", player.ship);
	
	// the player's response to the npc's response is added here
	// no need to check for the role of the ship, because we have done this before
	this._bcc.$createMessage({
		messageName: "InsistXpat_slaves" + this._IDcounter++,
		displayText: "Insist on slave offering", 
		messageText: "Puny Xpat, you don't understand. Give me my slaves or I will melt your flesh!",
		ship: ship, 
		transmissionType: "target",
		callbackFunction: this.$insistXpatSlavesTransmitCallback.bind(this, ship), 
		deleteOnTransmit: true, 
		delayCallback: 10, 
		hideOnConditionRed: false
	});
	// there may be several answers, but the rest should be deleted somehow if they become irrelevant
}

// callback definition still can be on top level of code
this.$insistXpatSlavesTransmitCallback = function $insistXpatSlavesTransmitCallback(ship) {
	// we get here after the player has send the message, and after whatever delay was requested
	ship.commsMessage("We understand, cretin. Do your worst, you will never break our spirit.", player.ship);
	
	// you can add another response here! And so on to infinity
}
Old Murgh wrote: Sun Jul 10, 2022 4:10 pm
I wish the error log was a little more specific so I could spot the offender
I wish too! (But in this case it would only blame the last line)
Post Reply