Speed
Moderators: winston, another_commander
- Rustybolts
- ---- E L I T E ----
- Posts: 293
- Joined: Sun Jun 07, 2009 6:22 pm
- Location: UK
Speed
How do you find out how fast a player ship is traveling using java script.
Eg i want some code to run if a certain speed is met.
Eg i want some code to run if a certain speed is met.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
From what it says in the following wiki page
http://wiki.alioth.net/index.php/Oolite ... ence:_Ship
I'd say you probably want
the raw player.ship.speed might not be too helpful: since some slower ships might never reach the speed you're waiting for, you might want a script to react once the ship is at full throttle (1) or at half its maximum speed (0.5), or whatever other proportion of the maximum speed...
Hope this helps
http://wiki.alioth.net/index.php/Oolite ... ence:_Ship
I'd say you probably want
Code: Select all
(player.ship.speed/player.ship.maxSpeed)
Hope this helps
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
- Rustybolts
- ---- E L I T E ----
- Posts: 293
- Joined: Sun Jun 07, 2009 6:22 pm
- Location: UK
Thanks but doesn't quite work here's my test code
which i wanted to start if witchdrive injectors where used. the jumpdrive should also start it but didn't. I mainly want it to detect witchdrive injector use though.
Code: Select all
if (player.ship.maxSpeed>"1.0"){
player.commsMessage("Works");
}
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
This should beRustybolts wrote:Thanks but doesn't quite work here's my test codewhich i wanted to start if witchdrive injectors where used. the jumpdrive should also start it but didn't. I mainly want it to detect witchdrive injector use though.Code: Select all
if (player.ship.maxSpeed>"1.0"){ player.commsMessage("Works"); }
Code: Select all
if (player.ship.maxSpeed > 1.0)
{
player.commsMessage("Works");
}
- Rustybolts
- ---- E L I T E ----
- Posts: 293
- Joined: Sun Jun 07, 2009 6:22 pm
- Location: UK
Unfortunately despite changing my mistake this still did not work. Maybe a value of 1 is a s high as maxspeed goes
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
That would be :Rustybolts wrote:Thanks but doesn't quite work here's my test codewhich i wanted to start if witchdrive injectors where used. the jumpdrive should also start it but didn't. I mainly want it to detect witchdrive injector use though.Code: Select all
if (player.ship.maxSpeed>"1.0"){ player.commsMessage("Works"); }
Code: Select all
if (player.ship.speed>player.ship.maxSpeed>){
player.commsMessage("FuelInjection (Or jumpspeed) in use");
}
Code: Select all
if (player.ship.speed>20*player.ship.maxSpeed>){
player.commsMessage("Jumpspeed in use");
}
UPS-Courier & DeepSpacePirates & others at the box and some older versions
Or even better:
(I removed the extra '>' at the end of the conditions, as well as making it possible to check for jumpspeed & fuel injection separately)
the value of 1 I gave as an example was the result of dividing speed by maxSpeed, as in
If I were in you I'd test all various conditions and oolite properties inside the debug console. Just typing player.ship.speed in there will show your current speed etc... It's a great time saver!
Code: Select all
if (player.ship.speed>20*player.ship.maxSpeed){
player.commsMessage("Jumpspeed in use");
} else if (player.ship.speed>player.ship.maxSpeed){
player.commsMessage("Fuel Injection in use");
}
the value of 1 I gave as an example was the result of dividing speed by maxSpeed, as in
Code: Select all
if((player.ship.speed/player.ship.maxSpeed) > 1) { ... }
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
- Rustybolts
- ---- E L I T E ----
- Posts: 293
- Joined: Sun Jun 07, 2009 6:22 pm
- Location: UK
I have tried all possibilities suggested and receive no comms message i have checked deepspace pirates and you have used it as follows
Which is no different....
Thanks for all your help though.
Code: Select all
if(!system.isInterstellarSpace && !player.ship.docked && player.ship.speed > 20*player.ship.maxSpeed*Math.random() && !player.alertHostiles)
Thanks for all your help though.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
- LittleBear
- ---- E L I T E ----
- Posts: 2882
- Joined: Tue Apr 04, 2006 7:02 pm
- Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.
For testing it, you could try player.consoleMessage instead. I've found when playtesting that comms messages are not always displayed (maybe due to a range thing from the ship sending it) and it might be the same type of thing here.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
- Rustybolts
- ---- E L I T E ----
- Posts: 293
- Joined: Sun Jun 07, 2009 6:22 pm
- Location: UK
Thanks i have changed my code a bit
To test i performed a witchspace jump the console message told me when it had ended so that worked fine.
Then i tried my injectors recieved no message
Then i tried a jump again no message.
Code: Select all
this.shipWillExitWitchspace = function(){
player.consoleMessage("witchspace ended");
}
if (player.ship.speed>20*player.ship.maxSpeed){
player.consoleMessage("Jumpspeed in use");
} else if (player.ship.speed>player.ship.maxSpeed){
player.consoleMessage("Fuel Injection in use");
}
Then i tried my injectors recieved no message
Then i tried a jump again no message.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Try next code:
You had nothing in your code that triggered your code. The tickle triggers every 10 seconds, with the same timer as the legacy code.
Although the tickle is nice for testing, don't use it in final work as at this moment all legacy scripts run also and your code will run at the busiest possible time.
Code: Select all
this.tickle = function()
{
if (player.ship.speed>20*player.ship.maxSpeed)
{
player.consoleMessage("Jumpspeed in use");
}
else if (player.ship.speed>player.ship.maxSpeed)
{
player.consoleMessage("Fuel Injection in use");
}
}
Although the tickle is nice for testing, don't use it in final work as at this moment all legacy scripts run also and your code will run at the busiest possible time.
UPS-Courier & DeepSpacePirates & others at the box and some older versions
- Rustybolts
- ---- E L I T E ----
- Posts: 293
- Joined: Sun Jun 07, 2009 6:22 pm
- Location: UK
Ahh thanks for this i didn't fully realise that when using javascript it doesn't run code unless you have called an event.
It works but is maybe too slow for what i am wanting. I need it to detect at the instant it occurs also at the instant no longer in use.
What i was wanting to do was have a heat meter that increased on start of witch injection, when reached highest temperature cut out the injectors until they had cooled down. This is probably not possible then at the moment.
It works but is maybe too slow for what i am wanting. I need it to detect at the instant it occurs also at the instant no longer in use.
What i was wanting to do was have a heat meter that increased on start of witch injection, when reached highest temperature cut out the injectors until they had cooled down. This is probably not possible then at the moment.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871