Page 61 of 117

Re: Scripters cove

Posted: Fri Feb 01, 2013 1:01 am
by GGShinobi
Thargoid wrote:

So the simplest way is to take your initial script, and adjust it to

Code: Select all

this.shipDied = function(whom, why) {
   if (Math.random() > 0.77) {
      this.ship.spawn("energy-bomb",1);
   }
where energy-bomb is one of the roles of the trunk q-bomb. Use that function definition to replace the one in your first script, keeping the header information (this.name etc) from your code above.[/color]
Thargoid, thanks for that info - it almost works as I want. Funny thing is, this is very close to my initial code, which looked like this:

Code: Select all

this.shipDied = function(whom, why) {
   if (Math.random() > 0.77) {
      system.addShips("energy-bomb", 1, this.ship.position, 0);
   }
But unfortunately, it didn't work :-( don't know why.

As I said, your code worked almost perfectly, but there a two minor drawbacks that I don't know how to resolve:
  • the q-bomb is spawned near the last position of the Star Destroyer, but not near enough to look like it's the explosion from the Star Destroyer.
    • Now that I write these lines I think it might be that the Q-Mine got drifted away by the shockwave of the exploding Star Destroyer? If this is the cause, is there a way I can prevent this?
  • I can't set the time after which the Q-Bomb should spawn. For my purpose, that's no big deal, because the preset countdown of the Q-Bomb pretty much matches the time that I would have set anyway... but just out of curiosity, would it be possible to spawn the bomb after, let's say 5 seconds? :roll:
If anyone wonders how I manage to pulverize a StarDestroyer so easily: My savegame is at Xeer, the Navy Headquarters, and I've got a test-script that spawns a StarDestroyer near the station when I launch. All I have to do is wait a few seconds - the Star Destroyer is very aggressive and attacks everything in range. The navy then does the dirty work for me, whilst I hide behind the station and watch! :D :lol:
Hey, who just called me a dishonorable coward?!? :evil:

Re: Scripters cove

Posted: Fri Feb 01, 2013 6:51 am
by Thargoid
Yes it is possible, and it will go back somewhat towards where your script went in having a worldScript to start a timer to spawn the thing. An alternative route is to use a specially coded entity rather than the trunk qBomb, with an AI/script to either hide it from the scanner for 5s before making it appear (hence simulating the delay) or spawning it somewhere else and then moving it to the relevant location after the delay. Either way will work but will be more complex code.

One other point from your previous code version - it isn't possible to pass parameters to a timer in the way you were doing. You either have to get fancy with the function definition and binding, or more simply just pass the parameters via a suitably scoped variable.

You are right that the spawned entity will be close but not exactly on the old position, but that can be done by something like the addShips line you quoted. But as you say in either case then your entity will get affected (moved) by the Star Destroyer and its explosion anyway so it's a bit academic, mainly due to the qBomb needing to exist for the 5s for its countdown. Normally when this kind of trick is used, it's for an immediate enhanced (but non-quirium) explosion rather than the pop in a blue cloud. Where that happens (such as the Purple Haze that Eric correctly identifies as being the ship I meant before) as noted it tends to get very irritating and the OXP removed or lobotomised.

Re: Scripters cove

Posted: Fri Feb 01, 2013 7:32 am
by Rorschachhamster
I just thought... wouldn't it be possible to spawn a wrecked stardestroyer on destruction of the original one with the properties of a q-bomb? That way the q-bomb wouldn't be diplaced as it is the stardestroyer :?:
EDIT: And even if it is displaced by the shockwave, you would see the stardestroyer drift aimlessly before... boom. If I'm not mistaken...

Re: Scripters cove

Posted: Fri Feb 01, 2013 10:25 am
by Commander McLane
Rorschachhamster wrote:
I just thought... wouldn't it be possible to spawn a wrecked stardestroyer on destruction of the original one with the properties of a q-bomb? That way the q-bomb wouldn't be diplaced as it is the stardestroyer :?:
EDIT: And even if it is displaced by the shockwave, you would see the stardestroyer drift aimlessly before... boom. If I'm not mistaken...
Yes, sure. Just spawn a clone of the ship, and give it a clone of timebombAI. (Just giving it timebombAI will create an incompatibility for players who have [wiki]Status Quo Q-bomb OXP[/wiki] installed, unless you also give your ship clone the script contained in that OXP.)

Re: Scripters cove

Posted: Fri Feb 01, 2013 11:16 pm
by GGShinobi
Thanks y'all for your awesome answers! :D

Rorschachhamster, excellent :!: idea of replacing the ship with a drifting version of itself... and thanks to Thargoid and Commander McLane for the info on how it can be done! That's what I'm gonna do :idea: :P
Thargoid wrote:

One other point from your previous code version - it isn't possible to pass parameters to a timer in the way you were doing. You either have to get fancy with the function definition and binding, or more simply just pass the parameters via a suitably scoped variable.
That's very interesting... I see I'll have to read more about JavaScript in order to understand what's going on.

And since I stole spara his answers (sorry spara) and because I'd like to know the answer to his question, too:
spara wrote:
I want to check if certain key exists in a descriptions.plist. At the moment I'm doing something like this:

Code: Select all

var key = expandDescription("[foo]");
if (key == "[foo]") 
//key not found
Not exactly a clean solution, :D as using expandDescription seems to thrown a JS warning. Is there some nice elegant way to do this check?
Has anyone an answer for this? :?: :)

Re: Scripters cove

Posted: Sat Feb 02, 2013 3:32 pm
by Lone_Wolf
GGShinobi wrote:
And since I stole spara his answers (sorry spara) and because I'd like to know the answer to his question, too:
spara wrote:
I want to check if certain key exists in a descriptions.plist. At the moment I'm doing something like this:

Code: Select all

var key = expandDescription("[foo]");
if (key == "[foo]") 
//key not found
Not exactly a clean solution, :D as using expandDescription seems to thrown a JS warning. Is there some nice elegant way to do this check?
Has anyone an answer for this? :?: :)
wiki wrote:
Whenever Oolite reads in a scriptline, missiontext or description, it first looks for something between brackets. If it finds something it looks to see if it is a mission_variable. If yes, it replaces the name of the variable with its content. Then it looks in the descriptions.plist. If it finds a key, it replaces the name with the string content. If it is an array it picks at random one of the strings.
While it isn't stated what happens if the stuff between brackets doesn't exist, a fair asumption seems to be it will return a null value.
In that case, a simple test for null should work :

