Functions

```
           function bool

```

This function is only available on the server.

```
           function bool

```

This function is only available on the server.

```
           function

```

 Invokes a function on a remote client, in the client instance of the caller script. Example usage would be a server Resource Trader calling the setData() function of its client instance. Return values of the remotely executed functions cannot be retrieved.

This function is only available on the server.

Parameters

```
           playerIndex The player index of the client the function should be invoked on

           functionName The name of the scripting function that is to be executed

           arguments An arbitrary number of arguments that will be given to the remote function

```

Returns

 nothing

```
           function

```

### broadcastInvokeClientFunction

(string functionName, var... arguments)

 Invokes a function on \*all\* remote clients, in the client instances of the caller script. Return values of the remotely executed functions cannot be retrieved.

This function is only available on the server.

Parameters

```
           functionName The name of the scripting function that is to be executed

           arguments An arbitrary number of arguments that will be given to the remote function

```

Returns

 nothing

```
           function

```

### playSound

(string soundName, int type, float volume)

This function is only available on the client.

Returns

 nothing

```
           function

```

### play3DSound

(string soundName, int type, vec3 position, float radius, float volume, Entity [or nil] entity)

This function is only available on the client.

Returns

 nothing

```
           function

```

### displayMissionAccomplishedText

(string bigText, string smallText)

This function is only available on the client.

Returns

 nothing

```
           function

```

### registerBoss

(int entityIndex, var healthColor, var shieldColor)

This function is only available on the client.

Returns

 nothing

```
           function

```

### unregisterBoss

(int entityIndex)

This function is only available on the client.

Returns

 nothing

```
           function

```

### setBossHealth

(int index, var health, var maxHealth, var shield, var maxShield)

This function is only available on the client.

Returns

 nothing

```
           function

```

### setBossHealthColor

(int index, var health, var shield)

This function is only available on the client.

Returns

 nothing

```
           function

```

### displayChatMessage

(string message, string sender, int type)

 This function displays a chat message on the Chat window of the client.

This function is only available on the client.

Parameters

```
           message The message that will be displayed in the chat window

           sender The sender that will be displayed for the chat message

           type The type of chat message, 0 = Normal, 1 = Error, 2 = Warning, 3 = Info

```

Returns

 nothing

```
           function

```

### invokeServerFunction

(string functionName, var... arguments)

 Invokes a function on the remote server, in the server instance of the caller script. Example usage would be a server Resource Trader calling the getData() function of its server instance. Return values of the remotely executed functions are not retrieved. On the server side, a variable called "callingPlayer" will be created or set before executing the called function. callingPlayer contains the index of the calling player. Use this variable to verify that the calling player is actually the player you'd expect. After the call finishes on the server, callingPlayer is set to nil.

This function is only available on the client.

Parameters

```
           functionName The name of the scripting function that is to be executed

           arguments An arbitrary number of arguments that will be given to the remote function

```

Returns

 nothing

```
           function bool

```

### onServer

()

This function is only available on the client.

```
           function bool

```

### onClient

()

This function is only available on the client.

```
           function UserObject

```

### copy

(var value)

 Copies the given Object

Parameters

```
           value A non-POD, non-table object

```

Returns

 A true copy of the given object

```
           function bool

```

### valid

(var value)

 Checks if the given object is valid. Some objects can become invalid, for example when an entity is deleted the instances of the Entity in the scripts will become invalid.

Parameters

```
           value A non-POD, non-table object

```

Returns

 A boolean indicating whether the object is valid. Returns false when given nil.

```
           function

```

### terminate

()

 Terminates the script. This function returns, but no more following calls will be made to the script. The script will be removed from the entity on the next occasion.

Returns

 nothing

```
           function double, string

```

### getReadableValue

(double number)

 Rounds a large number and adds a suffix such as k or M. For example, 10.000 will become 10k.

Parameters

```
           number The number to make readable

```

Returns

 A string containing the rounded number and the suffix

```
           function bool

```

### deferredCallback

(double time, string function, var... args)

 Registers a deferred callback in the script. The given function will be executed after the given time. Depending on the tick rate of the simulation, the callback might get called slightly later than the given time. The callback will never happen before the given time hasn't passed.

Parameters

```
           time The time to wait until the callback will be executed

           function The function that is to be executed once the time has passed as a string

           args... Arguments that will be passed to the callback function

```

Returns

 true if the callback was registered, false otherwise

```
           function double

```

### systemTimeMs

()

 Returns the system time in milliseconds. Since lua doesn't support clocks that are accurate down to milliseconds.

Returns

 The system time in milliseconds

```
           function double

```

### systemTime

()

 Returns the system time in seconds. Since lua doesn't support clocks that are accurate down to milliseconds.

Returns

 The system time in seconds

```
           function var

```

### getGlobal

(string name)

 Retrieves a global variable. These variables are shared over the entire process.

Parameters

