• 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!

Extraloot tfs1.5 problem

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
188
Reaction score
9
GitHub
Jarek123
Hello guys I have problem when Player try login I have error in console and can not login

error
Lua:
Lua Script Error: [Scripts Interface]
/home/ots/data/scripts/loot.lua:callback
/home/ots/data/scripts/loot.lua:59: attempt to concatenate field 'extraloot' (a nil value)
stack traceback:
        [C]: in function '__concat'
        /home/ots/data/scripts/loot.lua:59: in function </home/ots/data/scripts/loot.lua:57>
Emanienko has logged out.
Rrrrrrr has logged in.

Lua Script Error: [Scripts Interface]
/home/ots/data/scripts/loot.lua:callback
/home/ots/data/scripts/loot.lua:59: attempt to concatenate field 'extraloot' (a nil value)
stack traceback:
        [C]: in function '__concat'
        /home/ots/data/scripts/loot.lua:59: in function </home/ots/data/scripts/loot.lua:57>
Rrrrrrr has logged out.

SCRIPT
Code:
boosted = {}
boosted.creatures = {}
-- possible monsters
boosted.possible = {
  {
    --{"Demon", "Hellhound", "Grim Reaper", "Juggernaut", "Amazon", "Valkyrie", "Carrion Worm", "Drillworm", "Rift Worm", "Rotworm", "Kongra", "Merlkin", "Sibang", "Yeti", }, -- exp list
    {"Lavanos", "Rhyder", "Dog Alfa", "Living Plant",}, -- exp list
      0.2 -- exp rate
  },
  {
    --{"Dragon Lord", "Medusa", "Hydra", "Serpent Spawn"}, -- loot list
    {"Lavanos", "Rhyder", "Living Plant",}, -- loot list
    0.2 -- loot rate
  },
  {
    -- {"Warlock", "Infernalist", "Demon Outcast", "Nightmare"}, -- extraloot list
    {"Lavanos", "Rhyder", "Living Plant",}, -- extraloot list
    {{6527, 1, 2}, {10558, 1, 2}, {2346, 1, 2}, {5957, 1, 2}} -- items list
  }
}

function getBoostedCreature()
  local t = {
    monster = {exp = boosted.creatures[1], loot = boosted.creatures[2], extraloot = boosted.creatures[3]},
    rate = {exp = boosted.possible[1][2], loot = boosted.possible[2][2], extraloot = boosted.possible[3][2]}
    }
  return t
end

local boostedInfo = ""
local globalevent = GlobalEvent("boostedcreatures")

