Trigger API Reference DCEI Functions Unit0 - BLKTower/TestWiki GitHub Wiki

Table of Contents

Trigger API Reference\DCEI Functions\Unit (1/3) {Trigger-API-ReferenceDCEI-FunctionsUnit-13}

unit CreateUnitFilter(UnitFilter filter) {unit-CreateUnitFilterUnitFilter-filter}

unit CreateUnitFilter(UnitFilter filter)

Description

Create a unit with the unit filter.

Parameters

  • UnitFilter filter the unit filter to create.

Example Usage

local unit_filter = DCEI.CreateUnitFilter({team = 1, name = "Standard MeleeUnit"})

unit CreateUnit(int teamId, int playerId, string unitType, float x, float z, float dx, float dz) {unit-CreateUnitint-teamId-int-playerId-string-unitType-float-x-float-z-float-dx-float-dz}

unit CreateUnit(int teamId, int playerId, string unitType, float x, float z, float dx, float dz)

Description

Creates a unit at the specified location using default facing.

Parameters

  • int teamId which team to create the unit for. Use 1 for local player and -1 for enemy.
  • int playerId which player to create the unit for. Use 1 for local player and -1 for enemy.
  • string unitTypeName the unit type to create.
  • float x the x coordinate of where to create the unit.
  • float z the y coordinate of where to create the unit.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, z = 16, 16
DCEI.CreateUnit(team_id, player_id, unit_type, x, z)

Related

void KillUnit(unit unit) {void-KillUnitunit-unit}

void KillUnit(unit unit)

Description

Kills a unit.

Parameters

  • unit unit the unit to kill.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
DCEI.KillUnitAsync(unit)

Related

void RemoveUnit(unit unit) {void-RemoveUnitunit-unit}

void RemoveUnit(unit unit)

Description

Parameters

Example Usage

void RemoveUnitSync(unit unit) {void-RemoveUnitSyncunit-unit}

void RemoveUnitSync(unit unit)

⚠️Warning⚠️: This api was deprecated at 7/19/2022, and will be removed after 90 days.

Description

Removes a unit.

Parameters

  • unit unit the unit to remove.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, z = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, z)
DCEI.RemoveUnitSync(unit)

Related

string GetUnitType(unit unit) {string-GetUnitTypeunit-unit}

string GetUnitType(unit unit)

Description

Returns the unit name as a string.

Parameters

  • unit unit the unit to get the name of.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local unit_name = DCEI.UnitName(unit)

-- prints "Standard MeleeUnit
DCEI.LogMessage(unit_name)

double GetUnitTypeHealth(string unitType) {double-GetUnitTypeHealthstring-unitType}

double GetUnitTypeHealth(string unitType)

Description

Returns the maximum health for a unit type.

Parameters

  • string unitType the unit type to get the health of.

Example Usage

local unit_type = "Standard MeleeUnit"
local health = DCEI.GetUnitTypeHealth(unit_type)
DCEI.LogMessage(health)

Related

string GetUnitDisplayName(unit unit) {string-GetUnitDisplayNameunit-unit}

string GetUnitDisplayName(unit unit)

Description

Returns the Display Name of a unit as a string.

Parameters

  • unit unit the unit whose display name to get.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local display_name = DCEI.UnitDisplayName(unit)
DCEI.LogMessage(display_name)

Related

string GetUnitCategory(unit unit) {string-GetUnitCategoryunit-unit}

string GetUnitCategory(unit unit)

Description

Returns the unit category of a unit as a string (Unit, Missile, or Structure).

Parameters

  • unit unit the unit whose unit category to get.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local unit_category = DCEI.UnitType(unit)

-- prints "Unit"
DCEI.LogMessage(unit_category)

void Move(unit unit, float x, float z) {void-Moveunit-unit-float-x-float-z}

void Move(unit unit, float x, float z)

Description

Issues an order for a unit to move to a target point.

Parameters

  • unit target the unit to issue the order to.
  • float x the x-axis coordinate to move towards.
  • float z the z-axis coordinate to move towards.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.TriggerAddUnitMoveCommandEvent(unit, OnUnitMoveCommand)

function OnUnitMoveCommand(destination)
    local unit = DCEI.TriggeringUnit
    local unit_name = DCEI.UnitName(unit)
    local position = DCEI.GetUnitPosition2D(unit)

    local message = string.format("%q is moving to (%.2f, %.2f) from (%.2f, %.2f).", unit_name, destination.x, destination.y, position.x, position.y)
    DCEI.LogMessage(message)
end

DCEI.Move(unit, 15, 15)

Related

void Attack(unit unit, unit target) {void-Attackunit-unit-unit-target}

void Attack(unit unit, unit target)

Description

Issues an order for a unit to attack another unit, causing it to move to get in range if necessary.