```
           name The name of the global variable

```

Returns

 The queried variable, or nil if non-existant

```
           function

```

### setGlobal

(string name, var value)

 Sets a global variable. These variables are shared over the entire process.

Parameters

```
           name The name of the global variable

           value The value of the global variable. POD datatypes only. Nil deletes the variable.

```

Returns

 nothing

```
           function

```

### print

(var... args)

 Prints to the console. In the ingame console, server output will be printed in cyan, client output will be printed in white.

Parameters

```
           args Any number of arguments. The first value can be a format string. If no formatting can be done then the function falls back to printing all given values.

```

Returns

 nothing

```
           function

```

### printlog

(var... args)

 Similar to print, but prints to the log file.

Parameters

```
           args Any number of arguments. The first value can be a format string. If no formatting can be done then the function falls back to printing all given values.

```

Returns

 nothing

```
           function

```

### writeTrace

(var... args)

 Similar to print, but prints to the user trace stream. This trace stream can be enabled by passing "-t user" to the command line arguments of client or server.

Parameters

```
           args Any number of arguments. The first value can be a format string. If no formatting can be done then the function falls back to printing all given values.

```

Returns

 nothing

```
           function string

```

### createMonetaryString

(int number)

 Inserts dots into a large number to create an easily human readable money string. Example: 10000000 will become 10.000.000

Parameters

```
           number The large number

```

Returns

 A string containing the readable number

```
           function Faction

```

### getParentFaction

()

This function is only available on the server.

```
           function Entity

```

### getPlayerCraft

()

This function is only available on the client.

```
           function Faction

```

### getParentFaction

()

This function is only available on the client.

```
           function

```

### drawText

(string text, int px, int py, Color color, int size, int bold, int italic, int style)

 Draw text. This function should only be called in valid rendering steps. This function is expensive, don't overuse it.

This function is only available on the client.

Parameters

```
           text The text that is to be rendered

           px The x value in pixels of the position, ie. upper left

           py The y value in pixels of the position, ie. upper left

           color The color of the text

           size The font size of the rendered text

           bold Use 1 if the text should be bold, 0 otherwise

           italic Use 1 if the text should be italic, 0 otherwise

           style The style of the text, 0 is default style, 1 is shadowed, 2 is outlined

```

Returns

 nothing

```
           function

```

### drawTextRect

(string text, Rect rect, int horizontalAlignment, int verticalAlignment, Color color, int size, int bold, int italic, int style)

 Draw text inside a rect. This function should only be called in valid rendering steps. This function is expensive, don't overuse it.

This function is only available on the client.

Parameters

```
           text The text that is to be rendered

           rect The rect that functions as boundaries for the text

           horizontalAlignment -1 to position the text at the left, 0 to center it horizontally, +1 to position the text at the right

           verticalAlignment -1 to position the text at the top, 0 to center it vertically, +1 to position the text at the bottom

           color The color of the text, as an int

           size The font size of the rendered text

           bold Use 1 if the text should be bold, 0 otherwise

           italic Use 1 if the text should be italic, 0 otherwise

           style The style of the text, 0 is default style, 1 is shadowed, 2 is outlined

```

Returns

 nothing

```
           function

```

### drawRect

(Rect rect, Color color)

 Draw a rect. This function should only be called in valid rendering steps. This function is expensive, don't overuse it.

This function is only available on the client.

Parameters

```
           rect The rect that is to be drawn

           color The color of the rect

```

Returns

 nothing

```
           function

```

### drawBorder

(Rect rect, Color color)

 Draw a border. This function should only be called in valid rendering steps. This function is expensive, don't overuse it.

This function is only available on the client.

Parameters

```
           rect The rect that is to be drawn

           color The color of the rect

```

Returns

 nothing

```
           function

```

### drawTurretTooltip

(TurretTemplate turret)

This function is only available on the client.

Returns

 nothing

```
           function

```

### drawFighterTooltip

(FighterTemplate fighter)

This function is only available on the client.

Returns

 nothing

```
           function

```

### drawDebugSphere

(Sphere sphere, Color color)

This function is only available on the client.

Returns

 nothing

```
           function

```

### drawDebugBox

(Box box, Matrix matrix, Color color)

This function is only available on the client.

Returns

 nothing

```
           function

```

### drawDebugLine

(vec3 a, vec3 b, Color color)

This function is only available on the client.

Returns

 nothing

```
           function vec3

```

### projectPoint

(vec3 p)

This function is only available on the client.

```
           function vec2

```

### getResolution

()

This function is only available on the client.

function string GetLocalizedString(string str)

function Color ColorHSV(float h, float s, float v)

function Color ColorARGB(float a, float r, float g, float b)

function Color ColorRGB(float r, float g, float b)

function Color ColorInt(int i)

```
           function var

```

### dot

(var a, var b)

 Calculates the dot product between 2 vectors. The vectors must have the same type.

Parameters