function globalevent.onStartup()
-- select monsters
  local monster1 = boosted.possible[1][1][math.random(#boosted.possible[1][1])]
  local monster2 = boosted.possible[2][1][math.random(#boosted.possible[2][1])]
  local monster3 = boosted.possible[3][1][math.random(#boosted.possible[3][1])]

  boosted.creatures[1] = monster1
  boosted.creatures[2] = monster2
  boosted.creatures[3] = monster3
  -- string for talkaction
  boostedInfo = boostedInfo .. ('Today daily creatures are: %s has extra exp %.1f\n%s has extra loot rate %.1f\n%s has extraloot, list of possible items:\n\n'):format(monster1, getBoostedCreature().rate.exp, monster2, getBoostedCreature().rate.loot, monster3)
  for index, value in ipairs(boosted.possible[3][2]) do
    boostedInfo = boostedInfo .. "[" .. ItemType(value[1]):getName() .. "]: count; " .. value[2] .. ", chance; " .. (not value and "100%" or value[3] .. "%") .. ((#boosted.possible[3][2] > 1 and index < #boosted.possible[3][2]) and "\n" or "")
  end
  -- in case you forget to register the event in monsterfile.xml
  MonsterType(monster1):registerEvent("BoostedDeathExp")
  MonsterType(monster2):registerEvent("BoostedDeathLootRate")
  MonsterType(monster3):registerEvent("BoostedDeathExtraLoot")
    ------------------------------------------------------------
  return true
end
globalevent:register() --registering boostedcreatures

local creatureevent = CreatureEvent("BoostedLogin")
function creatureevent.onLogin(player)
  local boosted = getBoostedCreature()
  local message = "Today daily creatures are: " .. boosted.monster.exp .. " has extra exp rate " .. boosted.rate.exp .. "\n" .. boosted.monster.loot .. " has extra loot rate " .. boosted.rate.loot .. "\n" .. boosted.monster.extraloot .. " has extra loot: type !extraloot for more information \n\nEnjoy!"
  player:sendTextMessage(MESSAGE_INFO_DESCR, message)
  return true
end
creatureevent:register() -- registering BoostedLogin

local creatureevent = CreatureEvent("BoostedDeathExp")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
  if not creature:isMonster() or not killer:isPlayer() or not corpse then
    return true
  end
  local BOOSTED = getBoostedCreature()
  -- exp-------------------------------------------
  if creature:getName():lower() == BOOSTED.monster.exp:lower() then
    local exp = math.floor(MonsterType(creature:getName()):experience() * (Game.getExperienceStage(killer:getLevel()) + BOOSTED.rate.exp))
    killer:addExperience(exp, true)
  end
  return true
end
creatureevent:register()--registering BoostedDeathExp

    -- loot-------------------------------------------
local creatureevent = CreatureEvent("BoostedDeathLootRate")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
  if not creature:isMonster() or not killer:isPlayer() or not corpse then
    return true
  end
  local BOOSTED = getBoostedCreature()
  if creature:getName():lower() == BOOSTED.monster.loot:lower() then
    local monsterloot = MonsterType(creature:getName()):getLoot()
    local bp = corpse:addItem(1987, 1)
    local str = ""
    local rate = BOOSTED.rate.loot * configManager.getNumber(configKeys.RATE_LOOT)
    for i, loot in pairs(monsterloot) do
      if math.random(100000) <= rate * loot.chance then
        local count = loot.maxCount > 1 and math.random(loot.maxCount) or 1
        bp:addItem(loot.itemId, count)
        str = str .. count .. " " .. ItemType(loot.itemId):getName() .. ", "
      end
    end
    if str ~= "" then
      if str:sub(-2, -2) == "," then
        str = str:sub(1, str:len() - 2)
      end
      killer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Loot bonus [" .. creature:getName() .. "]: " .. str .. '.')
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALARROW, killer)
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALSQUARE, killer)
    end
  end
  return true
end
creatureevent:register()--registering BoostedDeathLootRate

-- extraloot------------------------------------------------------
local creatureevent = CreatureEvent("BoostedDeathExtraLoot")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
  if not creature:isMonster() or not killer:isPlayer() or not corpse then
    return true
  end
  local BOOSTED = getBoostedCreature()
  if creature:getName():lower() == BOOSTED.monster.extraloot:lower() then
    local bp = corpse:addItem(1987, 1)
    local str = ""
    for index, value in ipairs(boosted.possible[3][2]) do
      if not value[3] or math.random(100) <= value[3] then
        if ItemType(value[1]):isStackable() then
          bp:addItem(value[1], value[2])
        else
          for i = 1, value[2] do
            bp:addItem(value[1], 1)
          end
        end
          str = str .. value[2] .. " " .. ItemType(value[1]):getName() .. ", "
      end
    end
    if str ~= "" then
      if str:sub(-2, -2) == "," then
        str = str:sub(1, str:len() - 2)
      end
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALARROW, killer)
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALSQUARE, killer)
      killer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Extra loot [" .. creature:getName() .. "]: " .. str .. '.')
    end
  end
  return true
end
creatureevent:register()--registering BoostedDeathExtraLoot

local talkaction = TalkAction('!extraloot')

function talkaction.onSay(player, words, param)
    player:popupFYI(boostedInfo)
    return false
end

talkaction:separator(" ")
talkaction:register() --registering !extraloot
 
Lua:
boostedInfo = boostedInfo .. ('Today daily creatures are: %s has extra exp %.1f\n%s has extra loot rate %.1f\n%s has extraloot, list of possible items:\n\n'):format(monster1, getBoostedCreature().rate.exp, monster2, getBoostedCreature().rate.loot, monster3)

The error occurs because the extraloot field of getBoostedCreature().monster is nil.

You can try to add checks to ensure that if the values are nil they are replaced with default values, for example "0" for rates and "None" for monster3:
Lua:
local creatureInfo = getBoostedCreature()
boostedInfo = boostedInfo .. ('Today daily creatures are: %s has extra exp %.1f\n%s has extra loot rate %.1f\n%s has extraloot, list of possible items:\n\n'):format(monster1, creatureInfo.rate.exp or 0, monster2, creatureInfo.rate.loot or 0, monster3 or "None")
 
Try This ;)

Lua:
boosted = {}
boosted.creatures = {}
-- possible monsters
boosted.possible = {
 
{

    --{"Demon", "Hellhound", "Grim Reaper", "Juggernaut", "Amazon", "Valkyrie", "Carrion Worm", "Drillworm", "Rift Worm", "Rotworm", "Kongra", "Merlkin", "Sibang", "Yeti", }, -- exp list

    {"Lavanos", "Rhyder", "Dog Alfa", "Living Plant",}, -- exp list

      0.2 -- exp rate

  },

  {

    --{"Dragon Lord", "Medusa", "Hydra", "Serpent Spawn"}, -- loot list

    {"Lavanos", "Rhyder", "Living Plant",}, -- loot list

    0.2 -- loot rate

  },

  {

    -- {"Warlock", "Infernalist", "Demon Outcast", "Nightmare"}, -- extraloot list

    {"Lavanos", "Rhyder", "Living Plant",}, -- extraloot list

    {{6527, 1, 2}, {10558, 1, 2}, {2346, 1, 2}, {5957, 1, 2}} -- items list

  }

}


function getBoostedCreature()
  local t = {
    monster = {exp = boosted.creatures[1], loot = boosted.creatures[2], extraloot = boosted.creatures[3]},
    rate = {exp = boosted.possible[1][2], loot = boosted.possible[2][2], extraloot = boosted.possible[3][2]}
  }
  return t
end

local boostedInfo = ""
local globalevent = GlobalEvent("boostedcreatures")

function globalevent.onStartup()
  local monster1 = boosted.possible[1][1][math.random(#boosted.possible[1][1])]
  local monster2 = boosted.possible[2][1][math.random(#boosted.possible[2][1])]
  local monster3 = boosted.possible[3][1][math.random(#boosted.possible[3][1])]

  boosted.creatures[1] = monster1
  boosted.creatures[2] = monster2
  boosted.creatures[3] = monster3

  -- Check if 'extraloot' is not nil before concatenating
  if getBoostedCreature().monster.extraloot then
    boostedInfo = boostedInfo .. ('Today daily creatures are: %s has extra exp %.1f\n%s has extra loot rate %.1f\n%s has extraloot, list of possible items:\n\n'):format(monster1, getBoostedCreature().rate.exp, monster2, getBoostedCreature().rate.loot, monster3)
    for index, value in ipairs(boosted.possible[3][2]) do
      boostedInfo = boostedInfo .. "[" .. ItemType(value[1]):getName() .. "]: count; " .. value[2] .. ", chance; " .. (not value and "100%" or value[3] .. "%") .. ((#boosted.possible[3][2] > 1 and index < #boosted.possible[3][2]) and "\n" or "")
    end
  else
    print("Warning: 'extraloot' is nil")
  end

  MonsterType(monster1):registerEvent("BoostedDeathExp")
  MonsterType(monster2):registerEvent("BoostedDeathLootRate")
  MonsterType(monster3):registerEvent("BoostedDeathExtraLoot")
  return true
end
globalevent:register()

local creatureevent = CreatureEvent("BoostedLogin")
function creatureevent.onLogin(player)
  local boosted = getBoostedCreature()
  local message = "Today daily creatures are: " .. boosted.monster.exp .. " has extra exp rate " .. boosted.rate.exp .. "\n" .. boosted.monster.loot .. " has extra loot rate " .. boosted.rate.loot .. "\n" .. (boosted.monster.extraloot or "No extra loot today") .. " has extra loot: type !extraloot for more information \n\nEnjoy!"
  player:sendTextMessage(MESSAGE_INFO_DESCR, message)
  return true
end
creatureevent:register()

local creatureevent = CreatureEvent("BoostedDeathExp")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
  if not creature:isMonster() or not killer:isPlayer() or not corpse then
    return true
  end
  local BOOSTED = getBoostedCreature()
  if creature:getName():lower() == BOOSTED.monster.exp:lower() then
    local exp = math.floor(MonsterType(creature:getName()):experience() * (Game.getExperienceStage(killer:getLevel()) + BOOSTED.rate.exp))
    killer:addExperience(exp, true)
  end
  return true
end
creatureevent:register()

local creatureevent = CreatureEvent("BoostedDeathLootRate")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
  if not creature:isMonster() or not killer:isPlayer() or not corpse then
    return true
  end
  local BOOSTED = getBoostedCreature()
  if creature:getName():lower() == BOOSTED.monster.loot:lower() then
    local monsterloot = MonsterType(creature:getName()):getLoot()
    local bp = corpse:addItem(1987, 1)
    local str = ""
    local rate = BOOSTED.rate.loot * configManager.getNumber(configKeys.RATE_LOOT)
    for i, loot in pairs(monsterloot) do
      if math.random(100000) <= rate * loot.chance then
        local count = loot.maxCount > 1 and math.random(loot.maxCount) or 1
        bp:addItem(loot.itemId, count)
        str = str .. count .. " " .. ItemType(loot.itemId):getName() .. ", "
      end
    end
    if str ~= "" then
      if str:sub(-2, -2) == "," then
        str = str:sub(1, str:len() - 2)
      end
      killer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Loot bonus [" .. creature:getName() .. "]: " .. str .. '.')
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALARROW, killer)
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALSQUARE, killer)
    end
  end
  return true
end
creatureevent:register()

local creatureevent = CreatureEvent("BoostedDeathExtraLoot")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
  if not creature:isMonster() or not killer:isPlayer() or not corpse then
    return true
  end
  local BOOSTED = getBoostedCreature()
  if creature:getName():lower() == BOOSTED.monster.extraloot:lower() then
    local bp = corpse:addItem(1987, 1)
    local str = ""
    for index, value in ipairs(boosted.possible[3][2]) do
      if not value[3] or math.random(100) <= value[3] then
        if ItemType(value[1]):isStackable() then
          bp:addItem(value[1], value[2])
        else
          for i = 1, value[2] do
            bp:addItem(value[1], 1)
          end
        end
        str = str .. value[2] .. " " .. ItemType(value[1]):getName() .. ", "
      end
    end
    if str ~= "" then
      if str:sub(-2, -2) == "," then
        str = str:sub(1, str:len() - 2)
      end
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALARROW, killer)
      creature:getPosition():sendMagicEffect(CONST_ME_TUTORIALSQUARE, killer)
      killer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Extra loot [" .. creature:getName() .. "]: " .. str .. '.')
    end
  end
  return true
end
creatureevent:register()

local talkaction = TalkAction('!extraloot')

function talkaction.onSay(player, words, param)
    player:popupFYI(boostedInfo)
    return false
end

talkaction:separator(" ")
talkaction:register()
 
Back
Top