• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[OTCv8] Error battle.lua - 'sortCreatures' and 'checkCreatures'

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,404
Solutions
17
Reaction score
154
Location
Brazil
Hello guys, My OTCv8 (last version from OTCv8 repo) is getting this error on log. Someone help me to fix, please? Error:


Lua:
ERROR: lua function callback failed: /modules/game_battle/battle.lua:357: attempt to compare nil with number
stack traceback:
    [C]: in function '__lt'
    /modules/game_battle/battle.lua:357: in function </modules/game_battle/battle.lua:355>
    [C]: in function 'sort'
    /modules/game_battle/battle.lua:355: in function 'sortCreatures'
    /modules/game_battle/battle.lua:263: in function 'checkCreatures'
    /modules/game_battle/battle.lua:224: in function </modules/game_battle/battle.lua:221>

Function pointed:

Lua:
 function sortCreatures(creatures)
  local player = g_game.getLocalPlayer()
  
  if getSortType() == 'distance' then
    local playerPos = player:getPosition()
    table.sort(creatures, function(a, b) 
      if getDistanceBetween(playerPos, a:getPosition()) == getDistanceBetween(playerPos, b:getPosition()) then
        return ages[a:getId()] > ages[b:getId()]
      end
      return getDistanceBetween(playerPos, a:getPosition()) > getDistanceBetween(playerPos, b:getPosition()) 
    end)
  elseif getSortType() == 'health' then
    table.sort(creatures, function(a, b) 
      if a:getHealthPercent() == b:getHealthPercent() then
        return ages[a:getId()] > ages[b:getId()]
      end
      return a:getHealthPercent() > b:getHealthPercent() 
    end)
  elseif getSortType() == 'age' then
    table.sort(creatures, function(a, b) return ages[a:getId()] > ages[b:getId()] end)
  elseif getSortType() == 'screenage' then
    table.sort(creatures, function(a, b) return a.screenAge > b.screenAge end)
  else -- name
    table.sort(creatures, function(a, b)
      if a:getName():lower() == b:getName():lower() then
        return ages[a:getId()] > ages[b:getId()]
      end
      return a:getName():lower() > b:getName():lower() 
    end)
  end
end
 
Back
Top