```
           a vector a

           b vector b

```

Returns

 The dot product between the two vectors

```
           function var

```

### cross

(var a, var b)

 Calculates the dot product between two vec3s. The vectors must have the same underlying type (double or float).

Parameters

```
           a vector a

           b vector b

```

Returns

 The cross product of the vectors

```
           function var

```

### normalize

(var vec)

 Normalizes a given vector. This function creates a new normalized vector, the given vector is not changed.

Parameters

```
           vec the vector to normalize

```

Returns

 The normalized result of the given vector

```
           function var

```

### normalize\_ip

(var vec)

 Normalizes a given vector. This function normalizes the vector in place.

Parameters

```
           vec the vector to normalize

```

```
           function var

```

### length

(var vec)

 Calculates the length of a vector

Parameters

```
           vec the vector

```

Returns

 The length of the vector

```
           function var

```

### length2

(var vec)

 Calculates the squared length of a vector

Parameters

```
           vec the vector

```

Returns

 The squared length of the vector

```
           function var

```

### distance

(var a, var b)

 Calculates the linear distance between two vectors. The vectors must have the same type.

Parameters

```
           a vector a

           b vector b

```

Returns

 The linear distance between the vectors

```
           function var

```

### distance2

(var a, var b)

 Calculates the squared linear distance between two vectors. The vectors must have the same type.

Parameters

```
           a vector a

           b vector b

```

Returns

 The squared linear distance between the vectors

function Matrix MatrixLookUp(vec3 look, vec3 up)

function Matrix MatrixLookUpRight(vec3 look, vec3 up, vec3 right)

function Matrix MatrixLookUpPosition(vec3 look, vec3 up, vec3 pos)

```
           function Matrix

```

### translate

(Matrix in, vec3 pos)

```
           function Matrix

```

### scale

(Matrix in, vec3 size)

```
           function Matrix

```

### rotate

(Matrix in, float angle, vec3 axis)

```
           function Matrix

```

### lookAt

(vec3 eye, vec3 at, vec3 up)

```
           function Matrix

```

### perspective

(float fov, float aspect, float nearClip, float farClip)

function Seed SeedStr(string str)

```
           function int

```

### makeFastHash

(int x, int y, int seed)

```
           function int

```

### makeHash

(var... values)

```
           function double

```

### makeHash64

(var... values)

function FighterTemplate GenerateFighterTemplate(int seed, int weaponType, float dps, int tech, Rarity rarity, Material material)

function CraftStyle GenerateStationStyle(Seed seed, bool noDisks, bool noSpikes, bool rings, vec3 shape, Color color1, Color color2, Color color3)

function CraftStyle GenerateShipStyle(Seed seed, bool noSpikes, bool rings, vec3 shape, Color color1, Color color2, Color color3)

function BlockPlan GeneratePlanFromStyle(CraftStyle style, Seed seed, float volume, int maxBlocks, bool scaleToFit, Material material)

function BlockPlan GeneratePlanFromFile(string file, Seed seed, float volume, int maxBlocks, bool scaleToFit, Material material)

function BlockPlan LoadPlanFromFile(string file)

function  CorrectInefficiencies(BlockPlan plan, bool addEngines)

Returns

 nothing

function EntityDescriptor StationDescriptor()

function EntityDescriptor ShipDescriptor()

function EntityDescriptor DroneDescriptor()

function EntityDescriptor AsteroidDescriptor()

function EntityDescriptor FighterDescriptor()

function EntityDescriptor WreckageDescriptor()

function EntityDescriptor TurretDescriptor()

function EntityDescriptor WormholeDescriptor()

function EntityDescriptor CargoLootDescriptor()

function EntityDescriptor ColorLootDescriptor()

function EntityDescriptor TurretLootDescriptor()

function EntityDescriptor MoneyLootDescriptor()

function EntityDescriptor ResourceLootDescriptor()

function EntityDescriptor SystemUpgradeLootDescriptor()

function TurretTemplate CreateTemplateFromTurret(Entity turret)

function TurretTemplate GenerateTurretTemplate(Seed seed, int weaponType, float dps, int tech, Rarity rarity, Material material)

 Generates a turret with assigned values into the target slot. All other values will be chosen randomly, but matching to the given arguments.

Parameters

```
           seed The seed used for initializing the random generator. If this seed is 0, a random seed will be used.

           weaponType The type of the weapons that are attached to the turret.

           dps The base amount of damage per second that the turret will deal.

           material The material the turret is made of. This will not have an influence on the dps of the turret.

           rarity The rarity of the turret. This will have an influence on the dps.

```

Returns

 Returns the target slot on success, nil otherwise.

function Color... ColorPalette()

```
           function Seed

```

### getSectorSeed

(int x, int y)

```
           function Seed

```

### getGameSeed

()

```
           function Entity

```

### getParentEntity

()

function int NumMaterials()

function bool IsValidMaterial(int i)