Trigger API Reference DCEI Functions Unit2 - funovus/editor-wiki GitHub Wiki

Table of Contents
- [Trigger API Reference\DCEI Functions\Unit (3/3)](#trigger-api-referencedcei-functionsunit-33) * [object GetWaypointPaths(bool includeRallyDisabledLanes)](#object-getwaypointpathsbool-includerallydisabledlanes) * [Float2 GetWaypointPathStartPosition(string name, float dispersal)](#float2-getwaypointpathstartpositionstring-name-float-dispersal) * [void FollowUnit(unit unit, unit targetUnit, float offsetX, float offsetY, float distanceMax)](#void-followunitunit-unit-unit-targetunit-float-offsetx-float-offsety-float-distancemax) * [void ClearFollowUnit(unit unit)](#void-clearfollowunitunit-unit) * [void SelectUnit(unit unit)](#void-selectunitunit-unit) * [void SelectUnitSync(unit unit)](#void-selectunitsyncunit-unit) * [void DeselectUnit(unit unit)](#void-deselectunitunit-unit) * [void DeselectUnitSync(unit unit)](#void-deselectunitsyncunit-unit) * [unit FindUnit(string name)](#unit-findunitstring-name) * [object FindUnitsByPlayerId(int playerId)](#object-findunitsbyplayeridint-playerid) * [object FindUnitsByTeamId(int teamId)](#object-findunitsbyteamidint-teamid) * [object FindUnits(string name)](#object-findunitsstring-name) * [unit FindUnitAtPosition(string name, float x, float z)](#unit-findunitatpositionstring-name-float-x-float-z) * [bool IsUnitSelected(unit unit)](#bool-isunitselectedunit-unit)

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

object GetWaypointPaths(bool includeRallyDisabledLanes) {object-GetWaypointPathsbool-includeRallyDisabledLanes}

object GetWaypointPaths(bool includeRallyDisabledLanes)

Description

Parameters

Example Usage

Related

Float2 GetWaypointPathStartPosition(string name, float dispersal) {Float2-GetWaypointPathStartPositionstring-name-float-dispersal}

Float2 GetWaypointPathStartPosition(string name, float dispersal)

Description

Parameters

Example Usage

Related

void FollowUnit(unit unit, unit targetUnit, float offsetX, float offsetY, float distanceMax) {void-FollowUnitunit-unit-unit-targetUnit-float-offsetX-float-offsetY-float-distanceMax}

void FollowUnit(unit unit, unit targetUnit, float offsetX, float offsetY, float distanceMax)

Description

Commands a unit to follow another unit.

Parameters

  • unit unit the unit to command.
  • unit targetUnit the unit to follow.
  • float offsetX
  • float offsetY
  • float distanceMax if the distance between the units becomes larger than this, the follower unit will move towards the target unit.

Example Usage

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

DCEI.FollowUnit(unit, target, 1.0, 1.0, 2.0)

DCEI.Move(target, 10, 10)

void ClearFollowUnit(unit unit) {void-ClearFollowUnitunit-unit}

void ClearFollowUnit(unit unit)

Description

Clears the order for a unit to follow another unit.

Parameters

  • unit unit the unit to command.

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, y)

DCEI.FollowUnit(unit, target, 1.0, 1.0, 2.0)

DCEI.Move(target, 10, 10)

DCEI.TriggerAddTimerEventElapsed(function()
    DCEI.ClearFollowUnit(unit)
end, 2.0, false, true)

void SelectUnit(unit unit) {void-SelectUnitunit-unit}

void SelectUnit(unit unit)

Description

Selects a unit for the player.

Parameters

  • unit unit the unit to select.

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.SelectUnit(unit)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
end

DCEI.TriggerAddTimerEventElapsed(function()
    DCEI.Deselect(unit)
end, 2.0, false, true)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
else
    DCEI.LogMessage(unit_type .. " is not selected.")
end

Related

void SelectUnitSync(unit unit) {void-SelectUnitSyncunit-unit}

void SelectUnitSync(unit unit)

Description

Selects a unit for the player.

Parameters

  • unit unit the unit to select.

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.SelectUnit(unit)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
end

DCEI.TriggerAddTimerEventElapsed(function()
    DCEI.Deselect(unit)
end, 2.0, false, true)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
else
    DCEI.LogMessage(unit_type .. " is not selected.")
end

Related

void DeselectUnit(unit unit) {void-DeselectUnitunit-unit}

void DeselectUnit(unit unit)

Description

Deselects a unit.

Parameters

  • unit unit the unit to deselect.

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.SelectUnit(unit)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
end

DCEI.TriggerAddTimerEventElapsed(function()
    DCEI.Deselect(unit)
end, 2.0, false, true)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
else
    DCEI.LogMessage(unit_type .. " is not selected.")
end

Related

void DeselectUnitSync(unit unit) {void-DeselectUnitSyncunit-unit}

void DeselectUnitSync(unit unit)

Description

Deselects a unit.

Parameters

  • unit unit the unit to deselect.

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.SelectUnit(unit)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
end

DCEI.TriggerAddTimerEventElapsed(function()
    DCEI.Deselect(unit)
end, 2.0, false, true)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
else
    DCEI.LogMessage(unit_type .. " is not selected.")
end

Related

unit FindUnit(string name) {unit-FindUnitstring-name}

unit FindUnit(string name)

Description

Attempts to return an existing unit from its name.

Parameters

  • string name the name of the unit type to find.

Example Usage

