- Joined
- Jul 21, 2020
- Messages
- 67
I made the following function that basically tells my Hero AI to check if they have a teleport item, and if the cooldown is 0, makes them teleport to the nearest allied base. Issue is for some reason when this chunk of code is added into the mix, (AI updates about every second per AI, but obviously doesn't check this everytime), the whole map crashes about a minute into the match. Unsure why that is happening, as I don't see any leaks or things like that and but the time it gets to a minute in, max this would've run about 30 times worse case, so I don't see how that would leak so bad that the game would crash. Let me know if you guys have any ideas or know why this is crashing for me. Thanks!
FYI, all of the other functions referenced in this code block show up many other times in my code and haven't causes issues there.
FYI, all of the other functions referenced in this code block show up many other times in my code and haven't causes issues there.
Lua:
function self:teleportCheck(i, destX, destY)
local destDistance = 100000000.00
local destDistanceNew = 0.00
local unitX, unitY, u
local teleportUnit
local g = CreateGroup()
local heroUnit = self[i].unit
local heroX = GetUnitX(self[i].unit)
local heroY = GetUnitY(self[i].unit)
local distanceOrig = distance(heroX, heroY, destX, destY)
local teleportCooldown = BlzGetUnitAbilityCooldownRemaining(heroUnit, hero.item.teleportation.abilityId)
if teleportCooldown == 0 and UnitHasItemOfTypeBJ(heroUnit, hero.item.teleportation.id) then
GroupAddGroup(udg_UNIT_Bases_Teleport[self[i].teamNumber], g)
while true do
u = FirstOfGroup(g)
if u == nil then
break
end
unitX = GetUnitX(u)
unitY = GetUnitY(u)
destDistanceNew = distance(destX, destY, unitX, unitY)
if destDistanceNew < destDistance then
destDistance = destDistanceNew
teleportUnit = u
end
GroupRemoveUnit(g, u)
end
DestroyGroup(g)
if distanceOrig + 2000 > destDistanceNew then
print("Teleporting")
DisableTrigger(trig_CastSpell)
UnitUseItemTarget(heroUnit, GetItemOfTypeFromUnitBJ(heroUnit, hero.item.teleportation.id),
teleportUnit)
EnableTrigger(trig_CastSpell)
self:castSpell(i, 6)
return true
else
return false
end
else
return false
end
end