I want to move the player ship via .js - SOLVED

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

I want to move the player ship via .js - SOLVED

Post 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 8)

L
Last edited by Lestradae on Fri Aug 28, 2009 12:17 pm, edited 1 time in total.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Code: Select all

player.ship.position = system.sun.position; // For example
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 »

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
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Look at the planetfall script. I do that very thing on launch from the temporary station.
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

...

Post 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
:lol:

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!
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post 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
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

That depends. Where did launchVector and setPos() come from?
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

They're in my planetfall scripting, defined elsewhere in it.

You've been a little too specific in your borrowing ;)
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 »

..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
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

.

Post 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
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6626
Joined: Wed Feb 28, 2007 7:54 am

Post 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.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post 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.
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post by Lestradae »

OK guys, solved it! :shock:

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! :D

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!
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Post by Frame »

i would make the EQ_SHUTTLE less generic and call it EQ_LESTRADAE_SHUTTLE though ;-)
Bounty Scanner
Number 935
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 »

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.
Post Reply