Re: Scripters cove
Posted: Mon Jan 04, 2016 2:46 am
This creates an incredible amount of orphaned escorts if I don't remove them as well!
For information and discussion about Oolite.
https://bb.oolite.space/
Add the ship with the square brackets role, then immediately updateFritz wrote:system.addShips() can add ships with a certain role. I don't know where I have read it (it isn't documented in the wiki), but the method can also add ships of a certain type if the type name is enclosed in square brackets. But in the latter case, the ships don't seem to have a role, which can be bad for testing. I wonder if there is a possibility to add ships of a certain type in a specific role, like, for example, a Boa trader?
ship.primaryRole
to whatever you want (which can include roles that the ship can't normally have, if you want)shipSpawned
is called the first time the ship is updated by the core game loop, not immediately when it's added. If you do
Code: Select all
var ships = system.addShips(...);
ships[0].primaryRole = "trader";
shipSpawned
event.[color=#000080][i]setScreenOverlay("bottomLayer.png",0);
setScreenOverlay("middleLayer.png",1);
setScreenOverlay("topLayer.png",5);[/i][/color]
bgImage =
{name: "example.png",
height: 768};
setScreenBackground(bgImage);
shipKilledOther I hope that's what you were looking for. You have to test though, if colliding with something or burning up in a sun also triggers it.Fritz wrote:Is there a simple method to detect the death of a NPC entity without having to use a ship script or a timer function? There is a world script "shipSpawned" event for everything, but the world script "shipDied" event seems to be only for the player ship, because it hasn't a "ship" parameter.
To my understanding, this only triggers for the ship that killed the other. So if it's in a workscript, it triggers for player, if it's in a ship script, it triggers forthe ship scoring the kill.ocz wrote:shipKilledOther I hope that's what you were looking for.Fritz wrote:Is there a simple method to detect the death of a NPC entity without having to use a ship script or a timer function? There is a world script "shipSpawned" event for everything, but the world script "shipDied" event seems to be only for the player ship, because it hasn't a "ship" parameter.
You can inject your code in shipSpawned into the shipDied function of the ship's script. For example:Fritz wrote:Is there a simple method to detect the death of a NPC entity without having to use a ship script or a timer function?
Code: Select all
this.shipSpawned = function(ship) {
if(ship && ship.dataKey == "yourship") {
if(!ship.script) ship.script = "oolite-default-ship-script.js";
ship.script.shipDiedOrig = ship.script.shipDied;
ship.script.shipDied = function(whom, why) {
player.consoleMessage(this.ship.name+" shipDied "+whom+" "+why);
if(this.shipDiedOrig) this.shipDiedOrig(whom, why);
}
}
}
This looks interesting! I'll have to try it but it looks like this actually could work. Being rather new to JavaScript, I'm not used to the concept of creating new functions during runtime...You can inject your code in shipSpawned into the shipDied function of the ship's script.
Yes, please find a general way instead of aiming for a two AddOns coop only. It has shown many times already that earlier or later it gets messy pretty soon.spara wrote:Instead of injecting, co-operation is also possible :) . If it's just Spicy Hermits, then I'm 100% absolutely, positively sure we can find a way to get the OXPs work together.
Often there might also be some other ways to achieve what one desires. What are you trying to achieve?
I know! But in theory, somebody else could have introduced a ship script too. For Spicy Hermits I could easily find a solution even without your cooperation, because I know your OXP, but there are hundreds of OXPs around, and some of their creators aren't even available anymore. So I would like to find solutions that should, at least in theory, work with OXPs unknown to me. A world script "shipDied" event would have been the easiest way as is the "shipSpawned" event for situations where you don't want to add a ship script.spara wrote:Instead of injecting, co-operation is also possible . If it's just Spicy Hermits, then I'm 100% absolutely, positively sure we can find a way to get the OXPs work together.
I simply want to record the death event of a rock hermit, because I have to mark the destroyed hermit in the memory database. You use a ship script, but you need it anyhow.Often there might also be some other ways to achieve what one desires. What are you trying to achieve?