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:
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()