Oolite Bulletins

For information and discussion about Oolite.
It is currently Fri Sep 22, 2017 9:51 am

All times are UTC




Post new topic  Reply to topic  [ 1387 posts ]  Go to page Previous 186 87 88 89 9093 Next
Author Message
 Post subject: Re: Scripters cove
PostPosted: Mon Jan 04, 2016 2:46 am 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 12, 2015 2:30 pm
Posts: 591
Location: Bavaria, Germany
This creates an incredible amount of orphaned escorts if I don't remove them as well! :lol:

_________________
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"


Top
   
 Post subject: Re: Scripters cove
PostPosted: Wed Jan 06, 2016 10:26 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4012
Quote:
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?
Add the ship with the square brackets role, then immediately update ship.primaryRole to whatever you want (which can include roles that the ship can't normally have, if you want)

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripters cove
PostPosted: Wed Jan 06, 2016 10:32 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 12, 2015 2:30 pm
Posts: 591
Location: Bavaria, Germany
I thought about this, but what I wanted to test is done in shipSpawned(), and it is depending from role, so changing it later would be too late.

_________________
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"


Top
   
 Post subject: Re: Scripters cove
PostPosted: Thu Jan 07, 2016 9:53 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4012
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:
var ships = system.addShips(...);
ships[0].primaryRole = "trader";
then it will be set before the shipSpawned event.

It doesn't have to be on the next line - any time before you return from the function will do.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripters cove
PostPosted: Thu Jan 07, 2016 10:42 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 12, 2015 2:30 pm
Posts: 591
Location: Bavaria, Germany
That's interesting. I didn't know this, and I'll try it immediately!

Edit: It works perfectly, thank you!

_________________
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 08, 2016 1:16 pm 
Offline
Deadly
Deadly

Joined: Tue Nov 10, 2015 1:59 pm
Posts: 175
Background (background, setScreenBackground()) and screen overlay (overlay, setScreenOverlay()) are the only two layers of screenbackgrounds one can use to create a background, right? Or is there another possibility? Another possible, undocumented parameter of setScreenOverlay()?
Something like:
[color=#000080][i]setScreenOverlay("bottomLayer.png",0);
setScreenOverlay("middleLayer.png",1);
setScreenOverlay("topLayer.png",5);[/i][/color]

too add more.

EDIT: And while I'm at backgrounds. Shouldn't
bgImage =
{name: "example.png",
height: 768};
setScreenBackground(bgImage);

create a background, that at least has been scaled down to height 480 ("default" screen height)? Or even more preferable isn't scaled down, but fitted to the screen to provided a background with a higher resolution? (example.png would be an image with a resolution of 1366x768 in my example)


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 15, 2016 9:42 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 12, 2015 2:30 pm
Posts: 591
Location: Bavaria, Germany
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 wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 15, 2016 10:04 pm 
Offline
Deadly
Deadly

Joined: Tue Nov 10, 2015 1:59 pm
Posts: 175
Quote:
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.
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.


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 15, 2016 10:10 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Wed Aug 15, 2012 4:19 am
Posts: 2456
Location: Finland
Quote:
Quote:
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.
shipKilledOther I hope that's what you were looking for.
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.


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 15, 2016 10:27 pm 
Offline
Deadly
Deadly

Joined: Tue Nov 10, 2015 1:59 pm
Posts: 175
naahh, too bad. The wikis description read like it would be what fritz was looking for.


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 15, 2016 11:20 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Mon May 20, 2013 9:53 pm
Posts: 2392
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Quote:
Is there a simple method to detect the death of a NPC entity without having to use a ship script or a timer function?
You can inject your code in shipSpawned into the shipDied function of the ship's script. For example:
Code:
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);
        }
    }
}

_________________
OXPs by Norby


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Jan 15, 2016 11:29 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 12, 2015 2:30 pm
Posts: 591
Location: Bavaria, Germany
Yes, "shipKilledOther" doesn't have a "ship" parameter either. What I'm looking for really seems to be missing, but probably the situations where you can use it, are rare. In my case, I simply want to detect a rock hermit being destroyed (usually by somebody else). But I also was thinking about tracking the fate of certain NPC ships, for example how often they get destroyed by other NPCs.

Adding a ship script for core ships would be possible by using shipdata-overrides.plist, but this will probably turn into a nightmare if another OXP (in this case, Spicy Hermits) has already added a ship script. I assume, there can't be two ship scripts for a single entity. (I wrote this sentence before reading Norby's suggestion).
Quote:
You can inject your code in shipSpawned into the shipDied function of the ship's script.
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 wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sat Jan 16, 2016 11:01 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Wed Aug 15, 2012 4:19 am
Posts: 2456
Location: Finland
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?


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sat Jan 16, 2016 11:58 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Sat Oct 20, 2007 2:52 pm
Posts: 2264
Quote:
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?
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.

And as sidenote: Injection (or monkey-patching) is dangerous. In the end every AddOn developer looses the capability to control his own content and runtime behaviours of his/her own scripts. And clashes caused by this kind of thing are nearly impossible to spot. Choose a cleaner approach whenever you can.


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sat Jan 16, 2016 3:30 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 12, 2015 2:30 pm
Posts: 591
Location: Bavaria, Germany
Quote:
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 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.
Quote:
Often there might also be some other ways to achieve what one desires. What are you trying to achieve?
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.

I had the idea to add the beacon to a "visual effect" at the same position as the hermit, as this would (hopefully!) survive the destruction. Then, on saving or leaving the system, I could check all beacons if the associated hermit is still there. So there are definitely other methods, but I didn't want to do something unnecessarily complicated only because I didn't find a suitable event handler! That's why I asked.

If Norby's suggestion works (I'll probably know this evening), that's exactly what I need. But I'll try the "visual effect" method too, because it has another advantage: The ASC wouldn't lose it's target when the hermit is destroyed while it is set in the compass, and that's the intended behaviour.

For both methods, I wouldn't need to override shipdata.plist and introduce my own ship script. It would even work with OXP rock hermits with different data_keys and models, as long as they stick to the usual roles. And it would work with or without Spicy Hermits, and without you having to change anything!

_________________
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1387 posts ]  Go to page Previous 186 87 88 89 9093 Next

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited