OXP idea: Escape capsule locator
Moderators: winston, another_commander
-
- Poor
- Posts: 4
- Joined: Mon Sep 06, 2010 6:44 am
OXP idea: Escape capsule locator
Hi,
I found really simple to change the color the escape capsule is drawn in scanner, by changing the shipdata.plist.
But I'd like to create an additional equipment providing the same option, using Javascript.
I know how to create the equipment and that I can use the scannerdisplaycolor1(2) properties to set the colors, but I have no idea about how to say to Oolite to assign that color to the EscapeCapsule.
In other words, how should I write the javascript?
My idea is something like (pseudo-code)
"if equipment is installed and working, when new ship is added, if its name/type/role is EscapeCapsule, then scannerdisplaycolor1=... else retain normal (white) color" but I'm not sure this is the right way and which function to call.
Can someone suggest me something or implement this so I can read how to do that? I've no interest in this idea's credits or something similar, but I'm really interested in understanding the way to do this thing.
Thanks a lot
I found really simple to change the color the escape capsule is drawn in scanner, by changing the shipdata.plist.
But I'd like to create an additional equipment providing the same option, using Javascript.
I know how to create the equipment and that I can use the scannerdisplaycolor1(2) properties to set the colors, but I have no idea about how to say to Oolite to assign that color to the EscapeCapsule.
In other words, how should I write the javascript?
My idea is something like (pseudo-code)
"if equipment is installed and working, when new ship is added, if its name/type/role is EscapeCapsule, then scannerdisplaycolor1=... else retain normal (white) color" but I'm not sure this is the right way and which function to call.
Can someone suggest me something or implement this so I can read how to do that? I've no interest in this idea's credits or something similar, but I'm really interested in understanding the way to do this thing.
Thanks a lot
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
Re: OXP idea: Escape capsule locator
Let's assume that the equipment you have is called "EQ_ESCAPE_CAPSULE_LOCATOR" and that your OXP is called EscapePodLocator.oxp. You need a world script. Let's call it escapePodLocator.js. Inside that, you put:alocritani wrote:Hi,
I found really simple to change the color the escape capsule is drawn in scanner, by changing the shipdata.plist.
But I'd like to create an additional equipment providing the same option, using Javascript.
I know how to create the equipment and that I can use the scannerdisplaycolor1(2) properties to set the colors, but I have no idea about how to say to Oolite to assign that color to the EscapeCapsule.
In other words, how should I write the javascript?
My idea is something like (pseudo-code)
"if equipment is installed and working, when new ship is added, if its name/type/role is EscapeCapsule, then scannerdisplaycolor1=... else retain normal (white) color" but I'm not sure this is the right way and which function to call.
Can someone suggest me something or implement this so I can read how to do that? I've no interest in this idea's credits or something similar, but I'm really interested in understanding the way to do this thing.
Thanks a lot
Code: Select all
this.shipSpawned = function(ship)
{
if (ship.primaryRole == "escape-capsule" && player.ship.equipmentStatus("EQ_ESCAPE_CAPSULE_LOCATOR") == "EQUIPMENT_OK")
{
ship.scannerDisplayColor1 = "grayColor"; // or any [r, g, b, a]
ship.scannerDisplayColor2 = "orangeColor"; // or any [r, g, b, a]
}
}
Now you need to tell Oolite that this is a world script, i.e. it is applicable to player and all ships that are spawned. To do this, save a file called world-scripts.plist inside EscapePodLocator.oxp/Config, containing the following:
Code: Select all
(
"escapePodLocator.js"
)
I hope this is clear enough to get you started. If not, just ask. Quick and dirty version of the OXP is here (link will be valid for 15 days):
http://terrastorage.ath.cx/Marmagka/01e ... or.oxp.zip
-
- Poor
- Posts: 4
- Joined: Mon Sep 06, 2010 6:44 am
Thanks a lot, I've seen your OXP and it's exactly what I was looking for.
if I understand correctly, if I want to apply my script only to my ship I should create a script and refer to it in shipdata.plist while if the script should apply to all ships it should be referred in word-scripts.plist
But now I've another question: if the equipment become damaged, how can I change back the color? I know I can use ship.scannerDisplayColor1=null to bring back the original color, but how can I change the value for every ship?
My idea is, always in escapePodLocator.js:
what do you think? Do I have to define escape_capsule in some way in order to let the system know it's a ship entity?
thanks again!
if I understand correctly, if I want to apply my script only to my ship I should create a script and refer to it in shipdata.plist while if the script should apply to all ships it should be referred in word-scripts.plist
But now I've another question: if the equipment become damaged, how can I change back the color? I know I can use ship.scannerDisplayColor1=null to bring back the original color, but how can I change the value for every ship?
My idea is, always in escapePodLocator.js:
Code: Select all
this.shipBeingAttacked = this.shipBeingAttackedByCloaked = function()
{
if(player.ship.equipmentStatus("EQ_ESCAPE_CAPSULE_LOCATOR") == "EQUIPMENT_DAMAGED")
{
for (escape_capsule in system.shipsWithRole("escape-capsule")){
escape_capsule.scannerDisplayColor1=null;
escape_capsule.scannerDisplayColor2 = null;
}
}
}
thanks again!
Have a look at my OXP Target Autolock Plus (via the links in my sig below). That recolours the scanner lollipop of your current target, so is along similar lines.
You can refer to the script in the shipdata.plist script of the players ship, but that will then only work for that ship (and for an OXP you'd have to supply the ship). By using the world-scripts.plist file that A_C mentioned it will work for any player ship. World scripts are essentially scripts run on the current player, regardless of what ship they are flying.
And for your code below, that will only trigger if a ship (cloaked or otherwise) attacks you (the player), and in that case would reset the escape capsules lollipops to default. That said for (escape_capsule in system.shipsWithRole("escape-capsule")) isn't valid javascript, you need something like:
or something along those lines (above code is untested but along the right lines). this.capsules is an array formed of all ships in the system that have the role "escape-capsule". If there are any (ie the array has non-zero length) then the loop steps through them in turn and makes the change. There are other ways to do it that act on all items in the array, but personally I prefer loops as they are clearer.
Look over my OXP, that should give you a framework on doing things, or examine A_C's.
You can refer to the script in the shipdata.plist script of the players ship, but that will then only work for that ship (and for an OXP you'd have to supply the ship). By using the world-scripts.plist file that A_C mentioned it will work for any player ship. World scripts are essentially scripts run on the current player, regardless of what ship they are flying.
And for your code below, that will only trigger if a ship (cloaked or otherwise) attacks you (the player), and in that case would reset the escape capsules lollipops to default. That said for (escape_capsule in system.shipsWithRole("escape-capsule")) isn't valid javascript, you need something like:
Code: Select all
this.capsules = system.shipsWithRole("escape-capsule");
if(this.capsules.length > 0)
{
let i=0;
for(i=0;i<this.capsules.length;i++)
{
this.capsules[i].scannerDisplayColor1 = null;
this.capsules[i].scannerDisplayColor2 = null;
}
}
Look over my OXP, that should give you a framework on doing things, or examine A_C's.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
I think only the shipSpawned event is recognized in world scripts. Unless something changed recently and I missed it, acting on all ships is possible only with shipSpawned. Basically, world scripts are performed on events happening from the player side, while ship specific scripts are, well, specific to the ships they refer to. In your case, shipBeingAttacked will be executed only when the player is attacked, because there is no generic handling for all ships for this event.
However, there is the equipmentDamaged handler, which can be inserted in escapePodLocator.js. Once you detect that your pod locator is damaged, you can use your code to reset colors. Haven't checked it, but it should be
However, there is the equipmentDamaged handler, which can be inserted in escapePodLocator.js. Once you detect that your pod locator is damaged, you can use your code to reset colors. Haven't checked it, but it should be
Code: Select all
this.equipmentDamaged = function (eqKey)
{
if (eqKey == "EQ_ESCAPE_CAPSULE_LOCATOR")
{
... rest of your code ...
}
}
Personally I'd either use a timer that's started on launch and stopped on docking/equipment damage and the sort of scan I gave previously. But that's a little more complex than the code above.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
Oh! I had no idea that shipSpawned in a worldscript is triggered for NPCs as well. The documentation isn't very clear about it. Could one of you improve it according to what the handler actually does?
Also, IMO the parameter shouldn't be named "whom", because that sounds like it would contain the entity by whom the ship was spawned, which is misleading and often wouldn't make sense anyway. I think it should simply be renamed to "ship".
Also, IMO the parameter shouldn't be named "whom", because that sounds like it would contain the entity by whom the ship was spawned, which is misleading and often wouldn't make sense anyway. I think it should simply be renamed to "ship".
It's listed in ship script events too, which technically would be the NPC version (although it's the same function).
For me the converse was true, that shipSpawned actually fires for the player ship in place of this.startUp if the script is linked to the player ship via shipdata.plist. If you are using the script for a specific player ship then you have to use shipSpawned instead (as I had to do last night for a new WIP player ship).
That said I'd never noticed the whom parameter either until you mentioned it. But for me it doesn't seem to do anything at all - I would agree it should return the entity that spawned the ship.
For me the converse was true, that shipSpawned actually fires for the player ship in place of this.startUp if the script is linked to the player ship via shipdata.plist. If you are using the script for a specific player ship then you have to use shipSpawned instead (as I had to do last night for a new WIP player ship).
That said I'd never noticed the whom parameter either until you mentioned it. But for me it doesn't seem to do anything at all - I would agree it should return the entity that spawned the ship.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Its a new feature added to 1.74. Before, the shipSpawned event was only send to the shipScript but since 1.74 it is in addition also send to the worldScript.Commander McLane wrote:Oh! I had no idea that shipSpawned in a worldscript is triggered for NPCs as well. The documentation isn't very clear about it. Could one of you improve it according to what the handler actually does?
Also, IMO the parameter shouldn't be named "whom", because that sounds like it would contain the entity by whom the ship was spawned, which is misleading and often wouldn't make sense anyway. I think it should simply be renamed to "ship".
I think that this fact has never put in the wiki. And reading the history of that page is a bit confusing because it shows that the handler was there for ages. Truth is that it used to be a page for both world & ship scripts. At some point it was split in two versions but the info was never updated accordingly.
I just edited the text a bit to make clear its a new feature in 1.74 and changed the "whom" to "ship" as suggested.
UPS-Courier & DeepSpacePirates & others at the box and some older versions
Re: OXP idea: Escape capsule locator
Would it be possible to have this OXP available again?
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
Re: OXP idea: Escape capsule locator
The OXP in preliminary, barely tested form (actually, not tested at all with 1.75.3), has been uploaded here:
http://www.box.net/shared/hngzh2jmx67royok2npo
I do not intend to maintain it, anyone who is willing to take it and develop it further, feel free to do so.
http://www.box.net/shared/hngzh2jmx67royok2npo
I do not intend to maintain it, anyone who is willing to take it and develop it further, feel free to do so.
- Wildeblood
- ---- E L I T E ----
- Posts: 2453
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: OXP idea: Escape capsule locator
I just added
beacon="e";
to the escape capsules' shipdata when I wanted to make them easier to find.- Capt. Murphy
- Commodore
- Posts: 1127
- Joined: Fri Feb 25, 2011 8:46 am
- Location: UK South Coast.
Re: OXP idea: Escape capsule locator
You could very easily adapt the code from Police IFF Scanner to do this.
It's basically doing exactly the same thing but looking at ships with a bounty.
Link in my signature.
It's basically doing exactly the same thing but looking at ships with a bounty.
Link in my signature.
Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
Re: OXP idea: Escape capsule locator
I think that a Police Scanner should have this functionality in there by default. The Police have a duty to protect as well, and identifying an assisting people in distress falls within their realm.Capt. Murphy wrote:You could very easily adapt the code from Police IFF Scanner to do this.
It's basically doing exactly the same thing but looking at ships with a bounty.
Link in my signature.
Didn't there use to be an OXP with a ship that ran around doing that. Would make a good role for Staer9's Chopped Cobra. Oolite ambulance and rescue service running around with Chopped Cobras (Red Cross on each wing) with Role Police but scoping escape pods and bringing them back to the main station. Would need a separate AI. I'm going to dive into the Wiki to have a look.
Edit: Found it, Cobra Clipper SAR here
"A brilliant game of blasting and trading... Truly a mega-game... The game of a lifetime."
(Gold Medal Award, Zzap!64 May 1985).
(Gold Medal Award, Zzap!64 May 1985).