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

Lua [TFS 1.3] get loot percentage

  • Thread starter Thread starter Evil Puncker
  • Start date Start date
E

Evil Puncker

Guest
I've found a script by @Delusion that broadcasts the loot if found on table, is there a way to change it to broadcast loot based on the drop percentage instead? lets say, if loot has chance = 100, broadcast it instead of using table? Using tfs 1.3

LUA:
local rareItems = {1111, 2222, 3333}
local WORLD_CHAT = 00000 -- channel id here

local function scanRareItems(cid, pos)
    local player = Player(cid)
    local name = player:getName()
    local corpse = Tile(pos):getTopDownItem()
    for i = corpse:getSize()-1, 0, -1 do
        local item = corpse:getItem(i)
        if isInArray(rareItems, item:getId()) then
            local count = item:getCount()
            local string = ("%s has looted %s %s!"):format(name, count > 1 and count or item:getArticle(), count > 1 and item:getPluralName() or item:getName())
            Game.broadcastMessage(string)
            player:sendChannelMessage(nil, string, TALKTYPE_CHANNEL_R1, WORLD_CHAT)
        end
    end
end

function onKill(creature, target)
    if creature:isPlayer() and target:isMonster() then
        addEvent(scanRareItems, 0, creature:getId(), target:getPosition())
    end
    return true
end
 
Solution
LUA:
local maxChance = 100

--[[
    loot table structure:
    {
        itemId = 0000,
        chance = 0000,
        subType = 0000,
        maxCount = 0000,
        actionId = 0000,
        text = ""
    }
]]

local function findLootItem(loot, id)
    for i = 1, #loot do
        if loot[i].itemId == id then
            return loot[i]
        end
    end
end

local function scanRareItems(cid, lootTable, pos)
    local player = Player(cid)
    local corpse = Tile(pos):getTopDownItem()
    for i = corpse:getSize() - 1, 0, -1 do
        local item = corpse:getItem(i)
        if item then
            local lootItem = findLootItem(lootTable, item:getId())
            if lootItem and lootItem.chance <= maxChance then
                local...
LUA:
local maxChance = 100

--[[
    loot table structure:
    {
        itemId = 0000,
        chance = 0000,
        subType = 0000,
        maxCount = 0000,
        actionId = 0000,
        text = ""
    }
]]

local function findLootItem(loot, id)
    for i = 1, #loot do
        if loot[i].itemId == id then
            return loot[i]
        end
    end
end

local function scanRareItems(cid, lootTable, pos)
    local player = Player(cid)
    local corpse = Tile(pos):getTopDownItem()
    for i = corpse:getSize() - 1, 0, -1 do
        local item = corpse:getItem(i)
        if item then
            local lootItem = findLootItem(lootTable, item:getId())
            if lootItem and lootItem.chance <= maxChance then
                local count = item:getCount()
                local str = ("%s has looted %s %s!"):format(name, count > 1 and count or item:getArticle(), count > 1 and item:getPluralName() or item:getName())
                Game.broadcastMessage(str)
                player:sendChannelMessage(nil, str, TALKTYPE_CHANNEL_R1, WORLD_CHAT)
            end
        end
    end
end

function onDeath(creature, target)
    if creature:isPlayer() then
        addEvent(scanRareItems, 10, creature:getId(), target:getType():getLoot(), target:getPosition())
    end
    return true
end
 
Solution
Back
Top