local POTION_ID = 0000
local storageKey = 00000
local extraHP = 25
local extraMP = 25
local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
local storageValue = tonumber(player:getStorageValue(storageKey)) or -1
if storageValue ~= -1 then
player:sendCancelMessage("You have already used this potion.")
return true
end
player:setStorageValue(storageKey, 1)
player:setMaxHealth(player:getMaxHealth() + extraHP)
player:setMaxMana(player:getMaxMana() + extraMP)
player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(
"You have used a potion and gained %d extra HP and %d extra MP.",
extraHP, extraMP))
item:remove(1)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
return true
end
action:id(POTION_ID)
action:register()