local config = {
storage = 50000,
duration = 2 * 60 * 60,
itemId = 12345,
effect = CONST_ME_MAGIC_BLUE
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if not isPlayer(cid) then
return true
end
if item.itemid ~= config.itemId then
return true
end
local current = getPlayerStorageValue(cid, config.storage)
if current ~= -1 and current > os.time() then
local left = current - os.time()
local hours = math.floor(left / 3600)
local minutes = math.floor((left % 3600) / 60)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,
"This item is already active. Time left: " .. hours .. " hour(s) and " .. minutes .. " minute(s).")
return true
end
setPlayerStorageValue(cid, config.storage, os.time() + config.duration)
doSendMagicEffect(getThingPos(cid), config.effect)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Life/Mana leech activated for 2 hours.")
return true
end