# Module `Database`

Manage sets of units and groups.

# #Database class

Mission designers can use the DATABASE class to build sets of units belonging to certain:

- Coalitions
- Categories
- Countries
- Unit types
- Starting with certain prefix strings.

This list will grow over time. Planned developments are to include filters and iterators. Additional filters will be added around Zone#ZONEs, Radiuses, Active players, ... More iterators will be implemented in the near future ...

Administers the Initial Sets of the Mission Templates as defined within the Mission Editor.

# DATABASE construction methods:

Create a new DATABASE object with the DATABASE.New method:

- DATABASE.New: Creates a new DATABASE object.

# DATABASE filter criteria:

You can set filter criteria to define the set of units within the database. Filter criteria are defined by:

- DATABASE.FilterCoalitions: Builds the DATABASE with the units belonging to the coalition(s).
- DATABASE.FilterCategories: Builds the DATABASE with the units belonging to the category(ies).
- DATABASE.FilterTypes: Builds the DATABASE with the units belonging to the unit type(s).
- DATABASE.FilterCountries: Builds the DATABASE with the units belonging to the country(ies).
- DATABASE.FilterUnitPrefixes: Builds the DATABASE with the units starting with the same prefix string(s).

Once the filter criteria have been set for the DATABASE, you can start filtering using:

- DATABASE.FilterStart: Starts the filtering of the units within the database.

Planned filter criteria within development are (so these are not yet available):

- DATABASE.FilterGroupPrefixes: Builds the DATABASE with the groups of the units starting with the same prefix string(s).
- DATABASE.FilterZones: Builds the DATABASE with the units within a Zone#ZONE.

# DATABASE iterators:

Once the filters have been defined and the DATABASE has been built, you can iterate the database with the available iterator methods. The iterator methods will walk the DATABASE set, and call for each element within the set a function that you provide. The following iterator methods are currently available within the DATABASE:

- DATABASE.ForEachAliveUnit: Calls a function for each alive unit it finds within the DATABASE.

Planned iterators methods in development are (so these are not yet available):

- DATABASE.ForEachUnit: Calls a function for each unit contained within the DATABASE.
- DATABASE.ForEachGroup: Calls a function for each group contained within the DATABASE.
- DATABASE.ForEachUnitInZone: Calls a function for each unit within a certain zone contained within the DATABASE.

## Global(s)

DATABASE |

## Type `DATABASE`

DATABASE.AlivePlayers |
DATABASE.ClassName |
DATABASE.ClientsByID |
DATABASE.ClientsByName |
DATABASE.DCSGroups |
DATABASE.DCSGroupsAlive |
DATABASE.DCSUnits |
DATABASE.DCSUnitsAlive |
DATABASE.Filter |
DATABASE:FilterCategories(Categories) | Builds a set of units out of categories.
DATABASE:FilterCoalitions(Coalitions) | Builds a set of units of coalitons.
DATABASE:FilterCountries(Countries) | Builds a set of units of defined countries.
DATABASE:FilterGroupPrefixes(Prefixes) | Builds a set of units of defined group prefixes.
DATABASE.FilterMeta |
DATABASE:FilterStart() | Starts the filtering.
DATABASE:FilterTypes(Types) | Builds a set of units of defined unit types.
DATABASE:FilterUnitPrefixes(Prefixes) | Builds a set of units of defined unit prefixes.
DATABASE:ForEachAliveUnit(IteratorFunction, ...) | Interate the DATABASE and call an interator function for each alive unit, providing the Unit and optional parameters.
DATABASE:GetStatusGroup(GroupName) | Get a status to a Group within the Database, this to check crossing events for example.
DATABASE.Groups |
DATABASE.NavPoints |
DATABASE:New() | Creates a new DATABASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
DATABASE.Players |
DATABASE:ScanEnvironment() |
DATABASE:SetStatusGroup(GroupName, Status) | Set a status to a Group within the Database, this to check crossing events for example.
DATABASE:Spawn(SpawnTemplate) | Instantiate new Groups within the DCSRTE.
DATABASE.Statics |
DATABASE:TraceDatabase() | Traces the current database contents in the log ...
DATABASE.Units |
DATABASE:_EventOnBirth(Event) | Handles the OnBirth event for the alive units set.
DATABASE:_EventOnDeadOrCrash(Event) | Handles the OnDead or OnCrash event for alive units set.
DATABASE:_IsAliveDCSUnit(DCSUnit) |
DATABASE:_IsIncludeDCSUnit(DCSUnit) |
DATABASE:_RegisterGroup(GroupTemplate) | Registers new Group Templates within the DATABASE Object.

## Global(s)

#DATABASE DATABASE

## Type `Database`

