ralke
(҂ ͠❛ ෴ ͡❛)ᕤ
- Joined
- Dec 17, 2011
- Messages
- 1,759
- Solutions
- 31
- Reaction score
- 999
- Location
- Santiago - Chile
- GitHub
- ralke23
- Twitch
- ralke23
new attributes inside if creature:isPlayer() then in function us_onDamaged:
Absorb Health, Absorb Mana, reflect physical,fire,energy,earth.
LUA:-- Absorb Health / Mana on being hit Logic if primaryDamage > 0 then -- Absorb Health local absorbHealthPercent = creature:getAttribute(ATTR_ABSORBHEALTH) if absorbHealthPercent and absorbHealthPercent > 0 then if math.random(100) < 20 then local healAmount = math.floor(primaryDamage * absorbHealthPercent / 100) if healAmount > 0 then creature:addHealth(healAmount) end end end -- Absorb Mana local absorbManaPercent = creature:getAttribute(ATTR_ABSORBMANA) if absorbManaPercent and absorbManaPercent > 0 then if math.random(100) < 20 then local manaAmount = math.floor(primaryDamage * absorbManaPercent / 100) if manaAmount > 0 then creature:addMana(manaAmount) end end end -- Reflect damage back to attacker (true damage) if attacker and attacker ~= creature and attacker:isCreature() then local totalPercent = 0 local function include(attrId) local percent = creature:getAttribute(attrId) if percent and percent > 0 then totalPercent = totalPercent + percent end end -- Sum applicable reflect attributes for this damage type if primaryType == COMBAT_PHYSICALDAMAGE then include(ATTR_REFLECTPHYSICAL) include(ATTR_REFLECTELEMENTS) elseif primaryType == COMBAT_FIREDAMAGE then include(ATTR_REFLECTFIRE) include(ATTR_REFLECTELEMENTS) elseif primaryType == COMBAT_ENERGYDAMAGE then include(ATTR_REFLECTENERGY) include(ATTR_REFLECTELEMENTS) elseif primaryType == COMBAT_EARTHDAMAGE then include(ATTR_REFLECTPOISON) include(ATTR_REFLECTELEMENTS) end if totalPercent > 0 then if math.random(100) < 20 then local reflectAmount = math.floor(primaryDamage * totalPercent / 100) if reflectAmount > 0 then doTargetCombatHealth(creature:getId(), attacker, COMBAT_PHYSICALDAMAGE, -reflectAmount, -reflectAmount, CONST_ME_DRAWBLOOD, ORIGIN_CONDITION) creature:getPosition():sendMagicEffect(73) local pos = attacker:getPosition() addEvent(function() Game.sendAnimatedText("Reflect!", pos, TEXTCOLOR_PASTELRED) end, 200) end end end
config.lua - based on oen attr's:
LUA:[ATTR_ABSORBHEALTH] = { name = "Absorb Health", combatType = US_TYPES.DEFENSIVE, combatDamage = COMBAT_ENERGYDAMAGE + COMBAT_EARTHDAMAGE + COMBAT_FIREDAMAGE, maxValue = 10, format = function(value) return "[Absorb Health +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.BOOTS + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }, [ATTR_ABSORBMANA] = { name = "Absorb Mana", combatType = US_TYPES.DEFENSIVE, combatDamage = COMBAT_ENERGYDAMAGE + COMBAT_EARTHDAMAGE + COMBAT_FIREDAMAGE, maxValue = 10, format = function(value) return "[Absorb Mana +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.BOOTS + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }, [ATTR_REFLECTPHYSICAL] = { name = "Reflect Physical", combatType = US_TYPES.DEFENSIVE, maxValue = 10, format = function(value) return "[Reflect Physical +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }, [ATTR_REFLECTFIRE] = { name = "Reflect Fire", combatType = US_TYPES.DEFENSIVE, maxValue = 10, format = function(value) return "[Reflect Fire +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }, [ATTR_REFLECTENERGY] = { name = "Reflect Energy", combatType = US_TYPES.DEFENSIVE, maxValue = 10, format = function(value) return "[Reflect Energy +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }, [ATTR_REFLECTPOISON] = { name = "Reflect Poison", combatType = US_TYPES.DEFENSIVE, maxValue = 10, format = function(value) return "[Reflect Poison +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }, [ATTR_REFLECTELEMENTS] = { name = "Reflect Elements", combatType = US_TYPES.DEFENSIVE, maxValue = 10, format = function(value) return "[Reflect Elements +" .. value .. "%]" end, itemType = US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.SHIELD + US_ITEM_TYPES.HELMET + US_ITEM_TYPES.LEGS }
You code ralke looks really greatdidn't had much time to analyze it but it looks great!
Thanks, appreciate it! Be aware with ATTR_REFLECTPHYSICAL and others because in older protocols I think that reflection attributes aren't enabled, that's why I only kept drown as reflection damage (without calling attribute, if i'm not wrong I used a formula from income damage). Regards!