- Joined
- Jun 26, 2020
- Messages
- 1,972
Hello, I don't know why but I have this trigger that uses a threat system that when that system issues an order then make the unit cast their spells, here is part of the code:
Even if I added a wait and the issue order function returns true, the unit doesn't do anything, what's wrong?
Lua:
---@param u unit
---@param spell integer
local function insertSpell(u, spell)
if IsPlayerInGame(GetOwningPlayer(u)) then
return
end
local set = UnitSpellAIs[u]
if not set then
set = Set.create()
UnitSpellAIs[u] = set
ZTS_AddThreatUnit(u, false)
end
set:addSingle(SpellAIs[spell])
end
do
local t = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_ORDER)
TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
TriggerAddAction(t, function ()
if not ZTS_IsEvent() then
return
end
local creep = GetOrderedUnit()
PolledWait(1.)
local set = UnitSpellAIs[creep]
if set then
DisableTrigger(t)
print(set)
for func in set:elements() do
print(func)
local res = func(creep)
print(res)
if res then
break
end
end
--set:random()(creep)
EnableTrigger(t)
end
end)
end
Lua:
SpellAIs[spell] = function (u)
if isPaused[u] then
return false
end
if not UnitCanCastAbility(u, spell) then
return false
end
local abil = BlzGetUnitAbility(u, spell)
local level = GetUnitAbilityLevel(u, spell)
local range = convertedRange(BlzGetAbilityRealLevelField(abil, ABILITY_RLF_CAST_RANGE, level - 1))
local area = BlzGetAbilityRealLevelField(abil, ABILITY_RLF_AREA_OF_EFFECT, level - 1)
if hasUnitTarget then
local target
if enemyTarget then
local maxThreat = -1
ForUnitsInRange(GetUnitX(u), GetUnitY(u), range, function (u2)
if not BlzIsUnitInvulnerable(u2) and UnitAlive(u2) then
local threat = ZTS_GetThreatUnitAmount(u, u2)
if threat > maxThreat then
target = u2
maxThreat = threat
print("c", u2)
end
end
end)
end
if allyTarget then
target = GetRandomUnitOnRange(GetUnitX(u), GetUnitY(u), range, function (u2)
return IsUnitAlly(u, GetOwningPlayer(u2)) and UnitAlive(u2)
end)
end
if target then
print("d", target)
return IssueTargetOrderById(u, order, target)
end
elseif hasPointTarget then
area = area > 0 and area or 200.
local x, y = GetConcentration(GetUnitX(u), GetUnitY(u), range, GetOwningPlayer(u), area, enemyTarget, allyTarget)
if x then
return IssuePointOrderById(u, order, x, y)
else
local random = GetRandomUnitOnRange(GetUnitX(u), GetUnitY(u), range, function (u2)
return ((enemyTarget and UnitAlive(u2) and IsUnitEnemy(u, GetOwningPlayer(u2)) and not BlzIsUnitInvulnerable(u2)) or (allyTarget and IsUnitAlly(u, GetOwningPlayer(u2))))
end)
if random then
return IssuePointOrderById(u, order, GetUnitX(random), GetUnitY(random))
end
end
elseif hasNoTarget then
local count = 0
ForUnitsInRange(GetUnitX(u), GetUnitY(u), area, function (u2)
if enemyTarget and (not IsUnitEnemy(u, GetOwningPlayer(u2)) or BlzIsUnitInvulnerable(u2)) and UnitAlive(u2) then
return
end
if allyTarget and not IsUnitAlly(u, GetOwningPlayer(u2)) and UnitAlive(u2) then
return
end
count = count + 1
end)
if count >= 1 then
return IssueImmediateOrderById(u, order)
end
end
return false
end