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

TFS 1.X+ Add vocation to extra loot

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,521
Solutions
27
Reaction score
870
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again! I wanted to ask something related to this script

Lua:
local monsters = {
    -- all monsters
    all = {
        loot = {
            { itemId=2152, count=100, chance=20 },
            { itemId=2160, count=10, chance=20 },
            { itemId=2160, minCount=10, maxCount=20, chance=20 }
        }
    },
    ["rotworm"] = {
        loot = {
            { itemId=2398, count=10, chance=20 }
        }
    },
    ["dragon"] = {
        loot = {
            { itemId=2152, minCount=10, maxCount=20, chance=20 },
            { itemId=2160, minCount=10, maxCount=20, chance=20 }
        }
    }
}

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
    if not corpse or not corpse:getType():isContainer() then
        return
    end
    local m = monsters[monster:getName():lower()] or monsters.all
    local loot = m.loot
    if #loot == 0 then
        return
    end
    local showText = false
    for _, lootItem in pairs(loot) do
        if math.random(100) <= lootItem.chance then
            local it = ItemType(lootItem.itemId)
            if lootItem.count then
                if corpse:addItem(lootItem.itemId, it:isStackable() and lootItem.count or 1) then
                    showText = true
                end
            elseif corpse:addItem(lootItem.itemId, it:isStackable() and math.random(lootItem.minCount or 1, lootItem.maxCount or 100) or 1) then
                showText = true
            end
        end
    end

    if showText then
        monster:say("You found something.", TALKTYPE_MONSTER_SAY)
    end
end

ec:register(777)

How can I add this extra loot specifically to one vocation?. I'm planing to have one file for each vocation with this extra loot thing, if it doesn't has any issue. The goal is to give potions as extra loot for each vocation, to avoid urgent refills and boost resources without raising the loot rate directly or the profit earning of all the creature's loot.

Thanks a lot in advance!
Regards
 
Solution
Thanks a lot for the fast reply @pips ! As I see looks really really good exactly what i'm looking for.
There's something I still miss, I said that I needed to give potions as extra loot for each vocation, but won't be helpfull if for example I give an ultimate health potion in a rotworm, so... How can I include tables for creatures?

I also use this system in c++ Monster Levels https://otland.net/threads/tfs-1-3-monster-levels.260470/ · ralke23/Greed-TFS-1.5-Downgrades@7175b79 (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commit/7175b79f5cfeba113a826acd23aff56fc79fe467) and define the skulls for each level with Show creature skulls https://otland.net/threads/tfs-1-x-monster-skull… ·...
Hi again! I wanted to ask something related to this script

Lua:
local monsters = {
    -- all monsters
    all = {
        loot = {
            { itemId=2152, count=100, chance=20 },
            { itemId=2160, count=10, chance=20 },
            { itemId=2160, minCount=10, maxCount=20, chance=20 }
        }
    },
    ["rotworm"] = {
        loot = {
            { itemId=2398, count=10, chance=20 }
        }
    },
    ["dragon"] = {
        loot = {
            { itemId=2152, minCount=10, maxCount=20, chance=20 },
            { itemId=2160, minCount=10, maxCount=20, chance=20 }
        }
    }
}

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
    if not corpse or not corpse:getType():isContainer() then
        return
    end
    local m = monsters[monster:getName():lower()] or monsters.all
    local loot = m.loot
    if #loot == 0 then
        return
    end
    local showText = false
    for _, lootItem in pairs(loot) do
        if math.random(100) <= lootItem.chance then
            local it = ItemType(lootItem.itemId)
            if lootItem.count then
                if corpse:addItem(lootItem.itemId, it:isStackable() and lootItem.count or 1) then
                    showText = true
                end
            elseif corpse:addItem(lootItem.itemId, it:isStackable() and math.random(lootItem.minCount or 1, lootItem.maxCount or 100) or 1) then
                showText = true
            end
        end
    end

    if showText then
        monster:say("You found something.", TALKTYPE_MONSTER_SAY)
    end
end

ec:register(777)

