Oolite JavaScript Reference: Player

From Elite Wiki
Revision as of 12:02, 6 December 2007 by Ahruman (talk | contribs) (commsMessage: Example as per request.)

Prototype: Ship

This class was added in Oolite test release 1.70.

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

name

name [read-only string]

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

score

score [read-write integer]

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

credits

credits [read-write integer]

The amount of money the player has.

fuelLeakRate

fuelLeakRate [read-write double]

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.

alertCondition

alertCondition [read-only integer]

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

docked

docked [read-only boolean]

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

alertTemperature

alertTemperature [read-only boolean]

Whether the cabin temperature is dangerously high.

alertMassLocked

alertMassLocked [read-only boolean]

Whether the player is mass locked.

alertAltitude

alertAltitude [read-only boolean]

Whether the player is dangerously close to a planet.

alertEnergy

alertEnergy [read-only boolean]

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

alertHostiles

alertHostiles [read-only boolean]

Whether there are hostile ships within scanner range.

dockedStation

dockedStation [read-only Station]

The station with which the player is currently docked.

Deprecated properties

The following properties are deprecated as of Oolite 1.70, and will be removed before the next stable release:


Methods

awardEquipment

void awardEquipment(equipmentKey)

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

commsMessage

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

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.

removeEquipment

void removeEquipment(equipmentKey)

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

hasEquipment

boolean hasEquipment(equipmentKey)

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!")

awardCargo

void awardCargo(cargoname, amount)

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

removeAllCargo

void removeAllCargo()

Removes all cargo from the ship’s cargo bay.

useSpecialCargo

void useSpecialCargo(description)

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

launch

void launch()

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