-- Everything is funnelled through this
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if creature:isPlayer() then
-- do stuff
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
-- Health
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if primaryType ~= 128 then -- Ignore health potions
-- This is where we push it through statChange...
2 scripts based on (on health/mana change) events one of them gives bonus healing (this bonus healing based on ur storage value) and second one dodge the dmg coming to u depending on percent (this percent based on ur storage value)Can you give example on what you want done?
with more than one word
To make it more simple about the bonus healingCan you give example on what you want done?
with more than one word
-- Everything is funnelled through this
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if creature:isPlayer() then
-- do stuff
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
-- Health
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if primaryType ~= 128 then -- Ignore health potions
-- This is where we push it through statChange
primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
-- Mana
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if primaryType ~= 64 then -- Ignore mana potions
-- This is where we push it through statChange
primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if creature:isPlayer() then
if creature:getStorageValue(XXXXX) > 0 then
if math.random(1,100) == 1 then -- 1% dodge
creature:getPosition():sendMagicEffect(CONST_ME_POFF)
creature:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You dodged an attack.")
return false -- this cancels the damage/heal/spell
end
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if creature:isPlayer() then
if creature:getStorageValue(XXXXX) > 0 then
if primaryType = COMBAT_HEALING then -- Healing
primaryDamage = primaryDamage + ((primaryDamage / 100) * 5) -- 5% healing buff
end
if secondaryType = COMBAT_HEALING then -- Healing
secondaryDamage = secondaryDamage + ((secondaryDamage / 100) * 5) -- 5% healing buff
end
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
<event type="healthchange" name="CombatModifiersHealth" script="combatmodifiers.lua"/>
<event type="manachange" name="CombatModifiersMana" script="combatmodifiers.lua"/>
player:registerEvent("CombatModifiersHealth")
player:registerEvent("CombatModifiersMana")
function Monster:onSpawn(position, startup, artificial)
self:registerEvent("CombatModifiersHealth")
self:registerEvent("CombatModifiersMana")
return true
end
Thanks for that, u saved meThe trick is to funnel onManaChange and onHealthChange through another function.
So boosts/reductions work properly regardless if the player has magic shield up or not.
Like this (non revscriptsys example):
Lua:-- Everything is funnelled through this function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if creature:isPlayer() then -- do stuff end return primaryDamage, primaryType, secondaryDamage, secondaryType, origin end -- Health function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if primaryType ~= 128 then -- Ignore health potions -- This is where we push it through statChange primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula end return primaryDamage, primaryType, secondaryDamage, secondaryType, origin end -- Mana function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if primaryType ~= 64 then -- Ignore mana potions -- This is where we push it through statChange primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula end return primaryDamage, primaryType, secondaryDamage, secondaryType, origin end
So dodges can be done like this:
Lua:function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if creature:isPlayer() then if creature:getStorageValue(XXXXX) > 0 then if math.random(1,100) == 1 then -- 1% dodge creature:getPosition():sendMagicEffect(CONST_ME_POFF) creature:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You dodged an attack.") return false -- this cancels the damage/heal/spell end end end return primaryDamage, primaryType, secondaryDamage, secondaryType, origin end
Healing is done by detecting that its type COMBAT_HEALING and buffing the values:
Lua:function statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if creature:isPlayer() then if creature:getStorageValue(XXXXX) > 0 then if primaryType = COMBAT_HEALING then -- Healing primaryDamage = primaryDamage + ((primaryDamage / 100) * 5) -- 5% healing buff end if secondaryType = COMBAT_HEALING then -- Healing secondaryDamage = secondaryDamage + ((secondaryDamage / 100) * 5) -- 5% healing buff end end end return primaryDamage, primaryType, secondaryDamage, secondaryType, origin end
I assume you already know how to register onHealthChange and onManaChange through creaturescripts.xml
XML:<event type="healthchange" name="CombatModifiersHealth" script="combatmodifiers.lua"/> <event type="manachange" name="CombatModifiersMana" script="combatmodifiers.lua"/>
And register it on players via login.lua:
Lua:player:registerEvent("CombatModifiersHealth") player:registerEvent("CombatModifiersMana")
If your changes affects monsters, you need to register it on each monster too.
I simply use the onSpawn function to do this (just like login.lua does for players):
Lua:function Monster:onSpawn(pos, forced) self:registerEvent("CombatModifiersHealth") self:registerEvent("CombatModifiersMana") return true end
Do not use this code as-is, its purely an example.
You need to actively test these sorts of changes as you're creating your new system.