--------------------------------------------------------------------------------------
eventCheckHead = {}
--------------------------------------------------------------------------------------
function table.removeKey(table, key)
local element = table[key]
table[key] = nil
return element
end
--------------------------------------------------------------------------------------
local magicBuff = Condition(CONDITION_ATTRIBUTES)
magicBuff:setParameter(CONDITION_PARAM_TICKS, 15 * 1000)
magicBuff:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 4)
magicBuff:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
--------------------------------------------------------------------------------------
local function checkHead(creatureUid)
local cid = Creature(creatureUid)
local player = cid:getPlayer()
if getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid == 2663 then
player:addCondition(magicBuff)
if (eventCheckHead[creatureUid]~=nil) then stopEvent(eventCheckHead[creatureUid]) end
eventCheckHead[creatureUid] = addEvent(checkHead, 10*1000, creatureUid)
else
table.removeKey(eventCheckHead, creatureUid)
end
end
--------------------------------------------------------------------------------------
function onEquip(cid, item, slot)
checkHead(cid.uid)
return true
end
--------------------------------------------------------------------------------------
function onDeEquip(cid, item, slot)
local player = cid:getPlayer()
if player:getCondition(CONDITION_ATTRIBUTES) then
player:removeCondition(CONDITION_ATTRIBUTES)
end
if (eventCheckHead~=nil) then stopEvent(eventCheckHead) end
Game.sendAnimatedText("Next time I will do my homework on my own.", getCreaturePosition(cid), TEXTCOLOR_LIGHTBLUE)
table.removeKey(eventCheckHead, cid.uid)
return true
end
--------------------------------------------------------------------------------------