Difference between revisions of "Oolite JavaScript Reference: Player"

From Elite Wiki
m (Methods: Even more cleanup.)
Line 54: Line 54:
 
The player’s score; nominally the number of kills the player has made, although some missions award additional points.
 
The player’s score; nominally the number of kills the player has made, although some missions award additional points.
   
== Deprecated properties ==
 
  +
=== <code>specialCargo</code> ===
The following properties are deprecated as of Oolite 1.70, and will be removed before the next stable release:
 
  +
{{Oolite-prop-future|1.72}}
* '''<code>legalStatus</code>''': use <code>[[Oolite JavaScript Reference: Ship#bounty|bounty]]</code> instead.
 
  +
'''specialCargo''' : String (read-only)
* '''<code>dockedStationName</code>''': use <code>[[#dockedStation|dockedStation]].[[Oolite JavaScript Reference: Ship#shipDescription|shipDescription]]</code> instead.
 
  +
The special cargo the player is carrying, if any; otherwise <code>null</code>.
* '''<code>dockedAtMainStation</code>''': use <code>[[#dockedStation|dockedStation]].[[Oolite JavaScript Reference: Ship#isMainStation|isMainStation]]</code> instead.
 
  +
  +
'''See also''': <code>[[#useSpecialCargo|useSpecialCargo]]()</code>
   
   
Line 69: Line 70:
 
function '''awardEquipment'''(equipmentKey : String)
 
function '''awardEquipment'''(equipmentKey : String)
 
Adds the given piece of equipment to the player’s ship. Example: <code>player.awardEquipment("EQ_TRUMBLE")</code>
 
Adds the given piece of equipment to the player’s ship. Example: <code>player.awardEquipment("EQ_TRUMBLE")</code>
  +
  +
=== <code>canAwardCargo</code> ===
  +
{{Oolite-method-future|1.72}}
  +
function '''canAwardCargo'''(cargoName : String, amount : Number) : Boolean
  +
Returns <code>true</code> if it is possible to add the specified cargo to the ship, <code>false</code> otherwise. In particular, it will return <code>false</code> if there is not enough space, if the cargo type is unknown or if there is currently special cargo installed (and the cargo is of a type measured in tons). Attempting to award cargo under these conditions will raise an error, so using <code>canAwardCargo</code> is strongly recommended.
  +
  +
'''See also:''' <code>[[#awardCargo|awardCargo]]()</code>
   
 
=== <code>commsMessage</code> ===
 
=== <code>commsMessage</code> ===
Line 97: Line 105:
 
function '''useSpecialCargo'''(description : String)
 
function '''useSpecialCargo'''(description : String)
 
Fills the cargo bay with the cargo described, effectively disabling the use of the cargo bay until the cargo is removed.
 
Fills the cargo bay with the cargo described, effectively disabling the use of the cargo bay until the cargo is removed.
  +
  +
'''See also''': <code>[[#specialCargo|specialCargo]]</code>
   
 
[[Category:Oolite scripting]]
 
[[Category:Oolite scripting]]

Revision as of 19:05, 23 May 2008

Prototype: Ship

The Player class is an Entity representing the player, and the player’s ship – the two are inseperable. The Player has all the properties and methods of a Ship, and several others. There is always exactly one Player object in existence, which can be accessed through the player global property.

Properties

alertAltitude

alertAltitude : Boolean (read-only)

Whether the player is dangerously close to a planet.

alertCondition

alertCondition : Number (read-only, integer)

Returns the current alert condition. 0 = Docked, 1 = Green, 2 = Yellow, 3 = Red.

alertEnergy

alertEnergy : Boolean (read-only)

Whether the player’s energy level is depleted (i.e., energy is less than maxEnergy).

alertHostiles

alertHostiles : Boolean (read-only)

Whether there are hostile ships within scanner range.

alertMassLocked

alertMassLocked : Boolean (read-only)

Whether the player is mass locked.

alertTemperature

alertTemperature : Boolean (read-only)

Whether the cabin temperature is dangerously high.

credits

credits : Number (read/write, integer)

The amount of money the player has.

docked

This property was added in Oolite test release 1.70.

docked : Boolean (read-only)

True if the player is docked with a station or carrier.

dockedStation

This property was added in Oolite test release 1.70.

dockedStation : Station (read-only)

The station with which the player is currently docked.

fuelLeakRate

fuelLeakRate : Number (read/write)

The rate at which the player is losing fuel, in tenths of a LY per second. May not be negative. Reset to 0 when fuel is empty.

name

name : String (read-only)

The name of the player’s character (e.g., “Jameson”).

score

score : Number (read/write, integer)

The player’s score; nominally the number of kills the player has made, although some missions award additional points.

specialCargo

specialCargo : String (read-only)

The special cargo the player is carrying, if any; otherwise null.

See also: useSpecialCargo()


Methods

awardCargo

function awardCargo(cargoname : String, amount : Number)

Awards the given amount of the specified type of cargo. The cargo name must match the name in commodities.plist exactly.

awardEquipment

function awardEquipment(equipmentKey : String)

Adds the given piece of equipment to the player’s ship. Example: player.awardEquipment("EQ_TRUMBLE")

canAwardCargo

function canAwardCargo(cargoName : String, amount : Number) : Boolean

Returns true if it is possible to add the specified cargo to the ship, false otherwise. In particular, it will return false if there is not enough space, if the cargo type is unknown or if there is currently special cargo installed (and the cargo is of a type measured in tons). Attempting to award cargo under these conditions will raise an error, so using canAwardCargo is strongly recommended.

See also: awardCargo()

commsMessage

function commsMessage(message : String [, duration: Number])

Writes the specified message in the player’s communications log, as well as displaying it as a console message. The optional duration parameter determines how long the message should be displayed on the console before fading out. It is clamped to the range [1, 10]. If no duration is specified, 4.5 seconds will be used. Example: player.commsMessage("Hello, cruel universe.", 6)

consoleMessage

function consoleMessage(message : String [, duration: Number])

Displays the specified message as a console message, that is, as a message on the HUD. The optional duration parameter determines how long the message should be displayed before fading out. It is clamped to the range [1, 10]. If no duration is specified, 3 seconds will be used.

hasEquipment

function hasEquipment(equipmentKey : String) : Boolean

Returns true if the given piece of equipment is present on/in the player’s ship, false if it is not. Example: if (player.hasEquipment("EQ_TRUMBLE")) Log("Oh noes, I has a trumble!")

launch

function launch()

Launches the player’s ship if it is currently docked.

removeAllCargo

function removeAllCargo()

Removes all cargo from the ship’s cargo bay.

removeEquipment

function removeEquipment(equipmentKey : String)

Removes the given piece of equipment from the player’s ship. Example: player.removeEquipment("EQ_TRUMBLE")

useSpecialCargo

function useSpecialCargo(description : String)

Fills the cargo bay with the cargo described, effectively disabling the use of the cargo bay until the cargo is removed.

See also: specialCargo