local config = {
[1111] = { -- itemid
slot = "ammo", -- ("head", "necklace", "backpack", "armor", "shield", "weapon", "legs", "feet", "ring", "ammo")
{
[{1, 5}] = { -- vocation 1 and vocation 5
["statMain"] = {
-- flat_bonus_stats
{"life increase", 50},
{"mana increase", -200}, -- negative numbers will reduce a players stats
{"magic", 5},
{"melee", 15}, -- sword/axe/club
{"fist", 5},
{"club", 5}, -- if both melee and club exist on a single item, club will be the one that will trigger.
{"sword", 5}, -- example: (melee 20) -> (sword 5) ----> Result: (club 20) (sword 5) (axe 20)
{"axe", 5},
{"distance", 5},
{"shield", 5},
{"fishing", 5},
{"critical hit chance", 5},
{"critical hit damage", 5},
{"life leech chance", 5},
{"life leech amount", 5},
{"mana leech chance", 5},
{"mana leech amount", 5},
-- percent_bonus_stats
{"life increase percent", 200}, -- If using flat_bonus_stats and percent_bonus_stats on the same item, the percent_bonus_stats is the only one that will trigger.
{"mana increase percent", 200}, -- same idea as melee/club, but for flat/percent
{"magic percent", 3000},
{"melee percent", 200},
{"fist percent", 200}, -- 200 = 200% -> 15 fisting would turn into 30
{"club percent", 200},
{"sword percent", 200},
{"axe percent", 200},
{"distance percent", 200},
{"shield percent", 200},
{"fishing percent", 200}
},
["statSpeed"] = {
{"speed", 1000} -- when testing, it only gave half of this value. Might just be my client though
},
["statRegen"] = {
{"life regen", 5, 5000}, --{type, amount, ticks_in_milliseconds}
{"mana regen", 5, 5000} -- (can't go lower then 1 second)
},
["statSoulRegen"] = {
{"soul regen", 5, 5000}
},
},
[{2, 6}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
},
[{3, 7}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
},
[{4, 8}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
}
}
},
[2222] = {
slot = "armor",
{
[{1, 5}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
},
[{2, 6}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
},
[{3, 7}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
},
[{4, 8}] = {
["statMain"] = {},
["statSpeed"] = {},
["statRegen"] = {},
["statSoulRegen"] = {}
}
}
},
[3333] = {
slot = "ammo",
{
[{1, 5}] = {["statMain"] = {{"magic", 5}} },
[{2, 6}] = {["statSpeed"] = {{"speed", 500}} },
[{3, 7}] = {["statRegen"] = {{"life regen", 5, 5000}} },
[{4, 8}] = {["statSoulRegen"] = {{"soul regen", 5, 5000}} }
}
}
}
local function convertSlotTextToNumber(slot)
local text = nil
if slot == "head" then
slot = 1
elseif slot == "necklace" then
slot = 2
elseif slot == "backpack" then
slot = 3
elseif slot == "armor" then
slot = 4
elseif slot == "shield" then
slot = 5
elseif slot == "weapon" then
slot = 6
elseif slot == "legs" then
slot = 7
elseif slot == "feet" then
slot = 8
elseif slot == "ring" then
slot = 9
elseif slot == "ammo" then
slot = 10
end
return slot
end
local condition_ids = {
CONDITIONID_HEAD,
CONDITIONID_NECKLACE,
CONDITIONID_BACKPACK,
CONDITIONID_ARMOR,
CONDITIONID_RIGHT,
CONDITIONID_LEFT,
CONDITIONID_LEGS,
CONDITIONID_FEET,
CONDITIONID_RING,
CONDITIONID_AMMO
}
local conditions = {
["life increase"] = {CONDITION_PARAM_STAT_MAXHITPOINTS},
["mana increase"] = {CONDITION_PARAM_STAT_MAXMANAPOINTS},
["speed"] = {CONDITION_PARAM_SPEED},
["magic"] = {CONDITION_PARAM_STAT_MAGICPOINTS},
["melee"] = {CONDITION_PARAM_SKILL_MELEE},
["fist"] = {CONDITION_PARAM_SKILL_FIST},
["club"] = {CONDITION_PARAM_SKILL_CLUB},
["sword"] = {CONDITION_PARAM_SKILL_SWORD},
["axe"] = {CONDITION_PARAM_SKILL_AXE},
["distance"] = {CONDITION_PARAM_SKILL_DISTANCE},
["shield"] = {CONDITION_PARAM_SKILL_SHIELD},
["fishing"] = {CONDITION_PARAM_SKILL_FISHING},
["critical hit chance"] = {CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE},
["critical hit damage"] = {CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT},
["life leech chance"] = {CONDITION_PARAM_SPECIALSKILL_LIFELEECHCHANCE},
["life leech amount"] = {CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT},
["mana leech chance"] = {CONDITION_PARAM_SPECIALSKILL_MANALEECHCHANCE},
["mana leech amount"] = {CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT},
["life increase percent"] = {CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT},
["mana increase percent"] = {CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT},
["magic percent"] = {CONDITION_PARAM_STAT_MAGICPOINTSPERCENT},
["melee percent"] = {CONDITION_PARAM_SKILL_MELEEPERCENT},
["fist percent"] = {CONDITION_PARAM_SKILL_FISTPERCENT},
["club percent"] = {CONDITION_PARAM_SKILL_CLUBPERCENT},
["sword percent"] = {CONDITION_PARAM_SKILL_SWORDPERCENT},
["axe percent"] = {CONDITION_PARAM_SKILL_AXEPERCENT},
["distance percent"] = {CONDITION_PARAM_SKILL_DISTANCEPERCENT},
["shield percent"] = {CONDITION_PARAM_SKILL_SHIELDPERCENT},
["fishing percent"] = {CONDITION_PARAM_SKILL_FISHINGPERCENT},
["life regen"] = {CONDITION_PARAM_HEALTHGAIN, CONDITION_PARAM_HEALTHTICKS},
["mana regen"] = {CONDITION_PARAM_MANAGAIN, CONDITION_PARAM_MANATICKS},
["soul regen"] = {CONDITION_PARAM_SOULGAIN, CONDITION_PARAM_SOULTICKS}
}
local main_attributes = {CONDITION_ATTRIBUTES, CONDITION_HASTE, CONDITION_REGENERATION, CONDITION_SOUL}
local main_stats = {"statMain", "statSpeed", "statRegen", "statSoulRegen"}
local function giveItemBonus(playerid)
local player = Player(playerid)
local player_equipment = {}
-- find all player equipment
for i = 1, 10 do
local slotItem = player:getSlotItem(i)
if slotItem then
slotItem = slotItem.itemid
if not config[slotItem] or convertSlotTextToNumber(config[slotItem].slot) ~= i then
slotItem = 0
end
else
slotItem = 0
end
table.insert(player_equipment, slotItem)
end
-- remove all buffs from armor
for i = 1, 10 do
for n = 1, 4 do
if player:getCondition(main_attributes[n], condition_ids[i]) then
player:removeCondition(main_attributes[n], condition_ids[i])
end
end
end
-- add all buffs from equipment
local vocation = player:getVocation():getId()
for i = 1, 10 do
local itemID = player_equipment[i]
if itemID ~= 0 then
for voc, _ in pairs(config[itemID][1]) do
if isInArray(voc, vocation) then
for n = 1, 4 do
if config[itemID][1][voc][main_stats[n]] then
local condition = Condition(main_attributes[n], condition_ids[i])
condition:setParameter(CONDITION_PARAM_TICKS, -1)
local itemBonusIndex = config[itemID][1][voc][main_stats[n]]
for h = 1, #itemBonusIndex do
for p = 1, #conditions[itemBonusIndex[h][1]] do
condition:setParameter(conditions[itemBonusIndex[h][1]][p], itemBonusIndex[h][2])
end
end
player:addCondition(condition)
end
end
end
end
end
end
return true
end
-- HEAD -------------------------------------------------------------------------------
local onEquip_Head = MoveEvent()
function onEquip_Head.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Head:slot("head")
onEquip_Head:id(1111, 2222, 3333)
onEquip_Head:register()
local onDeEquip_Head = MoveEvent()
function onDeEquip_Head.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Head:slot("head")
onDeEquip_Head:id(1111, 2222, 3333)
onDeEquip_Head:register()
-- NECKLACE -------------------------------------------------------------------------------
local onEquip_Necklace = MoveEvent()
function onEquip_Necklace.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Necklace:slot("necklace")
onEquip_Necklace:id(1111, 2222, 3333)
onEquip_Necklace:register()
local onDeEquip_Necklace = MoveEvent()
function onDeEquip_Necklace.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Necklace:slot("necklace")
onDeEquip_Necklace:id(1111, 2222, 3333)
onDeEquip_Necklace:register()
-- BACKPACK -------------------------------------------------------------------------------
local onEquip_Backpack = MoveEvent()
function onEquip_Backpack.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Backpack:slot("backpack")
onEquip_Backpack:id(1111, 2222, 3333)
onEquip_Backpack:register()
local onDeEquip_Backpack = MoveEvent()
function onDeEquip_Backpack.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Backpack:slot("backpack")
onDeEquip_Backpack:id(1111, 2222, 3333)
onDeEquip_Backpack:register()
-- ARMOR -------------------------------------------------------------------------------
local onEquip_Armor = MoveEvent()
function onEquip_Armor.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Armor:slot("armor")
onEquip_Armor:id(1111, 2222, 3333)
onEquip_Armor:register()
local onDeEquip_Armor = MoveEvent()
function onDeEquip_Armor.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Armor:slot("armor")
onDeEquip_Armor:id(1111, 2222, 3333)
onDeEquip_Armor:register()
-- WEAPONS AND SHIELDS (hands) --------------------------------------------------------
local onEquip_Hands = MoveEvent()
function onEquip_Hands.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Hands:slot("hand")
onEquip_Hands:id(1111, 2222, 3333)
onEquip_Hands:register()
local onDeEquip_Hands = MoveEvent()
function onDeEquip_Hands.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Hands:slot("hand")
onDeEquip_Hands:id(1111, 2222, 3333)
onDeEquip_Hands:register()
-- LEGS -------------------------------------------------------------------------------
local onEquip_Legs = MoveEvent()
function onEquip_Legs.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Legs:slot("legs")
onEquip_Legs:id(1111, 2222, 3333)
onEquip_Legs:register()
local onDeEquip_Legs = MoveEvent()
function onDeEquip_Legs.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Legs:slot("legs")
onDeEquip_Legs:id(1111, 2222, 3333)
onDeEquip_Legs:register()
-- FEET -------------------------------------------------------------------------------
local onEquip_Feet = MoveEvent()
function onEquip_Feet.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Feet:slot("feet")
onEquip_Feet:id(1111, 2222, 3333)
onEquip_Feet:register()
local onDeEquip_Feet = MoveEvent()
function onDeEquip_Feet.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Feet:slot("feet")
onDeEquip_Feet:id(1111, 2222, 3333)
onDeEquip_Feet:register()
-- RING -------------------------------------------------------------------------------
local onEquip_Ring = MoveEvent()
function onEquip_Ring.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Ring:slot("ring")
onEquip_Ring:id(1111, 2222, 3333)
onEquip_Ring:register()
local onDeEquip_Ring = MoveEvent()
function onDeEquip_Ring.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Ring:slot("ring")
onDeEquip_Ring:id(1111, 2222, 3333)
onDeEquip_Ring:register()
-- AMMO -------------------------------------------------------------------------------
local onEquip_Ammo = MoveEvent()
function onEquip_Ammo.onEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onEquip_Ammo:slot("ammo")
onEquip_Ammo:id(1111, 2222, 3333)
onEquip_Ammo:register()
local onDeEquip_Ammo = MoveEvent()
function onDeEquip_Ammo.onDeEquip(player, item, slot, isCheck)
if not isCheck then
addEvent(giveItemBonus, 0, player:getId())
end
return true
end
onDeEquip_Ammo:slot("ammo")
onDeEquip_Ammo:id(1111, 2222, 3333)
onDeEquip_Ammo:register()
-- LOGIN ------------------------------------------------------------------------------
local loginEvent = CreatureEvent("newLoginEvent")
loginEvent:type("login")
function loginEvent.onLogin(player)
addEvent(giveItemBonus, 0, player:getId())
return true
end
loginEvent:register()