-- config
local conditionTimeSeconds = 2 * 60
local HP = 1000
local MP = 1000
local magLevel = 30
local skills = {
fist = 10,
club = 10,
sword = 10,
axe = 10,
distance = 10,
shield = 10,
}
local eventConditionSubId = 123
function addEventStatsCondition(player)
-- first try to remove, make sure it's not added twice
removeEventStatsCondition(player)
local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
-- unique subid for condition, to make it does not interact with other attributes conditions
condition:setParameter(CONDITION_PARAM_SUBID, eventConditionSubId)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
-- HP change
condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, HP - player:getMaxHealth())
-- mana change
condition:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, MP - player:getMaxMana())
-- mlvl change
condition:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, magLevel - player:getBaseMagicLevel())
-- change skills
condition:setParameter(CONDITION_PARAM_SKILL_FIST, skills.fist - player:getSkillLevel(SKILL_FIST))
condition:setParameter(CONDITION_PARAM_SKILL_CLUB, skills.club - player:getSkillLevel(SKILL_CLUB))
condition:setParameter(CONDITION_PARAM_SKILL_SWORD, skills.sword - player:getSkillLevel(SKILL_SWORD))
condition:setParameter(CONDITION_PARAM_SKILL_AXE, skills.axe - player:getSkillLevel(SKILL_AXE))
condition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skills.distance - player:getSkillLevel(SKILL_DISTANCE))
condition:setParameter(CONDITION_PARAM_SKILL_SHIELD, skills.shield - player:getSkillLevel(SKILL_SHIELD))
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
player:addCondition(condition)
end
function removeEventStatsCondition(player)
player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, eventConditionSubId)
end
-- Register action
local mirrorAction = Action()
-- Define what happens when the item is used
function mirrorAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- Retrieve the current storage value for key 130
local storageKey = 130
local currentValue = player:getStorageValue(storageKey)
if currentValue == -1 or currentValue == 0 then
-- If storage value is -1 or 0, set it to 1 and add event stats
player:setStorageValue(storageKey, 1)
addEventStatsCondition(player)
elseif currentValue == 1 then
-- If storage value is 1, set it to -1 and remove event stats
player:setStorageValue(storageKey, -1)
removeEventStatsCondition(player)
end
return true
end
mirrorAction:id(2560)
mirrorAction:register()