Author: Wizard
Created: June 7th, 2022
Version: 0.0.1
Description:
A dynamic spawn class for groups, units, and statics in DCS World
Features:
- Object Orientated
- Integrated Logging
- Spawn objects from late activated templates
- Spawn objects from custom templates
- Spawn objects from a variable amount of arguments
- Spawn with original group and unit names
- Spawn with a new nickname for the group and its units
- Spawn with a set schedule on repeat
- Spawn units with different payloads
- Spawn units with different liverys
- Spawn from a template
- Spawn from a zone
- Spawn from a zone on the nearest road
- Spawn from a random zone
- Spawn from a Vec3 position
- Spawn from a airbase runway
- Spawn from a airbase parking spot in a hot configuration
- Spawn from a airbase parking spot in a cold configuration
- Various
Setmethods to assign data for the templates to spawn with - Various
Getmethods to acquire data from templates like payloads and liverys - Get open airbase parking spots as well as get the first open spot with the option to filter terminal types
- Mark parking spots at an airbase to determine viable parking spot locations
- Add group, unit, and static Templates into the global
Database
| Field | Type | Description |
|---|---|---|
| Spawn.Version | string | semantic version |
| Spawn.Source | string | script source for dcs.log prefix |
| Spawn.DebugLevel | number | the max log level |
| Spawn.DebugLevels | table | log level enumerators |
| Spawn.Category | table | enumerators for spawn group categories |
| Spawn.Takeoff | table | enumerators for taking off from an airbase |
| Spawn.Skill | table | enumerators for skills |
| Spawn.Waypoint | table | enumerators for waypoints |
Create a new instance of a spawn object by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| templateName | string | ✓ | the group, unit, or static name of the ME Template |
| nickname | string | optional nickname the Spawn object will use instead of its template name |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group") Create a new instance of a Spawn object from a template
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| template | table | ✓ | the template table with required data for spawning |
| nickname | string | optional nickname the Spawn object will use instead of its template name | |
| staticTemplate | boolean | optional boolean if the template is a static object |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local ViperGroupTemplate = Spawn:GetGroupTemplate("Viper Group")
local ViperSpawn = Spawn:NewFromTemplate(ViperGroupTemplate)
local StaticDepotSpawn = Spawn:NewFromTemplate(Spawn:GetStaticTemplate("Static Depot"), nil, true) Create a new instance of a Spawn object from a table of properties
Required Unit Properties:
- type
- countryId
- categoryId
Required Static Properties:
- category
- shapeName
- staticTemplate
Optional Properties:
- skill
- canDrive
- alt
- altType
- heading
- action
- name
- waypoint
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| properties | table | ✓ | table of properties to give to the Spawn object |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
-- Tank Unit
local TankProperties = {}
TankProperties.type = "T-90" -- type required
TankProperties.countryId = country.id.RUSSIA -- countryId required
TankProperties.categoryId = Spawn.Category.Vehicle -- categoryId required
-- Static Tank
local StaticTankProperties = {}
StaticTankProperties.type = "T-90" -- type required
StaticTankProperties.countryId = country.id.RUSSIA -- countryId required
StaticTankProperties.category = "" -- category required
StaticTankProperties.shapeName = "" -- shapeName required Set the Spawn object to keep group or unit names
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| keepGroupName | boolean | true or false to keep the group name of the template | |
| keepUnitNames | boolean | true or false to keep all the unit names for the group template |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local TankSpawn = Spawn:New("Tank Group")
TankSpawn:SetKeepNames(true, true) Set the Spawn object to only allow a certain amount of groups and units to be alive
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| maxAliveGroups | number | ✓ | the max amount of groups that can be alive at a given time |
| maxAliveUnits | number | ✓ | the max amount of unit that can be alive at a given time |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local TankSpawn = Spawn:New("Tank Group")
TankSpawn:SetMaxAlive(2, 2) Set the Spawn object to use a certain heading
converts a degree heading into radians
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| heading | number | ✓ | the heading to give to the group or a unit at spawn time |
| unitId | number | optional unitId to provide for a specific unit within the group |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local TankSpawn = Spawn:New("Tank Group")
TankSpawn:SetHeading(90, 2) Set the spawn object to spawn from a vec3
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| vec | table | ✓ | the vec3 point to spawn at |
| alt | number | ✓ | required for airplanes and helicopters only |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local TankSpawn = Spawn:New("Tank Group")
TankSpawn:SetSpawnVec3(Spawn:GetZoneVec3("spawn zone")) Set the Spawn object to spawn from a zone
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string | ✓ | the name of the trigger zone to spawn at |
| alt | number | ✓ | required for airplanes and helicopters only |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local TankSpawn = Spawn:New("Tank Group")
TankSpawn:SetSpawnZone("spawn zone") Set the Spawn object to spawn from a airbase
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ✓ | the airbase name as seen in DCS to spawn at |
| takeoff | enum | ✓ | use: Spawn.Takeoff |
| spots | array | optional parking spots to provide, otherwise they will be decided by DCS. You can use Spawn:GetFreeParkingSpots(airbaseName) obtain useable spots. |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetSpawnAirbase("Aleppo", Spawn.Takeoff.FromParkingHot) Set the Spawn object to spawn from a random template
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| templateList | array | ✓ | a list of template names where one will be randomly selected each time it spawns |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local spawnList = {
"Tank Group 1",
"Tank Group 2",
"Tank Group 3",
"Tank Group 4",
}
local TankSpawn = Spawn:New("Tank Group")
TankSpawn:SetRandomFromTemplate(spawnList) Set the Spawn objects nickname
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| nickname | string | ✓ | will be used over the template name, unit names will be followed by -Id |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetNickname("Hornet CAP") Set the Spawn object to use a new paylaod
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| payload | table | ✓ | payload to provide to the group or a specifc unit. airplanes and helicopters only. the return of Spawn:GetPayload(unitName) can be used. |
| unitId | number | optional unit Id to set the payload for a specifc unit within the group |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetPayload("Hornet CAP") Set the Spawn object to use a new livery
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| livery | string | ✓ | livery name to provide to the group or specific unit. the return of Spawn:GetLivery(unitName) can be used. |
| unitId | number | optional unit Id to set the livery for a specifc unit within the group |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetLivery("Hornet CAP") Set the Spawn object to use a new skill level
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| skill | string | ✓ | skill level than can be used, can also use Spawn.Skill |
| unitId | number | optional unit Id to set the skill for a specific unit |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetSkill(Spawn.Skill.Random) Set the Spawn object to use a certain debug level
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| level | number | ✓ | max debug level where only set level and below will be used. can use Spawn.DebugLevel |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetDebugLevel(Spawn.DebugLevel.Info) Set the Spawn object to use a specific method for spawning on a repeating schedule
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| method | function | ✓ | the spawn method that will be scheduled |
| params | array | the parameters to give to the method | |
| delay | number | ✓ |
| Return | Type |
|---|---|
| self | Spawn |
Set a spawn hook to capture the event of spawning
| Parameter | Type | Required | Description |
|---|---|---|---|
| spawnHook | string | ✓ | the name of the method to callback to upon spawning |
| Return | Type |
|---|---|
| self | Spawn |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetSpawnHook("OnEventSpawn")
function HornetSpawn:OnEventSpawn(spawnData)
self:Info("%s has spawned", spawnData.GroupName)
end
HornetSpawn:SpawnToWorld()Get the currently spawned DCS Class Group
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | DCSGroup |
Usage:
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SpawnToWorld()
local SpawnedGroup = HornetSpawn:GetSpawnedGroup() Get the currently spawned DCS Class StaticObject
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | DCSStaticObject |
Usage:
local CrateSpawn = Spawn:New("Static Crate")
CrateSpawn:SpawnToWorld()
local SpawnedStatic = CrateSpawn:GetSpawnedStatic() Get a payload table from a unit by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| unitName | string | ✓ | the name of a unit in the database to get a payload table from |
| Return | Type |
|---|---|
| payload | table |
Usage:
local CapPayload = Spawn:GetPayload("CAP Payload")
local HornetSpawn = Spawn:New("Hornet Group")
HornetSpawn:SetPayload(CapPayload)
HornetSpawn:SpawnToWorld() Get a livery name from a unit by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| unitName | string |
| Return | Type |
|---|---|
| liveryName | string |
Get a group template by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| groupName | string |
| Return | Type |
|---|---|
| groupTemplate | table |
Get a unit template by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| unitName | string |
| Return | Type |
|---|---|
| unitTemplate | table |
Get a static template by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| staticName | string |
| Return | Type |
|---|---|
| staticTemplate | table |
Get a template by name
this function also returns a second boolean variable if the template is static
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| templateName | string |
| Return | Type |
|---|---|
| template | table |
Get the Spawn objects base template
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| baseTemplate | table |
Get a empty spawn table for groups and units
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| spawnTemplate | table |
Get a empty spawn table for statics
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| staticSpawnTemplate | table |
Get a zone template by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string |
| Return | Type |
|---|---|
| zoneTemplate | table |
Get a quad zones points by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string |
| Return | Type |
|---|---|
| points | table |
Get a zones radius by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string |
| Return | Type |
|---|---|
| self | number |
Get a zones vec3 points by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string |
| Return | Type |
|---|---|
| vec | table |
Get all the open parking spots at an airbase by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| terminalType | number |
| Return | Type |
|---|---|
| openParkingSpots | table |
Get the first open parking spot an airbase by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| terminalType | number |
| Return | Type |
|---|---|
| openSpot | table |
Get the the terminal data from an airbase by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| spots | number |
| Return | Type |
|---|---|
| terminalData | table |
Get a DCS Group object by its spawn index
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| spawnIndex | number |
| Return | Type |
|---|---|
| self | DCSGroup |
Get a DCS StaticObject by its spawn index
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| spawnIndex | number |
| Return | Type |
|---|---|
| self | DCSStaticObject |
Return true or false if the current Spawn obejct is alive
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| alive | boolean |
Return true or false if the current Spawn group object is alive
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| isAlive | boolean |
Return true or false if the current Spawn static object is alive
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| isAlive | boolean |
Mark the parking spots at an airbase by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string |
| Return | Type |
|---|---|
| none |
Add a group template to the database
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| template | table |
| Return | Type |
|---|---|
| none |
Add a unit template to the database
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| template | table |
| Return | Type |
|---|---|
| none |
Add a static template to the database
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| template | table |
| Return | Type |
|---|---|
| none |
Spawn the object to the world
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object with a spawn method to be scheduled
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| method | function | ||
| params | array | ||
| delay | number |
| Return | Type |
|---|---|
| none |
Respawn the object
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a template
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| template | table | ||
| countryId | number | ||
| categoryId | number | ||
| static | boolean |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a zone by name
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string | ||
| alt | number |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a zone on the nearest road
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a random zone from a list
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneList | array | ||
| alt | number |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a random vec3 in a zone
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| zoneName | string | ||
| alt | number |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a random vec3 within a random radius
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| vec | table | ||
| minRadius | number | ||
| maxRadius | number | ||
| alt | number |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a vec3 on the nearest road
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| vec | table |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a vec3
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| vec | table |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object from a airbase on the runway
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| spots | array |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object at an airbase in a parking spot hot
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| spots | array |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object at an airbase in a parking spot cold
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| spots | array |
| Return | Type |
|---|---|
| self | Spawn |
Spawn an object at an airbase with any takeoff type and any spots
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ | |
| airbaseName | string | ||
| takeoff | enum | ||
| spots | array |
| Return | Type |
|---|---|
| self | Spawn |
Initializes the templates
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | Spawn |
Initialize the templates group and unit names
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | Spawn |
Add the spawn object into the world
| Parameter | Type | Required | Description |
|---|---|---|---|
| self | Spawn | ✓ |
| Return | Type |
|---|---|
| self | Spawn |