Entity

This represents an interface to an entity in the scene. Creating an object of this type will not create a new entity in the scene, but will rather enable access to an existing entity. Use the Sector class to create new entities.
 Avorion uses an entity component system (See entity component system on Wikipedia). Thus, some properties and functions are only available if the entity has the corresponding component. The list of components can be found here: Enum ComponentType

 Note: The **index** property of an Entity can be changed, but won't change the actual index of the underlying entity. Instead, the entity interface will be pointing to another entity with the new index. Use this for performance tuning to avoid creating lots of entity interfaces.
 Note 2: This class is considered to have too many members and functions. Over time these will be phased out into their respective component classes. Only a few frequently used properties and functions will remain for coding comfort.

function  Entity(int index)

Parameters

```
           index The index of the entity, must be an index of an existing entity

```

Returns

 A new instance of Entity

## Member Functions

```
           function bool

```

### hasComponent

(int type)

```
           function var

```

### getNearestDistance

(Entity other)

```
           function

```

### setPlan

(BlockPlan plan)

Returns

 nothing

```
           function BlockPlan

```

### getPlan

()

```
           function var

```

### getUndamagedPlanMoneyValue

()

```
           function double...

```

### getUndamagedPlanResourceValue

()

```
           function var

```

### getPlanMoneyValue

()

```
           function double...

```

### getPlanResourceValue

()

```
           function

```

### heal

(float damage, int index, vec3 location, int inflictorId)

Returns

 nothing

```
           function

```

### inflictDamage

(float damage, int index, vec3 location, int inflictorID)

Returns

 nothing

```
           function

```

### destroyBlock

(int index, int inflictorID)

Returns

 nothing

```
           function

```

### destroy

(int inflictorID)

Returns

 nothing

```
           function

```

### setAccumulatingBlockHealth

(bool in)

Returns

 nothing

```
           function Box

```

### getBoundingBox

()

```
           function Sphere

```

### getBoundingSphere

()

```
           function

```

### moveBy

(vec3 delta)

Returns

 nothing

```
           function

```

### addBuildingPermission

(int )

Returns

 nothing

```
           function

```

### removeBuildingPermission

(int )

Returns

 nothing

```
           function int...

```

### getBuildingPermissions

()

```
           function var

```

### getBoostedValue

(int type, float value)

```
           function var

```

### addBaseMultiplier

(int type, float factor)

```
           function var

```

### addMultiplier

(int type, float factor)

```
           function var

```

### addMultiplyableBias

(int type, float factor)

```
           function var

```

### addAbsoluteBias

(int type, float factor)

```
           function var

```

### addKeyedBaseMultiplier

(int type, int key, float factor)

```
           function var

```

### addKeyedMultiplier

(int type, int key, float factor)

```
           function var

```

### addKeyedMultiplyableBias

(int type, int key, float factor)

```
           function var

```

### addKeyedAbsoluteBias

(int type, int key, float factor)

```
           function

```

### removeBonus

(int key)

Returns

 nothing

```
           function

```

### damageShield

(double amount, vec3 location, int inflictorId)

Returns

 nothing

```
           function

```

### healShield

(double amount)

Returns

 nothing

```
           function

```

### changeShield

(double delta)

Returns

 nothing

```
           function var

```

### isInsideShield

(vec3 point)

```
           function int...

```

### getMineableResources

()

```
           function Material

```

### getMineableMaterial

()

```
           function var

```

### isCollectable

(Entity entity)

```
           function int

```

### registerCallback

(string callbackName, string functionName)

 Register a callback in the entity. The callback receiver has to be inside the same sector for the registration to succeed. The callback will be removed if either the entity or the receiver leaves the sector or gets destroyed.

Parameters

```
           callbackName The name of the callback

           functionName The name of the function that will be executed in the script when the callback happens

```

Returns

 0 on success, 1 if the registration failed

```
           function int

```

### unregisterCallback

(string callbackName, string functionName)

```
           function Matrix, int...

```

### getTurretPositions

(TurretTemplate turret, int number)

```
           function var

```

### addTurret

(TurretTemplate turret, Matrix position, int part)

```
           function Entity

```

### getTurret

(int index)

```
           function Entity...

```

### getTurrets

()

```
           function var

```

### getNumArmedTurrets

()

```
           function var

```

### getNumUnarmedTurrets

()

```
           function var

```

### isTurretAllowed

(TurretTemplate turret)

```
           function var

```

### getFreeArbitraryTurrets

()

```
           function var

```

### getFreeArmedTurrets

()

```
           function var

```

### getFreeUnarmedTurrets

()

```
           function var

```

### getAllowedArbitraryTurrets

()

```
           function var

```

### getAllowedUnarmedTurrets

()

```
           function var

```

### getAllowedArmedTurrets

()

```
           function var

```

### getAttachedBlockIndex

()

```
           function var

```

### getTurretSize

()

```
           function var

```

### getTurretTurningSpeed

()

```
           function var

```

### isManned

()

```
           function

```

### setTurretSize

(float in)

Returns

 nothing

```
           function

```

### setTurretTurningSpeed

(float in)

Returns

 nothing

```
           function

```

### setAttachedBlockIndex

(int in)

Returns

 nothing

```
           function

```

### setManned

(bool in)

