Bom Dia gente, estou configurando os filtros de ordenação na BattleWindow do OTClient, porém por algum motivo está gerando muito erros consecutivos quando ele tenta adicionar o pokemon na BattleWindow, abaixo da pra ver na imagem, o problema é que isso se acumula e trava o cliente!
Segue aqui o código da função addCreature():
function addCreature(creature)
local creatureId = creature:getId()
local battleButton = battleButtonsByCreaturesList[creatureId]
-- Register when creature is added to battlelist for the first time
if not creatureAgeList[creatureId] then
creatureAgeList[creatureId] = os.time()
end
if creature:getHealthPercent() <= 1 then
battleButton:setVisible(false)
return true
end
if not battleButton then
battleButton = g_ui.createWidget('BattleButton')
battleButton:setup(creature)
battleButton.onHoverChange = onBattleButtonHoverChange
battleButton.onMouseRelease = onBattleButtonMouseRelease
battleButtonsByCreaturesList[creatureId] = battleButton
if pokemonId and creatureId == pokemonId then
battlePanel:insertChild(1, battleButton)
battleButton:getChildById('myPokemon'):setImageColor('white')
else
battlePanel:addChild(battleButton)
end
if creature == g_game.getAttackingCreature() then
onAttack(creature)
end
if creature == g_game.getFollowingCreature() then
onFollow(creature)
end
local inserted = false
local nameLower = creature:getName():lower()
local healthPercent = creature:getHealthPercent()
local playerPosition = g_game.getLocalPlayer():getPosition()
local distance = getDistanceBetween(playerPosition, creature:getPosition())
local age = creatureAgeList[creatureId]
local childCount = battlePanel:getChildCount()
for i = 1, childCount do
local child = battlePanel:getChildByIndex(i)
local childName = child:getCreature():getName():lower()
local equal = false
if getSortType() == 'age' then
local childAge = creatureAgeList[child:getCreature():getId()]
if (age < childAge and isSortAsc()) or (age > childAge and isSortDesc()) then
battlePanel:insertChild(i, battleButton)
inserted = true
break
elseif age == childAge then
equal = true
end
elseif getSortType() == 'distance' then
local childDistance = getDistanceBetween(child:getCreature():getPosition(), playerPosition)
if (distance < childDistance and isSortAsc()) or (distance > childDistance and isSortDesc()) then
battlePanel:insertChild(i, battleButton)
inserted = true
break
elseif childDistance == distance then
equal = true
end
elseif getSortType() == 'health' then
local childHealth = child:getCreature():getHealthPercent()
if (healthPercent < childHealth and isSortAsc()) or (healthPercent > childHealth and isSortDesc()) then
battlePanel:insertChild(i, battleButton)
inserted = true
break
elseif healthPercent == childHealth then
equal = true
end
end
-- If any other sort type is selected and values are equal, sort it by name also
if getSortType() == 'name' or equal then
local length = math.min(childName:len(), nameLower:len())
for j=1,length do
if (nameLower:byte(j) < childName:byte(j) and isSortAsc()) or (nameLower:byte(j) > childName:byte(j) and isSortDesc()) then
battlePanel:insertChild(i, battleButton)
inserted = true
break
elseif (nameLower:byte(j) > childName:byte(j) and isSortAsc()) or (nameLower:byte(j) < childName:byte(j) and isSortDesc()) then
break
elseif j == nameLower:len() and isSortAsc() then
battlePanel:insertChild(i, battleButton)
inserted = true
elseif j == childName:len() and isSortDesc() then
battlePanel:insertChild(i, battleButton)
inserted = true
end
end
end
if inserted then
break
end
end
Ele aponta erro na linha 444, está que está destacada:
battlePanel:insertChild(i, battleButton)
É justamente o momento que ele tenta inserir um filho na BattleWindow, provavelmente a lógica que invoca essa inserção está errada e entrando em loop, porém não consegui identificar.. Será que alguém pode me ajudar?
Imagem de erros no Terminal:
Desde já, agradeço!