DATABASE class

### Field(s)

DATABASE.AlivePlayers

#string DATABASE.ClassName

DATABASE.ClientsByID

DATABASE.ClientsByName

DATABASE.DCSGroups

DATABASE.DCSGroupsAlive

DATABASE.DCSUnits

DATABASE.DCSUnitsAlive

DATABASE.Filter

DATABASE:FilterCategories(Categories)

  Builds a set of units out of categories.

  Possible current categories are plane, helicopter, ground, ship.

  ### Parameter

  - `#string Categories` : Can take the following values: "plane", "helicopter", "ground", "ship".

  ### Return value

  #DATABASE: self

DATABASE:FilterCoalitions(Coalitions)

  Builds a set of units of coalitons.

  Possible current coalitions are red, blue and neutral.

  ### Parameter

  - `#string Coalitions` : Can take the following values: "red", "blue", "neutral".

  ### Return value

  #DATABASE: self

DATABASE:FilterCountries(Countries)

  Builds a set of units of defined countries.

  Possible current countries are those known within DCS world.

  ### Parameter

  - `#string Countries` : Can take those country strings known within DCS world.

  ### Return value

  #DATABASE: self

DATABASE:FilterGroupPrefixes(Prefixes)

  Builds a set of units of defined group prefixes.

  All the units starting with the given group prefixes will be included within the set.

  ### Parameter

  - `#string Prefixes` : The prefix of which the group name where the unit belongs to starts with.

  ### Return value

  #DATABASE: self

DATABASE.FilterMeta

DATABASE:FilterStart()

  Starts the filtering.

  ### Return value

  #DATABASE: self

DATABASE:FilterTypes(Types)

  Builds a set of units of defined unit types.

  Possible current types are those types known within DCS world.

  ### Parameter

  - `#string Types` : Can take those type strings known within DCS world.

  ### Return value

  #DATABASE: self

DATABASE:FilterUnitPrefixes(Prefixes)

  Builds a set of units of defined unit prefixes.

  All the units starting with the given prefixes will be included within the set.

  ### Parameter

  - `#string Prefixes` : The prefix of which the unit name starts with.

  ### Return value

  #DATABASE: self

DATABASE:ForEachAliveUnit(IteratorFunction, ...)

  Interate the DATABASE and call an interator function for each alive unit, providing the Unit and optional parameters.

  ### Parameters

  - `#function IteratorFunction` : The function that will be called when there is an alive unit in the database. The function needs to accept a UNIT parameter.

  - `...` :

  ### Return value

  #DATABASE: self

DATABASE:GetStatusGroup(GroupName)

  Get a status to a Group within the Database, this to check crossing events for example.

  ### Parameter

  - `GroupName` :

DATABASE.Groups

DATABASE.NavPoints

DATABASE:New()

  Creates a new DATABASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.

  ### Return value

  #DATABASE:

  ### Usage:

      -- Define a new DATABASE Object. This DBObject will contain a reference to all Group and Unit Templates defined within the ME and the DCSRTE.
      DBObject = DATABASE:New()

DATABASE.Players

DATABASE:ScanEnvironment()

DATABASE:SetStatusGroup(GroupName, Status)

  Set a status to a Group within the Database, this to check crossing events for example.

  ### Parameters

  - `GroupName` :

  - `Status` :

DATABASE:Spawn(SpawnTemplate)

  Instantiate new Groups within the DCSRTE.

  This method expects EXACTLY the same structure as a structure within the ME, and needs 2 additional fields defined: SpawnCountryID, SpawnCategoryID This method is used by the SPAWN class.

  ### Parameter

  - `SpawnTemplate` :

DATABASE.Statics

DATABASE:TraceDatabase()

  Traces the current database contents in the log ...

  (for debug reasons).

  ### Return value

  #DATABASE: self

DATABASE.Units

DATABASE:_EventOnBirth(Event)

  Handles the OnBirth event for the alive units set.

  ### Parameter

  - `Event#EVENTDATA Event` :

DATABASE:_EventOnDeadOrCrash(Event)

  Handles the OnDead or OnCrash event for alive units set.

  ### Parameter

  - `Event#EVENTDATA Event` :

DATABASE:_IsAliveDCSUnit(DCSUnit)

  ### Parameter

  - `DCSUnit#Unit DCSUnit` :

  ### Return value

  #DATABASE: self

DATABASE:_IsIncludeDCSUnit(DCSUnit)

  ### Parameter

  - `DCSUnit#Unit DCSUnit` :

  ### Return value

  #DATABASE: self

DATABASE:_RegisterGroup(GroupTemplate)

  Registers new Group Templates within the DATABASE Object.

  ### Parameter

  - `GroupTemplate` :