Returns

 nothing

```
           function var, var, table<in, in>, string>

```

### canAddCrew

(int number, int profession, bool change)

```
           function

```

### changeCrew

(int number, int profession)

Returns

 nothing

```
           function

```

### addCrew

(int number, CrewMan crewman)

Returns

 nothing

```
           function

```

### removeCrew

(int number, CrewMan crewman)

Returns

 nothing

```
           function var

```

### getCrewMembers

(int profession)

```
           function

```

### addCargo

(TradingGood good, int amount)

 Adds cargo to the entity. If the amount specified exceeds the maximum capacity of the cargo bay, as much cargo as still fits in will be added.

Parameters

```
           good TradingGood that is to be added.

           amount The amount of cargo that should be added.

```

Returns

 nothing

```
           function

```

### removeCargo

(var good, int amount)

 Removes cargo from the entity. When given a TradingGood, an exact check for that good will be performed. When given a string, only a name check will be performed, and which cargo will be removed first is undefined if there are multiple goods with the same name. An example would be Energy Cells vs. Stolen Energy Cells. The 'name' property is the same, but the 'stolen' property is different.

Parameters

```
           good Either a TradingGood or a string with the name of a good.

           amount The amount of cargo that should be removed. If this is more than there is on the ship, all specified cargo will be removed.

```

Returns

 nothing

```
           function

```

### destroyCargo

(float volume)

 Destroys cargo. The destruction distribution is generally equal over all goods.

Parameters

```
           volume The amount of volume that should be destroyed.

```

Returns

 nothing

```
           function TradingGood, int...

```

### getCargo

(unsigned int n)

```
           function table<TradingGood, int>

```

### getCargos

()

```
           function table<TradingGood, int>

```

### findCargos

(string name)

 Finds all cargos with the given name.

Parameters

```
           name A string that will be matched with the 'name' property of the cargos.

```

Returns

 A map containing all matching goods, with the good as key and amount as value.

```
           function var

```

### getCargoAmount

(var name)

 Counts all goods of the given type. When given a string, it will match the 'name' property of the goods. When given a TradingGood it will match the exact good.

Parameters

```
           name Either a TradingGood or a string containing the name of a trading good.

```

Returns

 The number of goods

```
           function var

```

### resolveScriptPath

(string path)

```
           function var...

```

### invokeFunction

(string scriptName, string functionName, var... arguments)

 Invokes a function in a script of the entity. Use this function to invoke functions from one script in another script. The first return value of the function is an integer indicating whether or not the call was successful. When it was, this integer is followed by the return values of the invoked function.

Parameters

```
           scriptName The name of the script containing the function

           functionName The name of the function that will be executed

           arguments An arbitrary list of arguments that will be given to the invoked function. Only numbers, strings and nil are supported here.

```

Returns

 Returns at least 1 value indicating if the call succeeded:
 0 The call was successful. In this case, the return values of the script are returned in addition to the call result, following the call result.
 1 The call failed because the entity with the specified index does not exist or has no scripting component.
 2 The call failed because it came from another sector than the entity is in.
 3 The call failed because the given script was not found in the entity.
 4 The call failed because the given function was not found in the script.

```
           function var

```

### addScript

(string scriptPath, var... arguments)

 Adds a new script to an entity

Parameters

```
           scriptPath The path of the script that should be added

           arguments An arbitrary number of arguments that will be given to the 'initialize' function of the added script

```

Returns

 0 on success, 1 if the entity could not be found

```
           function var

```

### addScriptOnce

(string scriptPath, var... arguments)

```
           function

```

### removeScript

(var script)

Returns

 nothing

```
           function var

```

### hasScript

(string name)

```
           function table<int, string>

```

### getScripts

()

```
           function vec3

```

### getRandomDockingPosition

(float radius)

```
           function bool

```

### isDocked

(Entity other)

```
           function vec3...

```

### getDockingPositions

()

 Lists all docking positions that the entity has

Returns

 A list of vec3s where every 2 values represent a dock. The first value is the local position, the second value is the local direction of the dock.

```
           function int...

```

### getDamageContributors

()

 Lists all factions that contributed damage to the entity

Returns

 Indices of all factions that contributed damage to the entity

```
           function int...

```

### getDamageContributorPlayers

()

 Lists all players that contributed damage to the entity

Returns

 Indices of all players that contributed damage to the entity

```
           function var

```

### hyperspaceBlocked

()

```
           function

```

### blockHyperspace

(float time)

Returns

 nothing

```
           function var

```

### getValue

(string key)

 Retrieves a custom value saved in the entity with the given key

Parameters

```
           key A string that serves as the name of the value

```

Returns

 The value if the key exists, otherwise nil

```
           function table<string, var>

```

### getValues

()

 Retrieves all key-value pairs of custom values of the entity

Returns

 A table containing all custom key-value pairs

```
           function

```

### setValue

(string key, var value)

 Sets a custom value

Parameters

```
           key A string that serves as the name of the value

           value The value to save. Must be bool, number, string or nil. If nil is given, the value will be deleted.

```

Returns

 nothing

```
           function

```

### setTitle

(string , string\_pair... )

Returns

 nothing

```
           function

```

### setTitleArguments

(string\_pair... )

Returns

 nothing

```
           function table<string, string>

```