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)
Float2 GetWaypointPathStartPosition(string name, float dispersal) {Float2-GetWaypointPathStartPositionstring-name-float-dispersal}
Float2 GetWaypointPathStartPosition(string 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 FollowUnit(unit unit, unit targetUnit, float offsetX, float offsetY, float distanceMax)
Commands a unit to follow another unit.
-
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.
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)
Clears the order for a unit to follow another unit.
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)
Selects a unit for the player.
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
void SelectUnitSync(unit unit)
Selects a unit for the player.
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
void DeselectUnit(unit unit)
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
void DeselectUnitSync(unit unit)
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
unit FindUnit(string name)
Attempts to return an existing unit from its name.
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.")
object FindUnitsByPlayerId(int playerId)
Returns a list of all units owned by a player.
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
object FindUnitsByTeamId(int teamId)
Returns a list of all units that belong to the specified team.
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
object FindUnits(string name)
Returns a list of all units with the specified unit name.
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
unit FindUnitAtPosition(string name, float x, float z) {unit-FindUnitAtPositionstring-name-float-x-float-z}
unit FindUnitAtPosition(string name, float x, float z)
Returns the unit with the given name closest to the given coordinates.
-
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.
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.")
bool IsUnitSelected(unit unit)
Returns true if the unit is selected.
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