function Player.onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
-- This is used to clean the forge and send contents to the players depot if they leave it there for X amount of time
function abandonedItem(playerId, anvilorworkbench)
local itemtosend = false
if anvilorworkbench == "workbench" then
local workbenchpos = Position(1148, 633, 6)
local workbench = Tile(workbenchpos):getItemById(23660)
if workbench:isContainer() then
itemtosend = workbench:getItem(0)
end
elseif anvilorworkbench == "anvil" then
local anvilpos = Position(1151, 633, 6)
local anvil = Tile(anvilpos):getItemById(8671)
if anvil:isContainer() then
itemtosend = anvil:getItem(0)
end
end
if itemtosend then
local player = false
-- see if player is online
for _, playersearch in ipairs(Game.getPlayers()) do
if playersearch:getId() == playerId then
player = Player(playerId)
end
end
-- player is online
if player then
local depot = player:getDepotChest(0, true)
itemtosend:moveTo(depot)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have left an item unattended in the " .. anvilorworkbench .. " in the forge, it has been sent to your depot.")
player:save()
local resetstorage = 0
if anvilorworkbench == "workbench" then
resetstorage = 30020
elseif anvilorworkbench == "anvil" then
resetstorage = 30021
end
Game.setStorageValue(resetstorage, -1)
else
itemtosend:removeAttribute(ITEM_ATTRIBUTE_OWNER)
end
else
return false
-- Couldn't get item from anvil/forge for some reason
end
end
if toCylinder and toCylinder:isItem() then
if toCylinder:getId() == 23660 then
local disenchantDesc = item:getAttribute(ITEM_ATTRIBUTE_ARTICLE)
if disenchantDesc:find "rare" or disenchantDesc:find "epic" or disenchantDesc:find "legendary" or disenchantDesc:find "dawnbreaker" then -- dawnbreaker is a custom weapon that may not exist on your server
item:setAttribute(ITEM_ATTRIBUTE_OWNER, self:getId())
Game.setStorageValue(30020, addEvent(abandonedItem, 60000, self:getId(), "workbench"))
return true
else
self:sendCancelMessage("You cannot disenchant regular items.")
return false
end
elseif toCylinder:getId() == 8671 then
local disenchantDesc = item:getAttribute(ITEM_ATTRIBUTE_ARTICLE)
if disenchantDesc:find "rare" or disenchantDesc:find "epic" or disenchantDesc:find "legendary" or disenchantDesc:find "dawnbreaker" then
self:sendCancelMessage("This item is already enchanted.")
return false
elseif rollCheck(item) == false then
self:sendCancelMessage("This item cannot be enchanted here.")
return false
else
item:setAttribute(ITEM_ATTRIBUTE_OWNER, self:getId())
Game.setStorageValue(30021, addEvent(abandonedItem, 60000, self:getId(), "anvil"))
return true
end
end
end
if fromCylinder and fromCylinder:isItem() then -- trying to move item from workbench
if fromCylinder:getId() == 23660 then
local ownerId = item:getAttribute(ITEM_ATTRIBUTE_OWNER) -- check owner
if ownerId ~= 0 then
local myId = self:getId()
if myId == ownerId then -- owner is trying to move their item
item:removeAttribute(ITEM_ATTRIBUTE_OWNER)
if Game.getStorageValue(30020) then
stopEvent(Game.getStorageValue(30020))
Game.setStorageValue(30020, -1)
end
return true
else -- someone is trying to move someone elses item
self:sendCancelMessage("This item does not belong to you.")
return false
end
else -- item has been abandoned in the workbench for a while, you can have it
self:sendTextMessage(MESSAGE_INFO_DESCR, "This item has been abandoned, it's now yours!")
end
elseif fromCylinder:getId() == 8671 then -- trying to move item from anvil
local ownerId = item:getAttribute(ITEM_ATTRIBUTE_OWNER)
if ownerId ~= 0 then
local myId = self:getId()
if myId == ownerId then
item:removeAttribute(ITEM_ATTRIBUTE_OWNER)
if Game.getStorageValue(30021) then
stopEvent(Game.getStorageValue(30021))
Game.setStorageValue(30021, -1)
end
return true
else
self:sendCancelMessage("This item does not belong to you.")
return false
end
else
self:sendTextMessage(MESSAGE_INFO_DESCR, "This item has been abandoned, it's now yours!")
end
end
end
return true
end