Scripting requests

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

Cheers Ahruman, i'll give that a shot.

Thargoid, apart from my staggering ineptitude when it comes to javascript, i dunno if that would give the effect i want. the launch delay is logical etc (although i do think the stations should have some emergency rapid launch facility in case they got attacked), so i can live w/ it. the repeated launch loop, even w/ a few seconds delay, is enough to gradually swarm the attacker.

lol point in testing : i found out i'd forgotten to change my defense ship AI : it launched and just headed off happily toward the planet :-/
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

One thought - not sure if it's something desirable or feasible. We can do a lot of communicating between AIs and scripts now, but to do something on the player ship is awkward as there is no AI involved. Hence to do something like a safeScriptActionOnTarget a temporary entity would need to be spawned near the player, target them, do the command via its own AI and then be removed again.

As there are some nice tricks that can be done using sSAOT in relation ot the player ship, would a JS worldscript command which does something similar and accepts AI commands be possible?

For example something like playerShip.scriptAction("performTumble") to pick an arbitrary name for the function? Or is that mixing JS and AI too much? Just to be able to do things directly rather than the roundabout way.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

right, can't get Ahruman's script to work.

kicked it through, i got "[script.javaScript.warning.undefinedProp]: ----- JavaScript warning (newscript.js 1.0): reference to undefined property this.ship"

i tried replacingit w/ "this.station", as the wiki seemed to suggest that the "station" entity had the dockedDefenders" etc but "ship" doesn't, made no diff : "[script.javaScript.warning.undefinedProp]: ----- JavaScript warning (newscript.js 1.0): reference to undefined property this.station"

edit : tried to copy Random Hits and put in
"this.defenders = this.ship.dockedDefenders;"
and it says "reference to undefined property this.defenders"
well, didn't i just define it? >:-/

i wish we used BASIC rather than javascript, i was lush at that. BBC BASIC rocked! :-D
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Have you assigned the script to the station?

In the shipdata.plist entry for the station you need a line script = "yourscripnamehere.js"; or it's XML equivalent, replacing of course yourscriptnamehere.js with the scripts name (newscript.js from your error post).

It needs to run as a ship script not a worldscript. By doing so this.ship gets defined (as the entity attached to the script, the station in this case).
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

aye, i've done that.
does the fact i spawn it up w/ it's own role rather than "station" make an impact?
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

No.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

tch. oh well, back to the drawing board tonight!
i never thought about xml scripts, tbh, i'm assuming they might be easier to do that JS for a numpty like me, i'll have to see if there's owt on wiki that i can understand.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

If you can package it up somewhere and send me a suitable link I'll have a look at it for you when I get chance.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Commander McLane wrote:
I'd like to renew a scripting request that wasn't yet granted in 1.74:

A new event handler (world and ship scripts) as complement of shipBeingAttacked, which is sent to the attacked ship. The new handler should at the same time be sent to the attacker, with a parameter containing the entity that was hit. Should work for lasers and probably for plasma balls as well.
Added shipAttackedOther(other) to trunk.
All times ship a attacks ship b, whether intentionally or not, ship b gets shipBeingAttacked(ship a) and ship a will get shipAttackedOther(ship b).
Should do what you need! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

Thanks a lot! :D
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

From some small works I've been doing for Killer Wolf from his request above, we've noticed some issues with the launch queue and defense ships. When a station is fired upon, it seems to take a horribly long time (up to a minute) between first shot hitting and defense ships being launched.

Would it be possible to have the defense ships "jump the queue" and get out more immediately when they are actually needed? In one or two cases I've seen them stuck behind a trader coming out, or in others they just take forever. Maybe a command to immediateLaunch <role> or equivalent for the specific commands for ships like defenseShips?
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

Expose missile_load_time to JS, as a read/write Ship property. Reason: not being able to change the time interval for an existing ship strikes me as unflexible. As it seems now, the time determined in shipdata cannot be altered by script, and even Ship.fireMissile() will automatically wait for the predetermined time.

I would like more flexibility for the AI, which would allow an NPC to at least fire a full salvo in retaliation before it goes puff.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Commander McLane wrote:
Expose missile_load_time to JS, as a read/write Ship property. Reason: not being able to change the time interval for an existing ship strikes me as unflexible. As it seems now, the time determined in shipdata cannot be altered by script, and even Ship.fireMissile() will automatically wait for the predetermined time.

I would like more flexibility for the AI, which would allow an NPC to at least fire a full salvo in retaliation before it goes puff.
Not really needed. Don't define a missile_load_time and define zero missiles. With a script you can add a missile to the ship and than fire it. And to prevent the use of unlimited missiles, you can keep a counter in your ship script.
That is what I did with the astrominers in random_hits. They shoot pods in the form of missiles to the hopper for collecting it. But code dictated that 1 out of ten fired missiles is from the random set. By adding explicit missiles by script, I still keep control over what is shot and you even can make your own mix of fired missiles.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Commander McLane wrote:
Expose missile_load_time to JS, as a read/write Ship property. Reason: not being able to change the time interval for an existing ship strikes me as unflexible. As it seems now, the time determined in shipdata cannot be altered by script, and even Ship.fireMissile() will automatically wait for the predetermined time.
missile_load_time has been exposed to JS in r3662. The JS property is called missileLoadTime, is read/write and has to be a positive number.
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

Great! :D
Post Reply