Trigger API Reference\DCEI Functions\Behavior

int GetUnitBehaviorStackCount(unit unit, string behaviorName)

int GetUnitBehaviorStackCount(unit unit, string behaviorName)

Description


Returns the stack count of a behavior on a unit.

Parameters

Example Usage

local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_type = DCEI.Behavior(DCEI.Behavior("Damage Taken Half")

DCEI.ApplyBehavior(test_subject, behavior_type, 5)

local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_type)

DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_type)

void ApplyBehaviorToSelf(unit unit, string behaviorName, int count = 1)

void ApplyBehaviorToSelf(unit unit, string behaviorName, int count = 1)

Description


Applies a behavior to a unit.

Parameters

Example Usage

local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

DCEI.ApplyBehaviorToSelf(test_subject, behavior_name, 2)

local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)

DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

void ApplyBehaviorToUnit(unit caster, unit source, unit target, string behaviorName, int count = 1)

void ApplyBehaviorToUnit(unit caster, unit source, unit target, string behaviorName, int count = 1)

Description


Applies a behavior to a unit with source and caster references

Parameters

Example Usage

local team_id = 1
local player_id = 1
local enemy_id = -1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local caster = DCEI.CreateUnit(enemy_id, enemy_id, unit_type, x-1, y-1)
local source = caster
local target = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Double")

DCEI.ApplyBehaviorToUnit(caster, source, target, behavior_name, 1)

local stacks = DCEI.GetUnitBehaviorStackCount(target, behavior_name)

DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

void RemoveBehavior(unit unit, string behaviorName, int count = 0)

void RemoveBehavior(unit unit, string behaviorName, int count = 0)

Description


Removes a behavior from a unit.

Parameters

Example Usage

-- create our test subject
local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

-- apply behavior to them and get the count
DCEI.ApplyBehavior(test_subject, behavior_name, 3)
local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)
DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

-- remove a stack and get the new count
DCEI.RemoveBehavior(test_subject, behavior_name, 1)
stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)
DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of" .. behavior_name)

void SetBehaviorDuration(unit unit, string behaviorName, float duration, bool extendDuration)

void SetBehaviorDuration(unit unit, string behaviorName, float duration, bool extendDuration)

Description


Sets the duration of a behavior currently on a unit.

Parameters

Example Usage

-- Create our test subject
local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

-- Apply our behavior
DCEI.ApplyBehaviorToSelf(test_subject, DCEI.Behavior("Damage Taken Half"), 1)
-- extend the duration by a random duration between 0 and 1.5 seconds.
DCEI.SetBehaviorDuration(test_subject, DCEI.Behavior("Damage Taken Half"), math.random() * 1.5, true)

void ApplyBehaviorAsync(unit unit, string behaviorName)

void ApplyBehaviorAsync(unit unit, string behaviorName)

Description


Applies a behavior to a unit. Asynchronous.

Parameters

Example Usage

local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

DCEI.ApplyBehaviorAsync(test_subject, behavior_name)

DCEI.Wait(0.0625)

local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)

DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

void RemoveBehaviorAsync(unit unit, string behaviorName)

void RemoveBehaviorAsync(unit unit, string behaviorName)

Description


Removes a behavior from a unit. Asynchronous.

Parameters

Example Usage

-- create our test subject
local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

-- apply behavior to them and get the count
DCEI.ApplyBehavior(test_subject, behavior_name, 3)
local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)
DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

-- remove a stack and get the new count
DCEI.RemoveBehaviorAsync(test_subject, behavior_name, 1)

DCEI.Wait(0.0625) -- Wait for Async API

stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)
DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of" .. behavior_name)

void ApplyBehaviorCountAsync(unit unit, string behaviorName, int count)

void ApplyBehaviorCountAsync(unit unit, string behaviorName, int count)

Description


Applies a behavior to a unit. Async version of API.

Parameters

Example Usage

local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

DCEI.ApplyBehaviorCountAsync(test_subject, behavior_name, 2)

DCEI.Wait(0.0625) -- Wait for Async API

local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)

DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

void RemoveBehaviorCountAsync(unit unit, string behaviorName, int count)

void RemoveBehaviorCountAsync(unit unit, string behaviorName, int count)

Description


Removes a behavior from a unit. Async version.

Parameters

Example Usage

-- create our test subject
local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

-- apply behavior to them and get the count
DCEI.ApplyBehavior(test_subject, behavior_name, 3)
local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)
DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)

-- remove a stack and get the new count
DCEI.RemoveBehaviorCountAsync(test_subject, behavior_name, 1)

DCEI.Wait(0.0625) -- Wait for async API

stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)
DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of" .. behavior_name)

void ApplyBehaviorWithDurationAsync(unit unit, string behaviorName, float duration, bool extendDuration)

void ApplyBehaviorWithDurationAsync(unit unit, string behaviorName, float duration, bool extendDuration)

Description


Applies a behavior to a unit. Asynchronous.

Parameters

Example Usage

local team_id = 1
local player_id = 1
local unit_type = DCEI.Unit("Standard MeleeUnit")
local x, y = 16, 16
local test_subject = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)
local behavior_name = DCEI.Behavior("Damage Taken Half")

DCEI.ApplyBehaviorWithDurationAsync(test_subject, behavior_name, 15, true)

DCEI.Wait(0.0625)

local stacks = DCEI.GetUnitBehaviorStackCount(test_subject, behavior_name)

DCEI.LogMessage(unit_type .. " has " .. stacks .. " stacks of " .. behavior_name)