How can I add this extra loot specifically to one vocation?. I'm planing to have one file for each vocation with this extra loot thing, if it doesn't has any issue. The goal is to give potions as extra loot for each vocation, to avoid urgent refills and boost resources without raising the loot rate directly or the profit earning of all the creature's loot.

Thanks a lot in advance!
Regards
make it separated.
not tested (made it quite simple...):

Lua:
local chance = 50
local maxChance = 100
-- real chance = chance / maxChance => 50 / 100 = 50%
local maxCount = 3 -- from 1 to maxCount
local vocations = {
  -- [vocation id] = {possible items},
  [1] = {1234,12345},
  [2] = {1111,2222,3333},
}

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
  if not corpse or not corpse:getType():isContainer() then
    return
  end
  -- chance
  local random = math.random(maxChance)
  if random >= chance then return true end
  -- get corpse owner
  local player = Player(corpse:getCorpseOwner())
  if not player then return true end
  -- get owner vocation
  local pVoc = player:getVocation():getId()
  -- get possible items
  local items = vocations[pVoc]
  if not items then return true end
  -- get a random item in the list
  local item = items[math.random(#items)]
  -- get random amount
  local count = math.random(maxCount)
  -- add item in corpse
  corpse:addItem(item, count)
  -- the end
  return true
end

ec:register(666)
 
make it separated.
not tested (made it quite simple...):

Lua:
local chance = 50
local maxChance = 100
-- real chance = chance / maxChance => 50 / 100 = 50%
local maxCount = 3 -- from 1 to maxCount
local vocations = {
  -- [vocation id] = {possible items},
  [1] = {1234,12345},
  [2] = {1111,2222,3333},
}

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
  if not corpse or not corpse:getType():isContainer() then
    return
  end
  -- chance
  local random = math.random(maxChance)
  if random >= chance then return true end
  -- get corpse owner
  local player = Player(corpse:getCorpseOwner())
  if not player then return true end
  -- get owner vocation
  local pVoc = player:getVocation():getId()
  -- get possible items
  local items = vocations[pVoc]
  if not items then return true end
  -- get a random item in the list
  local item = items[math.random(#items)]
  -- get random amount
  local count = math.random(maxCount)
  -- add item in corpse
  corpse:addItem(item, count)
  -- the end
  return true
end

ec:register(666)

Thanks a lot for the fast reply @pips ! As I see looks really really good exactly what i'm looking for.
There's something I still miss, I said that I needed to give potions as extra loot for each vocation, but won't be helpfull if for example I give an ultimate health potion in a rotworm, so... How can I include tables for creatures?

I also use this system in c++ Monster Levels https://otland.net/threads/tfs-1-3-monster-levels.260470/ · ralke23/Greed-TFS-1.5-Downgrades@7175b79 (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commit/7175b79f5cfeba113a826acd23aff56fc79fe467) and define the skulls for each level with Show creature skulls https://otland.net/threads/tfs-1-x-monster-skull… · ralke23/Greed-TFS-1.5-Downgrades@fdcdabd (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commit/fdcdabd7f647aeeb48c7bdfb71ed5cd8f6defba2)

It's worth to ask, is there a chance to merge all this extra potions script in c++ and give the potions according to the skull that the monster has? for example, giving mana potions if is "green skulled", giving strong mana potions if is "yellow skulled", etc.


I appreciate the help a lot!
Regards :)
 
Thanks a lot for the fast reply @pips ! As I see looks really really good exactly what i'm looking for.
There's something I still miss, I said that I needed to give potions as extra loot for each vocation, but won't be helpfull if for example I give an ultimate health potion in a rotworm, so... How can I include tables for creatures?

I also use this system in c++ Monster Levels https://otland.net/threads/tfs-1-3-monster-levels.260470/ · ralke23/Greed-TFS-1.5-Downgrades@7175b79 (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commit/7175b79f5cfeba113a826acd23aff56fc79fe467) and define the skulls for each level with Show creature skulls https://otland.net/threads/tfs-1-x-monster-skull… · ralke23/Greed-TFS-1.5-Downgrades@fdcdabd (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commit/fdcdabd7f647aeeb48c7bdfb71ed5cd8f6defba2)

It's worth to ask, is there a chance to merge all this extra potions script in c++ and give the potions according to the skull that the monster has? for example, giving mana potions if is "green skulled", giving strong mana potions if is "yellow skulled", etc.


I appreciate the help a lot!
Regards :)
Lua:
local chance = 50
local maxChance = 100
-- real chance = chance / maxChance => 50 / 100 = 50%
local maxCount = 3 -- from 1 to maxCount
local config = {
  [SKULL_NONE] = { -- monster skull
    [1] = { -- vocations id
      {id = 12345, maxCount = 3}, -- list of possible items
      {id = 12346, maxCount = 7},
    },
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
    [SKULL_YELLOW] = {
    [1] = {{id = 12345, maxCount = 3},},
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
    [SKULL_GREEN] = {
    [1] = {{id = 12345, maxCount = 3},},
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
    [SKULL_WHITE] = {
    [1] = {{id = 12345, maxCount = 3},},
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
    [SKULL_RED] = {
    [1] = {{id = 12345, maxCount = 3},},
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
    [SKULL_BLACK] = {
    [1] = {{id = 12345, maxCount = 3},},
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
    [SKULL_ORANGE] = {
    [1] = {{id = 12345, maxCount = 3},},
    [2] = {{id = 12345, maxCount = 3},},
    [3] = {{id = 12345, maxCount = 3},},
  },
}

local ec = EventCallback

function ec.onDropLoot(monster, corpse)
  if not corpse or not corpse:getType():isContainer() then
    return
  end
  -- get mob skull and voc list
  local skull = monster:getSkull()
  local vocations = config[skull]
  if not vocations then return true end
  -- chance
  local random = math.random(maxChance)
  if random >= chance then return true end
  -- get corpse owner
  local player = Player(corpse:getCorpseOwner())
  if not player then return true end
  -- get owner vocation
  local pVoc = player:getVocation():getId()
  -- get possible items
  local items = vocations[pVoc]
  if not items then return true end
  -- get a random item in the list
  local item = items[math.random(#items)]
  -- get random amount
  local count = math.random((item.maxCount or 1))
  -- add item in corpse
  corpse:addItem(item.id, count)
  -- the end
  return true
end

ec:register(666)
 
Solution
from 1 to maxCount
Hi @pips! Excellent outcome, I already merged it in the server so i'm waiting for what happens inside the game. A little question, what does local maxCount = 3 handle exactly? and a last thing if is possible; there could be a message or creature say when this extra loot appears?, such as the original script from Sarah. Thanks a lot in advance!
 
Hi @pips! Excellent outcome, I already merged it in the server so i'm waiting for what happens inside the game. A little question, what does local maxCount = 3 handle exactly? and a last thing if is possible; there could be a message or creature say when this extra loot appears?, such as the original script from Sarah. Thanks a lot in advance!
for msg:
after
-- add item in corpse
corpse:addItem(item.id, count)

you can add:
monster:say("You found something.", TALKTYPE_MONSTER_SAY)

as it is on the previous script.

maxCount is the maximum amount that the monster can drop of that item (random between 1 and maxCount)
if maxCount is not set, then the max is 1.
Post automatically merged:

ah, i saw now why u asked about the maxCount..
local maxCount = 3 -- from 1 to maxCount
this one, right?
just remove it, it's not in use
 
Last edited:
for msg:
after
-- add item in corpse
corpse:addItem(item.id, count)

you can add:
monster:say("You found something.", TALKTYPE_MONSTER_SAY)

as it is on the previous script.

maxCount is the maximum amount that the monster can drop of that item (random between 1 and maxCount)
if maxCount is not set, then the max is 1.
Post automatically merged:

ah, i saw now why u asked about the maxCount..
local maxCount = 3 -- from 1 to maxCount
this one, right?
just remove it, it's not in use
Worked perfectly!
Thanks @pips

1692016591897.png
 
Back
Top