Sector (Server)

This object is only available on the server.

function  Sector()

Returns

 A new instance of Sector

## Properties

```
           function Entity

```

 Convenience function to create a station. Creates a new station in the sector. A random name will be assigned in case of an AI station. This entity will have all components required for a default station.

Parameters

```
           faction The faction the station will belong to

           plan The plan of the station

           position The position of the station

           scripts An arbitrary number of script paths can be passed here, which will be added to the station in the order they are give.

```

Returns

 An entity representing the new station

```
           function Entity

```

### createShip

(Faction faction, string name, BlockPlan plan, Matrix position)

 Convenience function to create a ship. Creates a new ship in the sector. This entity will have all components required for a default ship.

Parameters

```
           faction The faction the ship will belong to

           name The name of the ship, pass "" for a random name

           plan The plan of the ship

           position The position of the ship

```

Returns

 An entity representing the new ship

```
           function Entity

```

### createAsteroid

(BlockPlan plan, bool mineable, Matrix position)

 Convenience function to create an asteroid. Creates a new asteroid in the sector. This entity will have all components required for a default asteroid.

Parameters

```
           plan The plan of the asteroid

           resources 1 if the asteroid should have mineable resources, 0 if not

           material The material of the asteroid and its resources

           position The position of the asteroid

```

Returns

 An entity representing the new asteroid

```
           function Entity

```

### createWreckage

(BlockPlan plan, Matrix position)

 Convenience function to create a wreckage. Creates a new wreckage in the sector. This entity will have all components required for a default wreckage.

Parameters

```
           plan The plan of the wreckage

           position The position of the wreckage

```

Returns

 An entity representing the new wreckage

```
           function Entity

```

### createObject

(BlockPlan plan, Matrix position)

 Convenience function to create a default object. Creates a new default object in the sector. This object has basic components for appearance and physics simulation, such as a plan, velocity and physics

Parameters

```
           plan The plan of the object

           position The position of the object

```

Returns

 An entity representing the new object

```
           function Entity

```

### createWormHole

(int x, int y, Color color, float size)

 Convenience function to create a wormhole. Creates a new wormhole in the sector. This entity will have all components required for a default wormhole.

Parameters

```
           x The destination sector's X coordinate

           y The destination sector's Y coordinate

           color The color of the wormhole

           size The size of the wormhole

```

Returns

 An entity representing the new wormhole

```
           function Entity

```

### createEntity

(EntityDescriptor descriptor)

 Creates a new arbitrary entity in the sector

Parameters

```
           descriptor A descriptor representing the entity to create

```

Returns

 The new entity

```
           function

```

### resendEntity

(Entity entity)

Returns

 nothing

```
           function

```

### dropBundle

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, int money, int... resources)

Returns

 nothing

```
           function Entity

```

### dropMoney

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, int amount)

```
           function Entity

```

### dropResources

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, Material material, int amount)

```
           function Entity

```

### dropCargo

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, TradingGood good, int owner, int amount)

```
           function Entity

```

### dropColor

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, Color color)

```
           function Entity

```

### dropRandomColor

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor)

```
           function Entity

```

### dropTurret

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, TurretTemplate desc)

```
           function Entity

```

### dropSectorTurret

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor)

```
           function Entity

```

### dropUpgrade

(vec3 position, Faction [or nil] reservedFor, Faction [or nil] deniedFor, SystemUpgradeTemplate upgrade)

```
           function

```

### deleteEntity

(Entity entity)

 Sets an entity for deletion. The entity is not deleted right away, but will be marked for deletion and will be deleted at the end of the current frame.

Parameters

```
           entity The entity to delete

```

Returns

 nothing

```
           function

```

### deleteEntityJumped

(Entity entity)

 Sets an entity for deletion. The entity is not deleted right away, but will be marked for deletion and will be deleted at the end of the current frame. This function also creates a hyperspace animation when deleting the entity.

Parameters

```
           entity The entity to delete

```

Returns

 nothing

```
           function

```

### collectGarbage

(var entity)

 Immediately deletes all entities in the sector that are set for deletion. **Don't call this function from an entity script.** Only call this if you know what you're doing.

Parameters

```
           entity The entity to delete

```

Returns

 nothing

```
           function string

```

### resolveScriptPath

(string path)

```
           function var...

```

### invokeFunction

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

```
           function int

```

### addScript

(string scriptPath, var... arguments)

```
           function int

```

### addScriptOnce

(string scriptPath, var... arguments)

```
           function

```

### removeScript

(var script)

Returns

 nothing

```
           function bool

```

### hasScript

(string name)

```
           function table<int, string>

```

### getScripts

()

```
           function

```

### registerCallback

(string callbackName, string functionName)

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

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

 nothing

```
           function

```

### unregisterCallback

(string callbackName, string functionName)

Returns

 nothing

```
           function int, int

```

### getCoordinates

()

 Access the x, y coordinates of the sector

Returns

 2 return values: x, y coordinates of the sector

```
           function Entity

```

### getEntity

(int index)

 Find an entity by index in the sector.
 Complexity: O(logn)

Parameters

```
           index The index of the entity

```

Returns

 The entity or nil if not found

```
           function Entity

```

### getEntityByFactionAndName

(int factionIndex, string name)

```
           function Entity...

```

### getEntities

()

 Returns all entities in the sector

Returns

 Multiple return values: All entities in the sector

```
           function Entity...

```

### getEntitiesByType

(int type)

 Returns all entities in the sector that have a specific type

Parameters

```
           type The desired entity type (See enum EntityType)

```

Returns

 Multiple return values: All matching entities in the sector

```
           function Entity...

```

### getEntitiesByScript

(string script)

 Returns all entities in the sector that have a specific script attached to them

Parameters

```
           script The script that is to check for. This operation checks if the given script name is contained in the actual script name.

```

Returns

 Multiple return values: All matching entities in the sector

```
           function Entity...

```

### getEntitiesByComponent

(int type)

 Returns all entities in the sector that have a specific component

Parameters

```
           type The desired component type (See enum ComponentType)

```

Returns

 Multiple return values: All matching entities in the sector

```
           function Entity...

```

### getEntitiesByComponents

(ComponentType... types)

 Returns all entities in the sector that have a specific set of components

Parameters

```
           types The desired set of component types (See enum ComponentType)

```

Returns

 Multiple return values: All matching entities in the sector

```
           function Entity...

```

### getEntitiesByLocation

(Sphere sphere)

 Returns all entities in the sector whose bounding spheres intersect with the given sphere. **Entities without a bounding sphere component will not be considered.**
 Complexity: O(logn)

Parameters

```
           sphere The intersected sphere

```

Returns

 Multiple return values: All matching entities in the sector

```
           function Entity...

```

### getEntitiesByFaction

(int factionIndex)

 Returns all entities in the sector that belong to the given faction Complexity: O(n)

Parameters

```
           factionIndex The desired faction

```

Returns

 Multiple return values: All matching entities in the sector

```
           function Player...

```

### getPlayers

()

 Returns all players that are currently in the sector

Returns

 Multiple return values: All players in the sector

```
           function

```

### broadcastChatMessage

(string sender, int messageType, string message, string... arguments)

 Broadcast a chat message to all players that are currently in the sector.

Parameters

```
           message The message that will be sent

           sender The sender that will be displayed for the chat message

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

```

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