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
- unit
unit
the unit to count the behavior stack count on. - string
behaviorName
the name of the behavior to get the stack count of.
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
Parameters
- unit
unit
the unit to apply the behavior to. - string
behaviorName
the name of the behavior to apply. - int
count
the number of stacks of the chosen behavior to apply.
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
- unit
caster
the unit that the behavior is considered to be the caster and owner of the applied behavior. - unit
source
the unit that the behavior is considered to have originated from. - unit
target
the unit to apply the behavior to. - string
behaviorName
the name of the behavior to apply. - int
count
the number of stacks of the chosen behavior to apply.
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
- unit
unit
the unit to remove the behavior from. - string
behaviorName
the name of the behavior to remove. - int
count
the number of stacks of the chosen behavior to remove.
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
- unit
unit
the unit with the behavior on it. - string
behaviorName
the name of the behavior to set the duration for. - float
duration
the duration to set the behavior to. - bool
extendDuration
if true, the duration of the behavior is extended by the duration instead of set.
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)