Parameters

  • unit unit the attacking unit.
  • unit target the unit to attack.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local target = DCEI.CreateUnit(team_id, player_id, unit_type, x + 1, y + 1)

DCEI.Attack(unit, target)

Related

void DirectionalMove(unit target, float right, float up) {void-DirectionalMoveunit-target-float-right-float-up}

void DirectionalMove(unit target, float right, float up)

Description

Issues an order for the unit to move in a specified direction.

Notes: The unit will not attempt to navigate around units or obstacles when using Directional Move. This function only runs for a single frame. To have the unit continue to move in a specific direction, this function must be run each frame. This useful for games with that use WASD or joystick movement to control units.

Parameters

  • unit unit the unit to issue the move order to.
  • float right a value between -1.0 and 1.0 that indicates the relative speed and direction to move along the x-axis.
  • float up a value between -1.0 and 1.0 that indicates the relative speed and direction to move along the y-axis.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

function OnJoystickMove()
    local axes = DCEI.TriggeringJoystickAxes
    -- order unit to move in direction of joystick axes
    DCEI.LogMessage("(" .. axes.x .. ", " .. axes.y .. ")")
    DCEI.DirectionalMove(unit, axes.x, axes.y)
end

DCEI.TriggerAddJoystickEvent(OnJoystickMove)

Related

void TurnUnitTowards(unit unit, float dx, float dz, float duration) {void-TurnUnitTowardsunit-unit-float-dx-float-dz-float-duration}

void TurnUnitTowards(unit unit, float dx, float dz, float duration)

Description

Turns a unit to face towards a specified direction.

Parameters

  • unit unit the unit to turn.
  • float right a value between -1.0 and 1.0 that indicates the relative direction to face along the x-axis.
  • float up a value between -1.0 and 1.0 that indicates the relative direction at to face along y-axis.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

-- Make the unit face southwest
DCEI.TurnUnitTowards(unit, -1.0,-1.0, 3.0)

Related

float GetHealth(unit unit) {float-GetHealthunit-unit}

float GetHealth(unit unit)

Description

Returns the current health of a unit.

Parameters

  • unit unit the unit to check.

Example Usage

DCEI.TriggerAddTimerEventElapsed(function()
    local team_id = 1
    local player_id = 1
    local unit_type = "Standard MeleeUnit"
    local x, y = 16, 16
    local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
    DCEI.Wait(1)

    DCEI.SetHealth(unit, 5)
    DCEI.SetMaxHealth(unit, 30)
    local hp = DCEI.GetHealth(unit)
    local max_hp = DCEI.GetMaxHealth(unit)
    DCEI.LogMessage(unit_type .. " has " .. hp .. "/" .. max_hp .. " hp currently.")

    DCEI.AddHealth(unit, 10)
    hp = DCEI.GetHealth(unit)
    DCEI.LogMessage(unit_type .. " has " .. hp .. "/" .. max_hp .. " hp currently.")
end, 
0)

void AddHealth(unit unit, float value) {void-AddHealthunit-unit-float-value}

void AddHealth(unit unit, float value)

Description

Increases the current health of a unit.

Parameters

  • unit unit the unit to add health to.
  • float value the amount of health to add.

Example Usage

DCEI.TriggerAddTimerEventElapsed(function()
    local team_id = 1
    local player_id = 1
    local unit_type = "Standard MeleeUnit"
    local x, y = 16, 16
    local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
    DCEI.Wait(1)

    DCEI.SetHealth(unit, 5)
    DCEI.SetMaxHealth(unit, 30)
    local hp = DCEI.GetHealth(unit)
    DCEI.LogMessage(unit_type .. " has " .. hp .. " hp currently.")

    DCEI.AddHealth(unit, 10)
    hp = DCEI.GetHealth(unit)
    DCEI.LogMessage(unit_type .. " has " .. hp .. " hp currently.")
end, 
0)

void SetHealth(unit unit, float value) {void-SetHealthunit-unit-float-value}

void SetHealth(unit unit, float value)

Description

Sets the current health of a unit.

Parameters

  • unit unit the unit to set the health of.
  • float value the amount to set it to.

Example Usage

DCEI.TriggerAddTimerEventElapsed(function()
    local team_id = 1
    local player_id = 1
    local unit_type = "Standard MeleeUnit"
    local x, y = 16, 16
    local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
    DCEI.Wait(1)

    DCEI.SetHealth(unit, 5)
    DCEI.SetMaxHealth(unit, 30)
    local hp = DCEI.GetHealth(unit)
    local max_hp = DCEI.GetMaxHealth(unit)
    DCEI.LogMessage(unit_type .. " has " .. hp .. "/" .. max_hp .. " hp currently.")

    DCEI.AddHealth(unit, 10)
    hp = DCEI.GetHealth(unit)
    DCEI.LogMessage(unit_type .. " has " .. hp .. "/" .. max_hp .. " hp currently.")
end, 
0)

