Page 1 of 3
I want to move the player ship via .js - SOLVED
Posted: Thu Aug 27, 2009 6:14 pm
by Lestradae
... how do I do that?
Had a look at Frame's save anywhere but did not become any wiser because of it, and couldn't find the old solar systems concept study any more.
Would be happy if someone helped me out
L
Posted: Thu Aug 27, 2009 6:19 pm
by JensAyton
Code: Select all
player.ship.position = system.sun.position; // For example
Posted: Thu Aug 27, 2009 6:40 pm
by Eric Walch
Ahruman wrote:Code: Select all
player.ship.position = system.sun.position; // For example
What is probably equal to
Code: Select all
player.ship.temperature = player.ship.maxTemp * 10 000
Posted: Thu Aug 27, 2009 7:15 pm
by Thargoid
Look at the planetfall script. I do that very thing on launch from the temporary station.
...
Posted: Thu Aug 27, 2009 8:31 pm
by Lestradae
Eric Walch wrote:Ahruman wrote:Code: Select all
player.ship.position = system.sun.position; // For example
What is probably equal to
Code: Select all
player.ship.temperature = player.ship.maxTemp * 10 000
You people are evil
Edit: Is this the new trumble recipe? "Do this and we promise you will
never, ever have troubles with trumbles again"
@T: Thanks, will have a look into the planetfall script then!
..
Posted: Thu Aug 27, 2009 9:14 pm
by Lestradae
OK, so I don't get it.
If I write a .js that goes like this:
Code: Select all
this.shipWillLaunchFromStation = function()
{
let launchPosition = player.ship.position.add(launchVector.multiply(10000));
this.setPos(player.ship,launchPosition);
}
... that should move any docked ship 10 kms away from any dockable object, into the launch direction - shouldn't it?
L
Posted: Thu Aug 27, 2009 9:24 pm
by JensAyton
That depends. Where did launchVector and setPos() come from?
Posted: Thu Aug 27, 2009 9:37 pm
by Thargoid
They're in my planetfall scripting, defined elsewhere in it.
You've been a little too specific in your borrowing
Posted: Fri Aug 28, 2009 4:58 am
by Kaks
..and setPos is used there to make the oxp compatible with both 1.72 & 1.73 at the same time.
You could definitely have borrowed from another part of planetfall.
If you're not bothered by 1.72 compatibility, something that should work ok when 1.73 is released is:
Code: Select all
player.ship.position=player.ship.position.add(player.ship.orientation.vectorForward().multiply(10))
The code above should magically move your ship 10 m forward, in the direction you're facing.
If you keep using launchVector as defined inside planetfall, you'll always move directly away from the planet, no matter where you are, no matter what direction you're facing.
L, I suggest you read & reread the vector3d & quaternion pages on the wiki (accessible via
this page) until they start to make sense.
It's really easy to get lost with this stuff otherwise!
Hope this helps
Kaks
.
Posted: Fri Aug 28, 2009 7:24 am
by Lestradae
What I still don't get:
Code: Select all
this.shipWillLaunchFromStation = function()
{
player.ship.position = player.ship.position.add(player.ship.orientation.vectorForward().multiply(8000))
}
... does not move the ship 8 kilometres forward at launch.
I am on trunk SVN 2309 currently. There is no error entry in the log that the vector properties would be undefined. I assume that the length of the vector are the 8000 and that the "vectorForward" part tells the direction already (? ... or not?) that could also be defined via Vector3D or Quaternion coordinates - correct?
Or do I still have to define these coordinates for the above and therefore have to define the "launchVector"?
I am really puzzled as to what is java script, what is Oolite's internal "function call" methods and what are variables that T has defined for his planetfall ...
L
Posted: Fri Aug 28, 2009 7:30 am
by another_commander
I would not put the change player position code in the shipWillLaunchFromStation handler, I would rather use the this.shipLaunchedFromStation = function() handler instead. I say that without being able to test atm though, so it might or might not be the solution to your problem.
Posted: Fri Aug 28, 2009 7:52 am
by Thargoid
shipWillLaunchFromStation should be ok in general, that's where I do it for Planetfall (for a similar job, or else you launch to just in front of the station and then visibly move, which looks rather odd.
I think the problem might be that vectorForward() may not yet be defined in this case. When I do it I'm not using that, but a specifically defined vector from the planet I landed on to the player position.
Try adding
Code: Select all
player.consoleMessage("Vector forward = " + player.ship.orientation.vectorForward() );
Or a log equivalent (replace player.consoleMessage with log) and see if the vector is defined. I get the feeling it may not be, hence you're moving the player by 8km * 0, hence they're going nowhere.
..
Posted: Fri Aug 28, 2009 8:04 am
by Lestradae
OK guys, solved it!
Actually, the handler change suggested by A_C did the trick. Now all is working as intended, and I am happy to report that the OSE transfer shuttle for ships too big to dock convincingly is in!
Now there are no NPCs crash-docking any more, and players with carriers have the transfer shuttle. Can't believe all solved now. Was only possible via the help of many people here - T's & Eric's bigShips script for traders, Eric's advice as to give GalCop carriers the hunter role to stop them from docking/launching too, and now without Frame, Thargoid, Kaks & another_commander and the people who put "targetStation.dockPlayer()" into the trunk the transfer shuttle wouldn't have been possible.
Thanks everyone!
The transfer shuttle as equipment now looks like this:
Code: Select all
<array>
<integer>0</integer>
<integer>500000</integer>
<string>Transfer Shuttle</string>
<string>EQ_SHUTTLE</string>
<string>A transfer shuttle that can be used as a ferry for the Commander, crew and cargo of vessels which are too big or impractical to dock at stations or other carriers in the conventional way. Your carrier will be parked a few kilometres away, awaiting your return.</string>
<dict>
<key>available_to_all</key>
<true/>
<key>requires_cargo_space</key>
<integer>600</integer>
</dict>
</array>
... its preinstalled on the real monster ships such as Dredgers ...
and the finished and working transfer shuttle script now reads:
Code: Select all
this.name = "Transfer Shuttle Script";
this.author = "Frame, Lestradae & some help from Thargoid, Kaks & another_commander";
this.copyright = "All";
this.description = "Enables the player to dock player carriers at any station or NPC carrier with an intermediate Transfer Shuttle";
this.version = "0.1";
this.shipLaunchedFromStation = function()
{
if(player.ship.hasEquipment("EQ_SHUTTLE"))
{
player.commsMessage("Commander " + player.name + ", your transfer shuttle has been released from its docking clamps and is ready for liftoff. Have a safe journey to your carrier.");
player.ship.position = player.ship.position.add(player.ship.orientation.vectorForward().multiply(4000))
}
}
this.playerRequestedDockingClearance = function()
{
if(player.ship.target) //no target no game, so it needs only to be in scanner range
{
this.targetStation = player.ship.target
if(player.ship.hasEquipment("EQ_SHUTTLE"))
{
player.commsMessage("Commander " + player.name + ", your transfer shuttle has been given docking clearance. Have a pleasant flight and please dock in the appropriate hangar section.");
this.targetStation.dockPlayer();
}
}
}
Cheers
L
Edit: Forgot to mention, the carrier "releases the transfer shuttle" aka docks via requesting docking clearance!
Posted: Fri Aug 28, 2009 9:55 am
by Frame
i would make the EQ_SHUTTLE less generic and call it EQ_LESTRADAE_SHUTTLE though
Posted: Fri Aug 28, 2009 11:01 am
by Eric Walch
Frame wrote:i would make the EQ_SHUTTLE less generic and call it EQ_LESTRADAE_SHUTTLE though
I would also remove the "available_to_all" in the equipment definition.
Code: Select all
<array>
<string>Transfer Shuttle</string>
<string>EQ_SHUTTLE</string>
<dict>
<key>available_to_all</key>
<true/>
<key>requires_cargo_space</key>
<integer>600</integer>
</dict>
</array>
After removal it only becomes buyable by ships that have it explicit defined in the shipYard.plist. And than define it only for the big player ships. That way you avoid someone with a krait to be able buying a shuttle.