no errors, !autoloot list command doesn't work
Creaturescript:
Talkaction:
Creaturescript:
Lua:
local function scanContainer(cid, position)
local player = Player(cid)
if not player then
return
end
local corpse = Tile(position):getTopDownItem()
if not corpse then
return
end
if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
for i = corpse:getSize() - 1, 0, -1 do
local containerItem = corpse:getItem(i)
if containerItem then
if player:getStorageValue(AUTOLOOT_STORAGE_GOLD) == 1 and containerItem:getWorth() > 0 then
local itemMoney = containerItem:getWorth()
player:sendTextMessage(MESSAGE_STATUS_SMALL, "[Auto Loot System] Collected: ".. itemMoney .." gold coins.")
player:setBankBalance(player:getBankBalance() + itemMoney)
containerItem:remove()
else
for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
if player:getStorageValue(i) == containerItem:getId() then
containerItem:moveTo(player)
end
end
end
end
end
end
end
function onKill(player, target)
if not target:isMonster() then
return true
end
addEvent(scanContainer, 100, player:getId(), target:getPosition())
return true
end
Talkaction:
Code:
local talk = TalkAction("!autoloot")
function talk.onSay(player, words, param)
local split = param:split(",")
local action = split[1]
if action == "add" then
local item = split[2]:gsub("%s+", "", 1)
local itemType = ItemType(item)
if not itemType or itemType:getId() == 0 then
itemType = ItemType(tonumber(item))
if not itemType or itemType:getId() == 0 then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with that id or name.")
return false
end
end
local itemName = tonumber(split[2]) and itemType:getName() or item
local size = 0
for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
local storage = player:getStorageValue(i)
if size == AUTO_LOOT_MAX_ITEMS then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your list is full, remove some to add a new one.")
break
end
if storage == itemType:getId() then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." it's already on your list.")
break
end
if storage <= 0 then
player:setStorageValue(i, itemType:getId())
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." has been added to your list.")
break
end
size = size + 1
end
elseif action == "remove" then
local item = split[2]:gsub("%s+", "", 1)
local itemType = ItemType(item)
if itemType:getId() == 0 then
itemType = ItemType(tonumber(item))
if itemType:getId() == 0 then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with that id or name.")
return false
end
end
local itemName = tonumber(split[2]) and itemType:getName() or item
for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
if player:getStorageValue(i) == itemType:getId() then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." has been removed from your list.")
player:setStorageValue(i, 0)
return false
end
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, itemName .." not found in your list.")
elseif action == "list" then
local text = "-- Auto Loot List --\n"
local count = 1
for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
local storage = player:getStorageValue(i)
if storage > 0 then
text = string.format("%s%d. %s\n", text, count, ItemType(storage):getName())
count = count + 1
end
end
if text == "" then
text = "Empty"
end
player:showTextDialog(1950, text, false)
elseif action == "clear" then
for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
player:setStorageValue(i, 0)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The autoloot list has been cleared.")
elseif action == "gold" then
if player:getStorageValue(AUTOLOOT_STORAGE_GOLD) == 1 then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Gold autoloot has been disabled.")
player:setStorageValue(AUTOLOOT_STORAGE_GOLD, -1)
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Gold autoloot has been enabled.")
player:setStorageValue(AUTOLOOT_STORAGE_GOLD, 1)
end
else
player:popupFYI("See below the available Auto Loot commands:\n\n!autoloot gold\n!autoloot list\n!autoloot add, itemname\n!autoloot remove, itemname\n!autoloot clear")
end
return false
end
talk:separator(" ")
talk:register()