Code: Select all

if ( [foo] == null )
{
 // key not found
};

Re: Scripters cove

Posted: Sat Feb 02, 2013 7:41 pm
by Tricky
Use missiontext.plist and expandMissionText. If the string doesn't exist then null is returned, not an error.

Code: Select all

var key = expandMissionText("foo");
if (!key)
//key not found
Note the lack of square brackets.

make subentities temporarily undestructible ("shield expande

Posted: Tue Feb 05, 2013 5:52 pm
by GGShinobi
I thought about doing an OXP which allows the ship to "extend" it's shields so that subentities are also covered and can't be destroyed as long as the shields are active (or at least are sufficently charged to, let's say, 20%). I thought this would be easy by just toggling ship.isFrangible, but now I found in the wiki that it is read only :( What's the reason for this? Any suggestions for an (preferably easy) workaround?

The reason why I want such an oxp: my cheat-ship for tests is a Falcon-S, which has many destroyable sub-entities. During battle, these subentities often get destroyed, which as itself would be fine with me, but it somehow doesn't feel right the way it works now. I have to do maintenance overhaul almost all the time, even if I fight against clearly inferior opposition. I'd rather have it that the subentities should be able to take damage only after my shields got drained.

I know I could do other things like turning "isFrangible" off or even raise the energy and/or energy-recharge rate of the subentities, but that would not be (as) cool :P

Re: Scripters cove

Posted: Tue Feb 05, 2013 5:56 pm
by Smivs
Is restoreSubEntities what you are looking for?

Re: Scripters cove

Posted: Tue Feb 05, 2013 5:58 pm
by cim
Give the subentities a ship script that checks the shields of the parent entity, and reassigns damage appropriately?

But I'm inclined to think this is a bug: those rare ships that have both frangible subents and shields should obviously have the shields cover the subents too.

Re: Scripters cove

Posted: Tue Feb 05, 2013 6:21 pm
by GGShinobi
Smivs wrote:
Is restoreSubEntities what you are looking for?
Hmm, good idea but no, because that would make the subentities act like super-shields since they absorb the damage that would hit my shields if the subentities weren't there. If I restore them as soon as they are destroyed my ship would become almost invincible! :?
cim wrote:
Give the subentities a ship script that checks the shields of the parent entity, and reassigns damage appropriately?
I also had this thought, but I don't know how I can do this to work with all ships. As far as I understand, for the events "shipIsBeingAttacked" to be catched I have to implement the function in the attacked ships' script, or in my case, in the script for the attacked subentity. Or is it possible to make a function which is called whenever any ship is attacked, and then check if it was one of my subentities? (sounds complicated...) Since I'd like to make a purchasable equipment, it should work without changing existing ship scripts.
cim wrote:
But I'm inclined to think this is a bug: those rare ships that have both frangible subents and shields should obviously have the shields cover the subents too.
Hmm, I also thought that this is a strange behaviour. But I can definitely confirm that on my system, when the Falcon-S get's hit, most of the time my shields receive no damage but one of the subentities instead!

If that's a bug then there is no need for such an oxp?! :D Fine with me! :mrgreen:

Possibilities of ship scripting

Posted: Thu Feb 07, 2013 10:51 pm
by GGShinobi
The "Master Artist Natural Definitive Of Magnificent Artwork Nobles" (mandoman) is currently creating a very fine spaceship that I "ordered". But since the original has several moveable parts we wonder if it is possible to make the ingame-model have those parts moveable, too. He advised me to pass this question on to the experienced scripters of this community! :)

In particular we'd like to know if it would be possible to:
  • make "wings" fold and "fins" retract a little when approaching a station aegis, so it becomes easier to dock, and also fold "radar-ears"
  • have some special animations when approaching a planet or a sun (e.g. fold "radar-ears")
  • make "wings" rotate (fast) when using jump (torus) drive
  • make "wings" rotate (slowly first, getting faster) when initiating hyperspace-jump
  • replace the ship/surround it with a comet tail when it activates the jump drive, so that it looks like a real comet? :?:
* (for a better understanding of what I mean with "wings", "fins" and "radar-ears", please have a look at this image (the same as in the link above): http://imageshack.us/a/img545/1778/comet3.png)

Another question is about the possibility to have the ship's thrusters "toggle" between different directions. The original of the ship mandoman is building (the comet) has the ability to start vertically, due to it's thrusters that are pointing downwards. It can also dodge in pretty much any direction because it has thrusters "everywhere". And it can fly (much faster) forward by using the normal thrusters (those in the wings and the main thruster located at rear). Would it somehow be possible to simulate that (fully or partially) in Oolite? :?:

That's it... but while I'm at it, here another question regarding my previous post (that one above):
GGShinobi wrote:
cim wrote:
But I'm inclined to think this is a bug: those rare ships that have both frangible subents and shields should obviously have the shields cover the subents too.
Hmm, I also thought that this is a strange behaviour. But I can definitely confirm that on my system, when the Falcon-S get's hit, most of the time my shields receive no damage but one of the subentities instead!

If that's a bug then there is no need for such an oxp?! :D Fine with me! :mrgreen:
  • Then shall I send a bug report because of this?
  • Can anyone confirm this behaviour? Perhaps with other ships? (The Falcon-S is the only ship with frangible subentities that I've flown so far I think)

Re: Possibilities of ship scripting

Posted: Thu Feb 07, 2013 11:07 pm
by cim
GGShinobi wrote:
In particular we'd like to know if it would be possible to:
  • make "wings" fold and "fins" retract a little when approaching a station aegis, so it becomes easier to dock, and also fold "radar-ears"
  • have some special animations when approaching a planet or a sun (e.g. fold "radar-ears")
  • make "wings" rotate (fast) when using jump (torus) drive
  • make "wings" rotate (slowly first, getting faster) when initiating hyperspace-jump
Yes, provided those bits are done as subentities, their position and orientation relative to the main ship body may be changed in a frame callback.
GGShinobi wrote:
  • replace the ship/surround it with a comet tail when it activates the jump drive, so that it looks like a real comet? :?:
Surround would be easier, and a Visual Effect is probably the easiest way to do that. Again, frame callbacks to position and orient.
GGShinobi wrote:
Another question is about the possibility to have the ship's thrusters "toggle" between different directions. The original of the ship mandoman is building (the comet) has the ability to start vertically, due to it's thrusters that are pointing downwards. It can also dodge in pretty much any direction because it has thrusters "everywhere". And it can fly (much faster) forward by using the normal thrusters (those in the wings and the main thruster located at rear). Would it somehow be possible to simulate that (fully or partially) in Oolite? :?:
The exhaust plumes always point straight backwards. Similarly, under conventional thrust, the ship will always fly forwards. However, you can again use script to change its position in other directions.

No need to send a bug report for the other one - it's already on my list to look at.

Re: Possibilities of ship scripting

Posted: Fri Feb 08, 2013 1:19 am
by GGShinobi
Thank you cim! That's awesome news! 8) I'll see if I can find out how it is done, if I get stuck I know where I can ask :wink:
cim wrote:
No need to send a bug report for the other one - it's already on my list to look at.
Cool, thanks! :mrgreen:

Re: Possibilities of ship scripting

Posted: Fri Feb 08, 2013 1:47 am
by Tricky
GGShinobi wrote:
In particular we'd like to know if it would be possible to:
  • make "wings" fold and "fins" retract a little when approaching a station aegis, so it becomes easier to dock, and also fold "radar-ears"
  • have some special animations when approaching a planet or a sun (e.g. fold "radar-ears")
  • make "wings" rotate (fast) when using jump (torus) drive
  • make "wings" rotate (slowly first, getting faster) when initiating hyperspace-jump
  • replace the ship/surround it with a comet tail when it activates the jump drive, so that it looks like a real comet? :?:
* (for a better understanding of what I mean with "wings", "fins" and "radar-ears", please have a look at this image (the same as in the link above): http://imageshack.us/a/img545/1778/comet3.png)
Take a look at Thargoid's Butterflies Callback demo OXP. Not sure if this still works as I have never seen a butterfly in my ooniverse lately. No reason why it shouldn't.