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

RevScripts droplist show

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,394
Reaction score
162
Hey, so i tryed to make a script with ai's help. but failing to fully make it working.

Now it works for normal items, but not stackaible items.

Can someone check and fix it please ?




Script:

LUA:
local droplist = TalkAction("!droplist")

function droplist.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !droplist <item name>")
        return false
    end

    -- Try to find the item by exact name or partial match
    local itemType = ItemType(param)
    if itemType:getId() == 0 then
        -- Try finding by partial name if exact match fails
        for id = 100, 30000 do
            local it = ItemType(id)
            if it:getId() ~= 0 and it:getName():lower():find(param:lower(), 1, true) then
                itemType = it
                break
            end
        end
        
        if itemType:getId() == 0 then
            player:sendCancelMessage("Item not found: " .. param)
            return false
        end
    end

    -- Gather all monsters that drop this item
    local drops = {}
    for _, monster in pairs(Game.getMonsterTypes()) do
        for _, loot in pairs(monster:getLoot() or {}) do
            local lootItem = ItemType(loot.itemId)
            if lootItem:getId() ~= 0 then
                -- Match item by ID, client ID, or name
                if loot.itemId == itemType:getId() or
                   (loot.clientId and ItemType(loot.clientId):getId() == itemType:getId()) or
                   lootItem:getName():lower() == itemType:getName():lower() then

                    local countInfo = ""
                    -- Handling stackable items
                    if loot.maxCount and loot.maxCount > 1 then
                        -- If it's stackable, show count range
                        countInfo = string.format(" (%d-%d)", loot.minCount or 1, loot.maxCount or loot.minCount or 1)
                    else
                        countInfo = ""
                    end

                    -- Store the drop information
                    table.insert(drops, {
                        monster = monster:getName(),
                        chance = loot.chance / 1000, -- Correct percentage
                        chanceText = string.format("%.2f%%", loot.chance / 1000),
                        countInfo = countInfo
                    })
                end
            end
        end
    end

    if #drops == 0 then
        player:sendCancelMessage("No monsters drop '" .. itemType:getName() .. "'.")
        return false
    end

    -- Sort by drop chance (highest first)
    table.sort(drops, function(a, b) return a.chance > b.chance end)

    -- Build result text with item image
    local result = string.format("Drop List for: %s\n\n", itemType:getName())
    for _, drop in ipairs(drops) do
        result = result .. string.format("%s - %s%s\n",
            drop.monster,
            drop.chanceText,
            drop.countInfo)
    end

    -- Show the result in a text dialog, also showing the item image
    player:showTextDialog(itemType:getId(), result)
    return false
end

droplist:separator(" ")
droplist:register()
 
up :)) anyone please :)
LUA:
local droplist = TalkAction("!droplist")

function droplist.onSay(player, words, param)
    if param == "" then
        player:sendCancelMessage("Usage: !droplist <item name>")
        return false
    end

    -- Try to find the item by exact name or partial match
    local searchName = param:lower()
    local itemType = ItemType(param)

    if itemType:getId() == 0 then
        -- Try finding by partial name if exact match fails
        for id = 100, 30000 do
            local it = ItemType(id)
            if it:getId() ~= 0 then
                local name = it:getName():lower()
                if name == searchName or name:find(searchName, 1, true) or name == searchName .. "s" then
                    itemType = it
                    break
                end
            end
        end
       
        if itemType:getId() == 0 then
            player:sendCancelMessage("Item not found: " .. param)
            return false
        end
    end

    -- Gather all monsters that drop this item
    local drops = {}
    for _, monster in pairs(Game.getMonsterTypes()) do
        for _, loot in pairs(monster:getLoot() or {}) do
            local lootItem = ItemType(loot.itemId)
            if lootItem:getId() ~= 0 then
                -- Match item by ID only
                if loot.itemId == itemType:getId() then
                    local countInfo = ""
                    -- Handling stackable items
                    if loot.maxCount and loot.maxCount > 1 then
                        -- If it's stackable, show count range
                        if itemType:isStackable() then
                            countInfo = string.format(" (%d-%d)", loot.minCount or 1, loot.maxCount or loot.minCount or 1)
                        else
                            countInfo = string.format(" x%d", loot.maxCount)
                        end
                    else
                        countInfo = ""
                    end

                    -- Store the drop information
                    table.insert(drops, {
                        monster = monster:getName(),
                        chance = loot.chance / 1000, -- Correct percentage
                        chanceText = string.format("%.2f%%", loot.chance / 1000),
                        countInfo = countInfo
                    })
                end
            end
        end
    end

    if #drops == 0 then
        player:sendCancelMessage("No monsters drop '" .. itemType:getName() .. "'.")
        return false
    end

    -- Sort by drop chance (highest first)
    table.sort(drops, function(a, b) return a.chance > b.chance end)

    -- Build result text with item image
    local result = string.format("Drop List for: %s\n\n", itemType:getName())
    local maxLines = 200
    for i, drop in ipairs(drops) do
        if i > maxLines then
            result = result .. string.format("\n...and %d more drops not shown.", #drops - maxLines)
            break
        end
        result = result .. string.format("%s - %s%s\n",
            drop.monster,
            drop.chanceText,
            drop.countInfo)
    end

    -- Show the result in a text dialog, also showing the item image
    player:showTextDialog(itemType:getId(), result)
    return false
end

droplist:separator(" ")
droplist:register()

key here is max lines ;)
ModalWindow have limit of around 8KB, you can try other values for maxlines. It will sadly fail silencly when too much data is put into it


1744628490343.webp
 
Last edited:

Similar threads

Back
Top