Skip to content

Instantly share code, notes, and snippets.

@Codinablack
Last active February 22, 2022 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Codinablack/156f5d9febbaa296b525bc3353c94ac0 to your computer and use it in GitHub Desktop.
Save Codinablack/156f5d9febbaa296b525bc3353c94ac0 to your computer and use it in GitHub Desktop.
----========================================================================================================================----
----========================================================================================================================----
---- CUSTOM EQUIPMENT SYSTEM. CREATED BY CODINABLACK @ OTLAND.NET OR CODINABLACK @ GITHUB.COM. {SYC} SHARE YOUR COPY! ----
----========================================================================================================================----
----========================================================================================================================----
local customEquipment = {}
local baseItemList = {}
---//// CONFIGS \\\\----
local conditionLimit = 15 --- the amount of conditions a single item can hold.
local penaltyTicks = 6000 --- in milliseconds, how often player takes damage.
local maxReflectPercent = 100 --- the max percent of reflection for a single dmg type a player can receive from all equipment's total value. Don't use negatives please.
local maxAbsorbPercent = 100 --- the max percent of absorbtion for a single dmg type a player can receive from all equipment's total value. Don't use negatives please.
local maxPrimePercent = 100 --- the max percent of primary damage increase for a single dmg type a player can receive from all equipment's total value. There is no negative limit.
local maxSecondPercent = 100 --- the max percent of secondary damage increase for a single dmg type a player can receive from all equipment's total value. There is no negative limit.
local attributeReload = false --- only enable if you have custom equipment in-game circulation, and you have decided to change attribute(s), will reapply attributes during events.
local reloadOnLook = false --- works with "attributeReload", will reload custom equipment's attributes during onLook event.
local reloadOnEquip = false --- works with "attributeReload", will reload custom equipment's attributes during onLook event.
local enableLoot = true --- must enable this to use tier system, and/or allow looting items from monsters corpse. Tiers determine which is more likely to spawn, rare, or common.
local lootChance = 50 --- this is used for determining if the player gets loot or not, only after corpse drops item with matching id to baseItem of custom equipment, and chance from xml is already been used.
local enableLootMessage = true --- this will let a player know if an item has been turned into custom equipment inside a corpse
local showBuffsDescription = true --- when enabled, items buffs are shown in description upon looking at item
local showSkillsDescription = true --- when enabled, items skill enhancments are shown in description upon looking at item
local showSpecialSkillsDescription = true --- when enabled, items special skills are shown in description upon looking at item
local soulTicks = 1000 --- how often soul is gained when wearing equipment that has soul condition. 1000 = 1 second.
local healthTicks = 1000 --- how often health is gained when wearing equipment that has healthgain condition. 1000 = 1 second.
local manaTicks = 1000 --- how often mana is gained when wearing equipment that has managain condition. 1000 = 1 second.
local equipConditions = {
["healthgain"] = {type = CONDITION_REGENERATION, param = CONDITION_PARAM_HEALTHGAIN,},
["managain"] = {type = CONDITION_REGENERATION, param = CONDITION_PARAM_MANAGAIN,},
["maxhitpoints"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_STAT_MAXHITPOINTS,},
["maxmanapoints"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_STAT_MAXMANAPOINTS,},
["magicpoints"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_STAT_MAGICPOINTS,},
["maxhitpointspercent"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT,},
["maxmanapointspercent"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT,},
["magicpointspercent"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT,},
["meleeskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_MELEE,},
["fistskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_FIST,},
["clubskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_CLUB,},
["swordskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_SWORD,},
["axeskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_AXE,},
["distanceskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_DISTANCE,},
["shieldskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_SHIELD,},
["fishingskill"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SKILL_FISHING,},
["criticalhitchance"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,},
["criticalhitamount"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT,},
["lifeleechchance"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SPECIALSKILL_LIFELEECHCHANCE,},
["lifeleechamount"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT,},
["manaleechchance"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SPECIALSKILL_MANALEECHCHANCE,},
["manaleechamount"] = {type = CONDITION_ATTRIBUTES, param = CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT,},
["speed"] = {type = CONDITION_HASTE, param = CONDITION_PARAM_SPEED,},
["soul"] = {type = CONDITION_SOUL, param = CONDITION_PARAM_SOULGAIN,},
["manashield"] = {type = CONDITION_MANASHIELD, param = CONDITION_PARAM_BUFF_SPELL,},
["invis"] = {type = CONDITION_INVISIBLE, param = CONDITION_PARAM_BUFF_SPELL,},
}
local slotList = {
[CONST_SLOT_HEAD] = CONDITIONID_HEAD,
[CONST_SLOT_NECKLACE] = CONDITIONID_NECKLACE,
[CONST_SLOT_ARMOR] = CONDITIONID_ARMOR,
[CONST_SLOT_RIGHT] = CONDITIONID_RIGHT,
[CONST_SLOT_LEFT] = CONDITIONID_LEFT,
[CONST_SLOT_LEGS] = CONDITIONID_LEGS,
[CONST_SLOT_FEET] = CONDITIONID_FEET,
[CONST_SLOT_RING] = CONDITIONID_RING
}
--- custom equipment xml file location
local equipmentFile = io.open("data/XML/custom_equipment.xml", "r")
--- loading xml into organized table data for each item based on name.
for i in equipmentFile:read("*a"):gmatch("<equipment (.-)</equipment>") do
local properties = {}
properties.baseItem = tonumber(i:match('baseItem.-=.-"(.-)"'))
properties.equipId = tonumber(i:match('equipId.-=.-"(.-)"'))
properties.attributes = {
["aid"] = i:match('aid.-=.-"(.-)"'),
["article"] = i:match('article.-=.-"(.-)"'),
["name"] = i:match('name.-=.-"(.-)"'),
["description"] = i:match('attr.-=.-"description".-value.-=.-"(.-)"'),
["defense"] = tonumber(i:match('attr.-=.-"defense".-value.-=.-"(.-)"')),
["weight"] = tonumber(i:match('attr.-=.-"weight".-value.-=.-"(.-)"')),
["attack"] = tonumber(i:match('attr.-=.-"attack".-value.-=.-"(.-)"')),
["extradefense"] = tonumber(i:match('attr.-=.-"extradef".-value.-=.-"(.-)"')),
["armor"] = tonumber(i:match('attr.-=.-"armor".-value.-=.-"(.-)"')),
["hitchance"] = tonumber(i:match('attr.-=.-"hitchance".-value.-=.-"(.-)"')),
["shootrange"] = tonumber(i:match('attr.-=.-"shootrange".-value.-=.-"(.-)"')),
}
properties.conditions = {
["healthgain"] = tonumber(i:match('buff.-=.-"healthgain".-value.-=.-"(.-)"')),
["managain"] = tonumber(i:match('buff.-=.-"managain".-value.-=.-"(.-)"')),
["maxhitpoints"] = tonumber(i:match('buff.-=.-"maxhitpoints".-value.-=.-"(.-)"')),
["maxmanapoints"] = tonumber(i:match('buff.-=.-"maxmanapoints".-value.-=.-"(.-)"')),
["magicpoints"] = tonumber(i:match('buff.-=.-"magicpoints".-value.-=.-"(.-)"')),
["maxhitpointspercent"] = tonumber(i:match('buff.-=.-"maxhitpointspercent".-value.-=.-"(.-)"')),
["maxmanapointspercent"] = tonumber(i:match('buff.-=.-"maxmanapointspercent".-value.-=.-"(.-)"')),
["magicpointspercent"] = tonumber(i:match('buff.-=.-"magicpointspercent".-value.-=.-"(.-)"')),
["meleeskill"] = tonumber(i:match('buff.-=.-"melee".-value.-=.-"(.-)"')),
["fistskill"] = tonumber(i:match('skill.-=.-"fist".-value.-=.-"(.-)"')),
["clubskill"] = tonumber(i:match('skill.-=.-"club".-value.-=.-"(.-)"')),
["swordskill"] = tonumber(i:match('skill.-=.-"sword".-value.-=.-"(.-)"')),
["axeskill"] = tonumber(i:match('skill.-=.-"axe".-value.-=.-"(.-)"')),
["distanceskill"] = tonumber(i:match('skill.-=.-"distance".-value.-=.-"(.-)"')),
["shieldskill"] = tonumber(i:match('skill.-=.-"shield".-value.-=.-"(.-)"')),
["fishingskill"] = tonumber(i:match('skill.-=.-"fishing".-value.-=.-"(.-)"')),
["criticalhitchance"] = tonumber(i:match('crit.-=.-"chance".-percent.-=.-"(.-)"')),
["criticalhitamount"] = tonumber(i:match('crit.-=.-"amount".-percent.-=.-"(.-)"')),
["lifeleechchance"] = tonumber(i:match('lifeleech.-=.-"chance".-percent.-=.-"(.-)"')),
["lifeleechamount"] = tonumber(i:match('lifeleech.-=.-"amount".-percent.-=.-"(.-)"')),
["manaleechchance"] = tonumber(i:match('manaleech.-=.-"chance".-percent.-=.-"(.-)"')),
["manaleechamount"] = tonumber(i:match('manaleech.-=.-"amount".-percent.-=.-"(.-)"')),
["speed"] = tonumber(i:match('buff.-=.-"speed".-value.-=.-"(.-)"')),
["soul"] = tonumber(i:match('buff.-=.-"soul".-value.-=.-"(.-)"')),
["manashield"] = tonumber(i:match('buff.-=.-"manashield".-enabled.-=.-"(.-)"')),
["invis"] = tonumber(i:match('buff.-=.-"invis".-enabled.-=.-"(.-)"')),
}
properties.penalties = {
[CONDITION_INFIGHT] = tonumber(i:match('penalty.-=.-"pzlock".-enabled.-=.-"(.-)"')),
[CONDITION_DRUNK] = tonumber(i:match('penalty.-=.-"drunk".-enabled.-=.-"(.-)"')),
[CONDITION_PARALYZE] = tonumber(i:match('penalty.-=.-"poison".-enabled.-=.-"(.-)"')),
[CONDITION_MUTED] = tonumber(i:match('penalty.-=.-"mute".-enabled.-=.-"(.-)"')),
[CONDITION_PACIFIED] = tonumber(i:match('penalty.-=.-"pacify".-enabled.-=.-"(.-)"')),
[CONDITION_EXHAUST_WEAPON] = tonumber(i:match('penalty.-=.-"disableweapon".-enabled.-=.-"(.-)"')),
[CONDITION_EXHAUST_COMBAT] = tonumber(i:match('penalty.-=.-"disablecombat".-enabled.-=.-"(.-)"')),
[CONDITION_EXHAUST_HEAL] = tonumber(i:match('penalty.-=.-"disableheal".-enabled.-=.-"(.-)"')),
}
properties.dmgPenalties =
{
[CONDITION_POISON] = tonumber(i:match('penalty.-=.-"poison".-damage.-=.-"(.-)"')),
[CONDITION_FIRE] = tonumber(i:match('penalty.-=.-"burn".-damage.-=.-"(.-)"')),
[CONDITION_ENERGY] = tonumber(i:match('penalty.-=.-"shock".-damage.-=.-"(.-)"')),
[CONDITION_BLEEDING] = tonumber(i:match('penalty.-=.-"bleed".-damage.-=.-"(.-)"')),
[CONDITION_CURSED] = tonumber(i:match('penalty.-=.-"curse".-damage.-=.-"(.-)"')),
[CONDITION_DAZZLED] = tonumber(i:match('penalty.-=.-"dazzle".-damage.-=.-"(.-)"')),
[CONDITION_DROWN] = tonumber(i:match('penalty.-=.-"drown".-damage.-=.-"(.-)"')),
[CONDITION_FREEZING] = tonumber(i:match('penalty.-=.-"freeze".-damage.-=.-"(.-)"')),
}
properties.absorbs = {
[COMBAT_PHYSICALDAMAGE] = tonumber(i:match('absorb.-=.-"physical".-percent.-=.-"(.-)"')),
[COMBAT_ENERGYDAMAGE] = tonumber(i:match('absorb.-=.-"energy".-percent.-=.-"(.-)"')),
[COMBAT_EARTHDAMAGE] = tonumber(i:match('absorb.-=.-"earth".-percent.-=.-"(.-)"')),
[COMBAT_FIREDAMAGE] = tonumber(i:match('absorb.-=.-"fire".-percent.-=.-"(.-)"')),
[COMBAT_DROWNDAMAGE] = tonumber(i:match('absorb.-=.-"water".-percent.-=.-"(.-)"')),
[COMBAT_ICEDAMAGE] = tonumber(i:match('absorb.-=.-"ice".-percent.-=.-"(.-)"')),
[COMBAT_HOLYDAMAGE] = tonumber(i:match('absorb.-=.-"holy".-percent.-=.-"(.-)"')),
[COMBAT_DEATHDAMAGE] = tonumber(i:match('absorb.-=.-"death".-percent.-=.-"(.-)"')),
}
properties.reflects = {
[COMBAT_PHYSICALDAMAGE] = tonumber(i:match('reflect.-=.-"physical".-percent.-=.-"(.-)"')),
[COMBAT_ENERGYDAMAGE] = tonumber(i:match('reflect.-=.-"energy".-percent.-=.-"(.-)"')),
[COMBAT_EARTHDAMAGE] = tonumber(i:match('reflect.-=.-"earth".-percent.-=.-"(.-)"')),
[COMBAT_FIREDAMAGE] = tonumber(i:match('reflect.-=.-"fire".-percent.-=.-"(.-)"')),
[COMBAT_DROWNDAMAGE] = tonumber(i:match('reflect.-=.-"water".-percent.-=.-"(.-)"')),
[COMBAT_ICEDAMAGE] = tonumber(i:match('reflect.-=.-"ice".-percent.-=.-"(.-)"')),
[COMBAT_HOLYDAMAGE] = tonumber(i:match('reflect.-=.-"holy".-percent.-=.-"(.-)"')),
[COMBAT_DEATHDAMAGE] = tonumber(i:match('reflect.-=.-"death".-percent.-=.-"(.-)"')),
}
properties.primeTypes = {
[COMBAT_ENERGYDAMAGE] = tonumber(i:match('primary.-=.-"energy".-percent.-=.-"(.-)"')),
[COMBAT_EARTHDAMAGE] = tonumber(i:match('primary.-=.-"earth".-percent.-=.-"(.-)"')),
[COMBAT_FIREDAMAGE] = tonumber(i:match('primary.-=.-"fire".-percent.-=.-"(.-)"')),
[COMBAT_DROWNDAMAGE] = tonumber(i:match('primary.-=.-"water".-percent.-=.-"(.-)"')),
[COMBAT_ICEDAMAGE] = tonumber(i:match('primary.-=.-"ice".-percent.-=.-"(.-)"')),
[COMBAT_HOLYDAMAGE] = tonumber(i:match('primary.-=.-"holy".-percent.-=.-"(.-)"')),
[COMBAT_DEATHDAMAGE] = tonumber(i:match('primary.-=.-"death".-percent.-=.-"(.-)"')),
}
properties.secondTypes = {
[COMBAT_ENERGYDAMAGE] = tonumber(i:match('secondary.-=.-"energy".-percent.-=.-"(.-)"')),
[COMBAT_EARTHDAMAGE] = tonumber(i:match('secondary.-=.-"earth".-percent.-=.-"(.-)"')),
[COMBAT_FIREDAMAGE] = tonumber(i:match('secondary.-=.-"fire".-percent.-=.-"(.-)"')),
[COMBAT_DROWNDAMAGE] = tonumber(i:match('secondary.-=.-"water".-percent.-=.-"(.-)"')),
[COMBAT_ICEDAMAGE] = tonumber(i:match('secondary.-=.-"ice".-percent.-=.-"(.-)"')),
[COMBAT_HOLYDAMAGE] = tonumber(i:match('secondary.-=.-"holy".-percent.-=.-"(.-)"')),
[COMBAT_DEATHDAMAGE] = tonumber(i:match('secondary.-=.-"death".-percent.-=.-"(.-)"')),
}
properties.requirements = {
["level"] = tonumber(i:match('level.-=.-"(.-)"')),
["magiclevel"] = tonumber(i:match('magiclevel.-=.-"(.-)"')),
["premium"] = tonumber(i:match('premium.-=.-"(.-)"')),
["vocation"] = i:match('vocation.-=.-"(.-)"'),
}
properties.expGain = tonumber(i:match('expgain.-=.-"(.-)"'))
properties.tier = {
["lootable"] = tonumber(i:match('lootable.-=.-"(.-)"')),
["chance"] = tonumber(i:match('lootchance.-=.-"(.-)"')),
}
local itemType = ItemType(properties.baseItem)
local group = itemType:getGroup()
--- in this system, we only accept weapons that are not wands, and valid armor for customization, any other types will not be accepted by the system.
if not group == (ITEM_GROUP_WEAPON or ITEM_GROUP_ARMOR) then
print("Error item " ..properties.attributes["name"].. " is not a valid weapon or armor! Was not added to CustomEquipment!")
else
local weaponType = itemType:getWeaponType()
if weaponType == WEAPON_WAND then
print("Error item " ..properties.attributes["name"].. " is a wand, wand's are currently not supported, was not added to CustomEquipment!")
end
if weaponType == WEAPON_AMMO then
print("Error item " ..properties.attributes["name"].. " is a type of ammo, ammo type's are not supported, was not added to CustomEquipment!")
end
if not table.contains(baseItemList, properties.baseItem) then
table.insert(baseItemList, properties.baseItem)
end
customEquipment[properties.equipId] = properties
end
end
----\\\\\\\\\\\\\\\\\\\\\\\\\\\\----
----===== REVSCRIPT EVENTS =====----
----\\\\\\\\\\\\\\\\\\\\\\\\\\\\----
local healthEvent = CreatureEvent("HealthProcessor")
function healthEvent.onHealthChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not player:isPlayer() then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if attacker == nil then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
local eq = {}
local reflectPercent = 0
local absorbPercent = 0
local primePercent = 0
local secondPercent = 0
for k , v in pairs(slotList) do
if player:getSlotItem(k)then
if player:getSlotItem(k):getCustomEquipId()then
local item = player:getSlotItem(k)
if item then
table.insert(eq, item)
end
end
end
end
if #eq > 0 then
for k,v in pairs(eq) do
local customItem = customEquipment[v:getCustomEquipId()]
if customItem then
if customItem.reflects[primaryType] then
reflectPercent = reflectPercent + customItem.reflects[primaryType]
if reflectPercent >= maxReflectPercent then
reflectPercent = maxReflectPercent
end
end
if customItem.absorbs[primaryType] then
absorbPercent = absorbPercent + customItem.absorbs[primaryType]
if absorbPercent >= maxAbsorbPercent then
absorbPercent = maxAbsorbPercent
end
end
if customItem.primeTypes[primaryType] then
primePercent = primePercent + customItem.primeTypes[primaryType]
if primePercent >= maxPrimePercent then
primePercent = maxPrimePercent
end
end
if customItem.secondTypes[secondaryType] then
secondPercent = secondPercent + customItem.secondTypes[secondaryType]
if secondPercent >= maxSecondPercent then
secondPercent = maxSecondPercent
end
end
end
end
end
if primePercent ~= 0 then
primaryDamage = (primaryDamage/100) * primePercent
end
if secondPercent ~= 0 then
secondPercent = (secondaryDamage/100) * secondPercent
end
if reflectPercent ~= 0 then
local reflectDamage = (primaryDamage/100) * reflectPercent
primaryDamage = primaryDamage - reflectDamage
player:say("reflecting")
doTargetCombat(attacker:getId(), attacker, primaryType, -reflectDamage, -reflectDamage, CONST_ME_NONE) -- can be exploited.
end
if absorbPercent ~= 0 then
local absorbDamage = (primaryDamage/100) * absorbPercent
primaryDamage = primaryDamage - absorbDamage
player:say("absorbing")
player:addHealth(absorbDamage)
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
healthEvent:register()
local manaEvent = CreatureEvent("ManaProcessor")
function manaEvent.onManaChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not player:isPlayer() then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if not player:getCondition(CONDITION_MANASHIELD) then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if attacker == nil then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
local eq = {}
local reflectPercent = 0
local absorbPercent = 0
local primePercent = 0
local secondPercent = 0
for k , v in pairs(slotList) do
if player:getSlotItem(k)then
if player:getSlotItem(k):getCustomEquipId()then
local item = player:getSlotItem(k)
if item then
table.insert(eq, item)
end
end
end
end
if #eq > 0 then
for k,v in pairs(eq) do
local customItem = customEquipment[v:getCustomEquipId()]
if customItem then
if customItem.reflects[primaryType] then
reflectPercent = reflectPercent + customItem.reflects[primaryType]
if reflectPercent >= maxReflectPercent then
reflectPercent = maxReflectPercent
end
end
if customItem.absorbs[primaryType] then
absorbPercent = absorbPercent + customItem.absorbs[primaryType]
if absorbPercent >= maxAbsorbPercent then
absorbPercent = maxAbsorbPercent
end
end
if customItem.primeTypes[primaryType] then
primePercent = primePercent + customItem.primeTypes[primaryType]
if primePercent >= maxPrimePercent then
primePercent = maxPrimePercent
end
end
if customItem.secondTypes[secondaryType] then
secondPercent = secondPercent + customItem.secondTypes[secondaryType]
if secondPercent >= maxSecondPercent then
secondPercent = maxSecondPercent
end
end
end
end
end
if primePercent ~= 0 then
primaryDamage = (primaryDamage/100) * primePercent
end
if secondPercent ~= 0 then
secondPercent = (secondaryDamage/100) * secondPercent
end
if reflectPercent ~= 0 then
local reflectDamage = (primaryDamage/100) * reflectPercent
primaryDamage = primaryDamage - reflectDamage
player:say("reflecting")
doTargetCombat(attacker:getId(), attacker, primaryType, -reflectDamage, -reflectDamage, CONST_ME_NONE) -- can be exploited.
end
if absorbPercent ~= 0 then
local absorbDamage = (primaryDamage/100) * absorbPercent
primaryDamage = primaryDamage - absorbDamage
player:say("absorbing")
player:addHealth(absorbDamage)
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
manaEvent:register()
local dropLootEvent = EventCallback
dropLootEvent.onDropLoot = function(self, corpse)
if not enableLoot then
return true
end
local lottery = {}
for index, item in pairs(corpse:getItems()) do
if table.contains(baseItemList, item:getId()) then
for eq, attr in pairs(customEquipment) do
if attr.baseItem == item:getId() then
if attr.tier and attr.tier["lootable"] then
if attr.tier["chance"] and attr.tier["chance"] < math.random(100) then
table.insert(lottery, attr.equipId)
end
end
end
end
end
end
if #lottery > 0 then
local equipId = lottery[math.random(#lottery)]
if math.random(100) > lootChance then
for index, item in pairs(corpse:getItems()) do
if customEquipment[equipId].baseItem == item:getId() then
local name = item:getName()
item:transformToEq(equipId)
if enableLootMessage then
Player(corpse:getCorpseOwner()):sendTextMessage(MESSAGE_LOOT, "There is something different about that " ..name.. "!")
end
end
end
end
end
return true
end
dropLootEvent:register(2)
local lookEvent = EventCallback
lookEvent.onLook = function(self, thing, position, distance, description)
if thing:isItem() then
if thing:getCustomEquipId() then
local eq = customEquipment[thing:getCustomEquipId()]
if eq then
-- Buffs
if showBuffsDescription then
if eq.conditions["healthgain"] then
description = string.format("%s\nHealth Regeneration: +" ..eq.conditions["healthgain"].. "", description)
end
if eq.conditions["managain"] then
description = string.format("%s\nMana Regeneration: +" ..eq.conditions["managain"].. "", description)
end
if eq.conditions["maxhitpoints"] then
description = string.format("%s\nMaximum hitpoints: +" ..eq.conditions["maxhitpoints"].. "", description)
end
if eq.conditions["maxmanapoints"] then
description = string.format("%s\nMaximum manapoints : +" ..eq.conditions["maxmanapoints"].. "", description)
end
if eq.conditions["magicpoints"] then
description = string.format("%s\nMagic boost: +" ..eq.conditions["magicpoints"].. "", description)
end
if eq.conditions["meleeskill"] then
description = string.format("%s\nMelee boost: +" ..eq.conditions["meleeskill"].. "", description)
end
if eq.conditions["speed"] then
description = string.format("%s\nSpeed boost: +" ..eq.conditions["speed"].. "", description)
end
if eq.conditions["soul"] then
description = string.format("%s\nSoul boost: +" ..eq.conditions["soul"].. "", description)
end
if eq.conditions["manashield"] then
description = string.format("%s\nManashield Activation ", description)
end
if eq.conditions["invis"] then
description = string.format("%s\nInvisible Activation ", description)
end
end
-- Skills
if showSkillsDescription then
if eq.conditions["fistskill"] then
description = string.format("%s\nFist skill boost: +" ..eq.conditions["fistskill"].. "", description)
end
if eq.conditions["clubskill"] then
description = string.format("%s\nClub skill boost: +" ..eq.conditions["clubskill"].. "", description)
end
if eq.conditions["swordskill"] then
description = string.format("%s\nSword skill boost: +" ..eq.conditions["swordskill"].. "", description)
end
if eq.conditions["axeskill"] then
description = string.format("%s\nAxe skill boost: +" ..eq.conditions["axeskill"].. "", description)
end
if eq.conditions["distanceskill"] then
description = string.format("%s\nDistance skill boost: +" ..eq.conditions["distanceskill"].. "", description)
end
if eq.conditions["shieldskill"] then
description = string.format("%s\nShield skill boost: +" ..eq.conditions["shieldskill"].. "", description)
end
if eq.conditions["fishingskill"] then
description = string.format("%s\nFishing skill boost: +" ..eq.conditions["fishingskill"].. "", description)
end
end
-- Special skill
if showSpecialSkillsDescription then
if eq.conditions["criticalhitchance"] then
description = string.format("%s\nCritical hit chance: +" ..eq.conditions["criticalhitchance"].. "", description)
end
if eq.conditions["criticalhitamount"] then
description = string.format("%s\nCritical hit amount: +" ..eq.conditions["criticalhitamount"].. "", description)
end
if eq.conditions["lifeleechchance"] then
description = string.format("%s\nLife leech chance: +" ..eq.conditions["lifeleechchance"].. "", description)
end
if eq.conditions["lifeleechamount"] then
description = string.format("%s\nLife leech amount: +" ..eq.conditions["lifeleechamount"].. "", description)
end
if eq.conditions["manaleechchance"] then
description = string.format("%s\nMana leech chance: +" ..eq.conditions["manaleechchance"].. "", description)
end
if eq.conditions["manaleechamount"] then
description = string.format("%s\nMana leech amount: +" ..eq.conditions["manaleechamount"].. "", description)
end
end
--- Requirements
if eq.requirements["level"] and type(eq.requirements["level"]) == "number" then
description = string.format("%s\nLevel Required: %d", description, eq.requirements["level"])
end
if eq.requirements["magiclevel"] and type(eq.requirements["magiclevel"]) == "number" then
description = string.format("%s\nMagic Level Required: %d", description, eq.requirements["magiclevel"])
end
if eq.requirements["premium"] and eq.requirements["premium"] > 0 then
description = string.format("%s\nPremium Required", description)
end
if eq.requirements["vocation"] then
description = string.format("%s\nVocation Required: " ..eq.requirements["vocation"].. "", description)
end
--- attributes reload onLook
if attributeReload then
if reloadOnLook then
for attr, val in pairs(eq.attributes) do
item:setAttribute(attr, val)
end
end
end
end
end
end
return description
end
lookEvent:register(1)
for key , id in pairs(baseItemList) do
local equipEvent = MoveEvent()
local deEquipEvent = MoveEvent()
equipEvent:id(id)
deEquipEvent:id(id)
function equipEvent.onEquip(player, item, slot, isCheck)
if isCheck == true then
local eq = customEquipment[item:getCustomEquipId()]
if eq then
if eq.requirements["level"] and eq.requirements["level"] > player:getLevel() then
player:sendTextMessage(MESSAGE_INFO_DESCR,"You don't have the proper level required to equip that item!")
return false
end
if eq.requirements["magiclevel"] and eq.requirements["magiclevel"] > player:getMagicLevel() then
player:sendTextMessage(MESSAGE_INFO_DESCR,"You don't have the proper magic level required to equip that item!")
return false
end
if eq.requirements["premium"] and eq.requirements["premium"] > 0 then
if not player:getPremiumEndsAt() then
player:sendTextMessage(MESSAGE_INFO_DESCR,"You must have premium to equip that item!")
return false
end
end
if eq.requirements["vocation"] then
local vocation = Vocation(eq.requirements["vocation"])
if vocation then
if vocation ~= (player:getVocation() or player:getVocation():getDemotion()) then
player:sendTextMessage(MESSAGE_INFO_DESCR,"You don't have the proper vocation to equip that item!")
return false
end
end
end
end
end
if isCheck == false then
if customEquipment[item:getCustomEquipId()] then
player:applyEquipmentConditions(item, slot)
player:applyEquipmentPentalties(item, slot)
player:applyDamagePenalties(item, slot)
player:registerEvent("HealthProcessor")
player:registerEvent("ManaProcessor")
--- attributes reload onEquip
if attributeReload then
if reloadOnEquip then
for attr, val in pairs(customEquipment[item:getCustomEquipId()].attributes) do
item:setAttribute(attr, val)
end
end
end
return true
end
end
return true
end
function deEquipEvent.onDeEquip(player, item, slot, isCheck)
if isCheck == false then
if customEquipment[item:getCustomEquipId()] then
player:removeEquipmentConditions(item, slot)
player:removeEquipmentPentalties(item, slot)
player:removeDamagePenalties(item, slot)
if player:hasCustomEquipment() then
return true
end
player:unregisterEvent("HealthProcessor")
player:unregisterEvent("ManaProcessor")
return true
end
end
return true
end
equipEvent:register()
deEquipEvent:register()
end
---\\\\\ END EVENTS \\\\\----
---\\\\\ FUNCTIONS/METHODS \\\\\---
--- returns false if it is ammo or backpack
local function getConditionIdForSlot(slotType)
return slotList[slotType] or false
end
function Player:addCustomEquipment(equipId)
if customEquipment[equipId] then
local item = self:addItem(customEquipment[equipId].baseItem)
for attr, val in pairs(customEquipment[equipId].attributes) do
item:setAttribute(attr, val)
item:setCustomAttribute("CustomEquipmentId", equipId)
end
end
end
function Player:applyEquipmentConditions(item, slot)
local equipment = customEquipment[item:getCustomEquipId()]
local conditionId = getConditionIdForSlot(slot)
if conditionId then
local conditionCount = 1
for _index, _value in pairs(equipment.conditions) do
if _index and _value then
local uniqueId = (100 + (conditionId * conditionLimit)) + conditionCount
local key = equipConditions[_index]
local condition = Condition(key.type, conditionId)
condition:setParameter(CONDITION_PARAM_SUBID, uniqueId)
condition:setTicks(-1)
if key.type == CONDITION_MANASHIELD then
self:addCondition(condition)
end
if key.type == CONDITION_SOUL then
condition:setParameter(key.param, _value)
condition:setParameter(CONDITION_PARAM_SOULTICKS, soulTicks)
self:addCondition(condition)
end
if key.type == CONDITION_REGENERATION then
if key.param == CONDITION_PARAM_HEALTHGAIN then
condition:setParameter(key.param, _value)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, healthTicks)
self:addCondition(condition)
end
if key.param == CONDITION_PARAM_MANAGAIN then
condition:setParameter(key.param, _value)
condition:setParameter(CONDITION_PARAM_MANATICKS, manaTicks)
self:addCondition(condition)
end
end
if not key.param == CONDITION_MANASHIELD or CONDITION_SOUL or CONDITION_REGENERATION or CONDITION_PARAM_MANAGAIN then
condition:setParameter(key.param, _value)
self:addCondition(condition)
end
conditionCount = conditionCount + 1
end
end
end
end
function Player:removeEquipmentConditions(item, slot)
local equipment = customEquipment[item:getCustomEquipId()]
local conditionId = getConditionIdForSlot(slot)
if conditionId then
local conditionCount = 1
for _index, _value in pairs(equipment.conditions) do
if _index and _value then
local uniqueId = (100 + (conditionId * conditionLimit)) + conditionCount
local key = equipConditions[_index]
self:removeCondition(key.type, conditionId, uniqueId)
conditionCount = conditionCount + 1
end
end
end
end
function Player:applyEquipmentPentalties(item, slot)
local equipment = customEquipment[item:getCustomEquipId()]
local penaltyId = getConditionIdForSlot(slot)
if penaltyId then
local penaltyCount = 1
for _index, _value in pairs(equipment.penalties) do
if _index and _value then
if _value > 0 then
local uniqueId = (500 + (penaltyId * conditionLimit)) + penaltyCount
local condition = Condition(_index, penaltyId)
if condition then
condition:setTicks(-1)
condition:setParameter(CONDITION_PARAM_SUBID, uniqueId)
self:addCondition(condition)
end
penaltyCount = penaltyCount + 1
end
end
end
end
end
function Player:removeEquipmentPentalties(item, slot)
local equipment = customEquipment[item:getCustomEquipId()]
local penaltyId = getConditionIdForSlot(slot)
if penaltyId then
local penaltyCount = 1
for _index, _value in pairs(equipment.penalties) do
if _index and _value then
if _value > 0 then
local uniqueId = (500 + (penaltyId * conditionLimit)) + penaltyCount
self:removeCondition(_index, penaltyId, uniqueId)
penaltyCount = penaltyCount + 1
end
end
end
end
end
function Player:applyDamagePenalties(item, slot)
local equipment = customEquipment[item:getCustomEquipId()]
local penaltyId = getConditionIdForSlot(slot)
if penaltyId then
local penaltyCount = 1
for _index, _value in pairs(equipment.dmgPenalties) do
if _index and _value then
local uniqueId = (1000 + (penaltyId * conditionLimit)) + penaltyCount
local condition = Condition(_index, penaltyId)
if condition then
condition:setTicks(-1)
condition:setParameter(CONDITION_PARAM_SUBID, uniqueId)
condition:addDamage(-1, penaltyTicks, _value)
condition:setParameter(CONDITION_PARAM_DELAYED, false)
self:addCondition(condition)
end
penaltyCount = penaltyCount + 1
end
end
end
end
function Player:removeDamagePenalties(item, slot)
local equipment = customEquipment[item:getCustomEquipId()]
local penaltyId = getConditionIdForSlot(slot)
if penaltyId then
local penaltyCount = 1
for _index, _value in pairs(equipment.dmgPenalties) do
if _index and _value then
local uniqueId = (1000 + (penaltyId * conditionLimit)) + penaltyCount
self:removeCondition(_index, penaltyId, uniqueId)
penaltyCount = penaltyCount + 1
end
end
end
end
function Item:getCustomEquipId()
return self:getCustomAttribute("CustomEquipmentId")
end
function Item:transformToEq(equipId)
if customEquipment[equipId] then
for attr, val in pairs(customEquipment[equipId].attributes) do
self:setAttribute(attr, val)
end
self:setCustomAttribute("CustomEquipmentId", equipId)
else
print("Invalid EquipID")
end
end
function Player:hasCustomEquipment()
for k, v in pairs(slotList) do
if self:getSlotItem(k) and self:getSlotItem(k):getCustomEquipId() then
return true
end
end
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment