function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local addh = creature:getHealth()
local addm = creature:getMana()
creature:addHealth(addh)
creature:addMana(addm)
item:remove()
return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local healthToAdd = player:getMaxHealth() - player:getHealth()
local manaToAdd = player:getMaxMana() - player:getMana()
-- prevent the player from accidentally using the item or double clicking
if healthToAdd == 0 and manaToAdd == 0 then
player:sendCancelMessage('You already have full Health and Mana!')
return true
end
player:addHealth(healthToAdd)
player:addMana(manaToAdd)
player:say('Aaaaah!', TALKTYPE_MONSTER_SAY)
item:remove(1)
return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local lessThanFullHP = player:getMaxHealth() - player:getHealth() > 0
local lessThanFullMP = player:getMaxMana() - player:getMana() > 0
if not lessThanFullHP and not lessThanFullMP then
player:sendCancelMessage('You already have full Health and Mana!')
return true
end
player:addHealth(player:getMaxHealth())
player:addMana(player:getMaxMana())
player:say('Aaaaah!', TALKTYPE_MONSTER_SAY)
item:remove(1)
return true
end
Code:function onUse(player, item, fromPosition, target, toPosition, isHotkey) local healthToAdd = player:getMaxHealth() - player:getHealth() local manaToAdd = player:getMaxMana() - player:getMana() -- prevent the player from accidentally using the item or double clicking if healthToAdd == 0 and manaToAdd == 0 then player:sendCancelMessage('You already have full Health and Mana!') return true end player:addHealth(healthToAdd) player:addMana(manaToAdd) player:say('Aaaaah!', TALKTYPE_MONSTER_SAY) item:remove(1) return true end
You could also probably just do this instead of calculating how much to add, not sure which is better nor if it even matters:
Code:function onUse(player, item, fromPosition, target, toPosition, isHotkey) local lessThanFullHP = player:getMaxHealth() - player:getHealth() > 0 local lessThanFullMP = player:getMaxMana() - player:getMana() > 0 if not lessThanFullHP and not lessThanFullMP then player:sendCancelMessage('You already have full Health and Mana!') return true end player:addHealth(player:getMaxHealth()) player:addMana(player:getMaxMana()) player:say('Aaaaah!', TALKTYPE_MONSTER_SAY) item:remove(1) return true end