void SetUnitOwner(unit unit, int playerId) {void-SetUnitOwnerunit-unit-int-playerId}

void SetUnitOwner(unit unit, int playerId)

Description

Sets the owner of a unit.

Parameters

  • unit unit the unit to change ownership of.
  • int playerId the player to give the unit to.

Example Usage

function OnRegionEnter()
    DCEI.SetUnitOwner(DCEI.TriggeringUnit, 2)
    DCEI.LogMessage(DCEI.UnitPlayerId(DCEI.TriggeringUnit))
end

DCEI.TriggerAddUnitEnterRegionEvent(DCEI.UnitAny, DCEI.RegionAny, OnRegionEnter)

void SetUnitTeamId(unit unit, int teamId) {void-SetUnitTeamIdunit-unit-int-teamId}

void SetUnitTeamId(unit unit, int teamId)

Description

Sets the team id of a unit.

Parameters

  • unit unit the unit to change ownership of.
  • int teamId the team ID to assign to the unit.

Example Usage

function OnRegionEnter()
    DCEI.SetUnitTeamId(DCEI.TriggeringUnit, 2)
    DCEI.LogMessage(DCEI.UnitTeamId(DCEI.TriggeringUnit))
end

DCEI.TriggerAddUnitEnterRegionEvent(DCEI.UnitAny, DCEI.RegionAny, OnRegionEnter)

float GetMana(unit unit) {float-GetManaunit-unit}

float GetMana(unit unit)

Description

Returns the current mana of a unit.

Parameters

  • unit unit the unit to check.

Example Usage

DCEI.TriggerAddTimerEventElapsed(function()
    local team_id = 1
    local player_id = 1
    local unit_type = "Standard MeleeUnit"
    local x, y = 16, 16
    local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
    DCEI.Wait(1)

    DCEI.SetMaxMana(unit, 20)
    DCEI.SetMana(unit, 5)
    local mana = DCEI.GetMana(unit)
    local max_mana = DCEI.GetMaxMana(unit)
    DCEI.LogMessage(unit_type .. " has " .. mana .. "/" .. max_mana .. " mana currently.")

    DCEI.AddMana(unit, 10)
    mana = DCEI.GetMana(unit)
    DCEI.LogMessage(unit_type .. " has " .. mana .. "/" .. max_mana .. " mana currently.")
end, 
0)

void AddMana(unit unit, float value) {void-AddManaunit-unit-float-value}

void AddMana(unit unit, float value)

Description

Increases the current mana of a unit.

Parameters

  • unit unit the unit to add mana to.
  • float value the amount to add.

Example Usage

DCEI.TriggerAddTimerEventElapsed(function()
    local team_id = 1
    local player_id = 1
    local unit_type = "Standard MeleeUnit"
    local x, y = 16, 16
    local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
    DCEI.Wait(1)

    DCEI.SetMaxMana(unit, 20)
    DCEI.SetMana(unit, 5)
    local mana = DCEI.GetMana(unit)
    local max_mana = DCEI.GetMaxMana(unit)
    DCEI.LogMessage(unit_type .. " has " .. mana .. "/" .. max_mana .. " mana currently.")

    DCEI.AddMana(unit, 10)
    mana = DCEI.GetMana(unit)
    DCEI.LogMessage(unit_type .. " has " .. mana .. "/" .. max_mana .. " mana currently.")
end, 
0)

void SetMana(unit unit, float value) {void-SetManaunit-unit-float-value}

void SetMana(unit unit, float value)

Description

Sets the current mana of a unit.

Parameters

  • unit unit the unit to add mana to.
  • float value the amount to set it to.

Example Usage

DCEI.TriggerAddTimerEventElapsed(function()
    local team_id = 1
    local player_id = 1
    local unit_type = "Standard MeleeUnit"
    local x, y = 16, 16
    local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
    DCEI.Wait(1)

    DCEI.SetMaxMana(unit, 20)
    DCEI.SetMana(unit, 5)
    local mana = DCEI.GetMana(unit)
    local max_mana = DCEI.GetMaxMana(unit)
    DCEI.LogMessage(unit_type .. " has " .. mana .. "/" .. max_mana .. " mana currently.")

    DCEI.AddMana(unit, 10)
    mana = DCEI.GetMana(unit)
    DCEI.LogMessage(unit_type .. " has " .. mana .. "/" .. max_mana .. " mana currently.")
end, 
0)

Float2 GetUnitFacing2D(unit unit) {Float2-GetUnitFacing2Dunit-unit}

Float2 GetUnitFacing2D(unit unit)

Description

Returns the facing of a unit as a vector with X and Y coordinates.

Parameters

  • unit unit the unit to get the position of.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

local facing = DCEI.GetUnitFacing2D(unit)
DCEI.LogMessage(unit_type .. " is facing " .. facing.x .. ", " .. facing.y)