local unit_type = "Standard MeleeUnit"
local x, y = 12, 12
local unit = {}
local i
for i = 1, 5 do
    unit[i] = DCEI.CreateUnit(i, i % 2, unit_type, x+i, y+i)
    DCEI.SetHealth(unit[i], i)
end

local test_subject = DCEI.FindUnit(unit_type)

local hp = DCEI.GetHealth(test_subject)
DCEI.LogMessage(unit_type .. " has " .. hp .. " hp currently.")
DCEI.SetUnitPosition2D(test_subject,14,10)

test_subject = DCEI.FindUnitAtPosition(unit_type, 14,14)
DCEI.LogMessage(DCEI.UnitName(test_subject) .. " owned by player " .. DCEI.UnitPlayerId(test_subject) .. " is at " .. DCEI.GetUnitPosition2D(test_subject).x .. ", " .. DCEI.GetUnitPosition2D(test_subject).y .. " currently.")

Related

object FindUnitsByPlayerId(int playerId) {object-FindUnitsByPlayerIdint-playerId}

object FindUnitsByPlayerId(int playerId)

Description

Returns a list of all units owned by a player.

Parameters

  • int playerId the player id to search for units by.

Example Usage

local unit_type = "Standard MeleeUnit"
local x, y = 12, 12
local unit = {}
local i
for i = 1, 5 do
    unit[i] = DCEI.CreateUnit(i, i % 2, unit_type, x+i, y+i)
    DCEI.SetHealth(unit[i], i)
end

local group = DCEI.FindUnitsByPlayerId(1)

for _, unit in ipairs(group) do
    DCEI.LogMessage(DCEI.UnitName(unit) .. " owned by player " .. DCEI.UnitPlayerId(unit) .. " is at " .. DCEI.GetUnitPosition2D(unit).x .. ", " .. DCEI.GetUnitPosition2D(unit).y .. " currently.")
end

Related

object FindUnitsByTeamId(int teamId) {object-FindUnitsByTeamIdint-teamId}

object FindUnitsByTeamId(int teamId)

Description

Returns a list of all units that belong to the specified team.

Parameters

  • int teamId the team id to search for units by.

Example Usage

local unit_type = "Standard MeleeUnit"
local x, y = 12, 12
local unit = {}
local i
for i = 1, 5 do
    unit[i] = DCEI.CreateUnit(i, i % 2, unit_type, x+i, y+i)
    DCEI.SetHealth(unit[i], i)
end

local group = DCEI.FindUnitsByTeamId(1)

for _, unit in ipairs(group) do
    DCEI.LogMessage(DCEI.UnitName(unit) .. " owned by player " .. DCEI.UnitPlayerId(unit) .. " is at " .. DCEI.GetUnitPosition2D(unit).x .. ", " .. DCEI.GetUnitPosition2D(unit).y .. " currently.")
end

Related

object FindUnits(string name) {object-FindUnitsstring-name}

object FindUnits(string name)

Description

Returns a list of all units with the specified unit name.

Parameters

  • string name the name of the unit type to find.

Example Usage

local unit_type = "Standard MeleeUnit"
local x, y = 12, 12
local unit = {}
local i
for i = 1, 5 do
    unit[i] = DCEI.CreateUnit(i, i % 2, unit_type, x+i, y+i)
    DCEI.SetHealth(unit[i], i)
end

local group = DCEI.FindUnits(unit_type)

for _, unit in ipairs(group) do
    DCEI.LogMessage(DCEI.UnitName(unit) .. " owned by player " .. DCEI.UnitPlayerId(unit) .. " is at " .. DCEI.GetUnitPosition2D(unit).x .. ", " .. DCEI.GetUnitPosition2D(unit).y .. " currently.")
end

Related

unit FindUnitAtPosition(string name, float x, float z) {unit-FindUnitAtPositionstring-name-float-x-float-z}

unit FindUnitAtPosition(string name, float x, float z)

Description

Returns the unit with the given name closest to the given coordinates.

Parameters

  • string name the name of the unit type to find.
  • float x the x-coordinate of the point to search for the unit at.
  • float z the y-coordinate of the point to search for the unit at.

Example Usage

local unit_type = "Standard MeleeUnit"
local x, z = 12, 12
local unit = {}
local i
for i = 1, 5 do
    unit[i] = DCEI.CreateUnit(i, i % 2, unit_type, x + i, y + i)
    DCEI.SetHealth(unit[i], i)
end

local test_subject = DCEI.FindUnit(unit_type)

local hp = DCEI.GetHealth(test_subject)
DCEI.LogMessage(unit_type .. " has " .. hp .. " hp currently.")
DCEI.SetUnitPosition2D(test_subject, 14, 10)

test_subject = DCEI.FindUnitAtPosition(unit_type, 14, 14)
DCEI.LogMessage(DCEI.UnitName(test_subject) .. " owned by player " .. DCEI.UnitPlayerId(test_subject) .. " is at " .. DCEI.GetUnitPosition2D(test_subject).x .. ", " .. DCEI.GetUnitPosition2D(test_subject).y .. " currently.")

Related

bool IsUnitSelected(unit unit) {bool-IsUnitSelectedunit-unit}

bool IsUnitSelected(unit unit)

Description

Returns true if the unit is selected.

Parameters

  • unit unit the unit to check.

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.SelectUnit(unit)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
end

DCEI.TriggerAddTimerEventElapsed(function()
    DCEI.Deselect(unit)
end, 2.0, false, true)

if DCEI.IsUnitSelected then
    DCEI.LogMessage(unit_type .. " is selected.")
else
    DCEI.LogMessage(unit_type .. " is not selected.")
end

Related

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