local config = {
minHeal = 300,
maxHeal = 600,
exhaust = 1000, -- milliseconds
effect = CONST_ME_MAGIC_RED,
infiniteItem = true
}
local exhaustedCreatures = {}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local playerId = player:getId()
local currentTime = os.mtime()
-- check exhaust
if exhaustedCreatures[playerId] and exhaustedCreatures[playerId] > currentTime then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are exhausted.")
return true
end
-- add exhaust
exhaustedCreatures[playerId] = currentTime + config.exhaust
-- heal player
local healAmount = math.random(config.minHeal, config.maxHeal)
player:addHealth(healAmount)
player:getPosition():sendMagicEffect(config.effect)
-- remove item, if not infinite
if not config.infiniteItem then
item:remove(1)
end
return true
end