Related

float GetUnitBounty(unit unit) {float-GetUnitBountyunit-unit}

float GetUnitBounty(unit unit)

Description

Returns the bounty of a unit.

Parameters

  • unit unit the unit to get the bounty of.

Example Usage

local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.SetGoldBounty(unit, 5.0)
local bounty = DCEI.GetUnitBounty(unit)
DCEI.LogMessage(unit_type .. " has a bounty of " .. bounty .. " gold.")

Related

object GetUnitBehaviorList(unit unit) {object-GetUnitBehaviorListunit-unit}

object GetUnitBehaviorList(unit unit)

Description

Returns a list of behaviors on a unit along with their stack count.

Parameters

  • unit unit the unit to get the list of behaviors from.

Example Usage

local behaviors = DCEI.GetUnitBehaviorList(unit)
for _, behavior in ipairs(behaviors) do
    DCEI.LogMessage(behavior.name .. ": " .. behavior.stack_count)
end

object GetUnitWeaponList(unit unit) {object-GetUnitWeaponListunit-unit}

object GetUnitWeaponList(unit unit)

Description

Returns a list of weapons on a unit.

Parameters

  • unit unit the unit to get the list of weapons from.

Example Usage

local weapons = DCEI.GetUnitWeaponList(unit)
for _, weapon in ipairs(weapons) do
    DCEI.LogMessage(weapon)
end

Related

object GetUnitAbilityList(unit unit) {object-GetUnitAbilityListunit-unit}

object GetUnitAbilityList(unit unit)

Description

Returns a list of abilities on a unit.

Parameters

  • unit unit the unit to get the list of abilities from.

Example Usage

local abilities = DCEI.GetUnitAbilityList(unit)
for _, ability in ipairs(abilities) do
    DCEI.LogMessage(ability)
end

void ApplyTag(unit unit, string tagName, float duration, int stackCount) {void-ApplyTagunit-unit-string-tagName-float-duration-int-stackCount}

void ApplyTag(unit unit, string tagName, float duration, int stackCount)

Description

Applies a set number of tags to a unit for a set duration.

Parameters

  • unit unit the unit to apply the tags to.
  • string tagName the name of the tag to apply.
  • float duration the length of time to apply the tag for. A value of -1 applies it permanently.
  • int stackCount the number of tags to apply.

Example Usage

-- Requires "Banana" added as a used tag in Trigger Settings
local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.ApplyTag(unit, "Banana", -1, 5)
local tag_count = DCEI.GetUnitTagCount(unit, "Banana")
DCEI.LogMessage(tag_count)


DCEI.RemoveTag(unit, "Banana", 2)
tag_count = DCEI.GetUnitTagCount(unit, "Banana")
DCEI.LogMessage(tag_count)

void RemoveTag(unit unit, string tagName, int stackCount) {void-RemoveTagunit-unit-string-tagName-int-stackCount}

void RemoveTag(unit unit, string tagName, int stackCount)

Description

Removes a set number of tags from a unit.

Parameters

  • unit unit the unit to remove the tags from.
  • string tagName the name of the tag to remove.
  • int stackCount the number of tags to remove.

Example Usage

-- Requires "Banana" added as a used tag in Trigger Settings
local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.ApplyTag(unit, "Banana", -1, 5)
local tag_count = DCEI.GetUnitTagCount(unit, "Banana")
DCEI.LogMessage(tag_count)


DCEI.RemoveTag(unit, "Banana", 2)
tag_count = DCEI.GetUnitTagCount(unit, "Banana")
DCEI.LogMessage(tag_count)

int GetUnitTagCount(unit unit, string tagName) {int-GetUnitTagCountunit-unit-string-tagName}

int GetUnitTagCount(unit unit, string tagName)

Description

Returns the tag count of a given tag on a unit.

Parameters

  • unit unit the unit to count the tags on.
  • string tagName the name of the tag to count.

Example Usage

-- Requires "Banana" added as a used tag in Trigger Settings
local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.ApplyTag(unit, "Banana", -1, 5)
local tag_count = DCEI.GetUnitTagCount(unit, "Banana")
DCEI.LogMessage(tag_count)


DCEI.RemoveTag(unit, "Banana", 2)
tag_count = DCEI.GetUnitTagCount(unit, "Banana")
DCEI.LogMessage(tag_count)

object GetUnitTagList(unit unit) {object-GetUnitTagListunit-unit}

object GetUnitTagList(unit unit)

Description

Returns a list of tags on a unit

Parameters

  • unit unit the unit to get the total damage of.

Example Usage

local tags = DCEI.GetUnitTagList(unit)
for _, tag in ipairs(tags) do
    DCEI.LogMessage(tag)
end

⚠️ **GitHub.com Fallback** ⚠️