S
Shadow_
Guest
Had to write this code for my server because when player PVP they die faster than they should, so i gave players protection through this code depending on their vocation,
so this code won't work verses monsters only players, you can easily change it by removing the if function i will show you it down in the code,
pvpbalance.lua
in creaturescripts.xml
in login.lua
in events.xml (set this to enabled = "1")
in events/scripts/creature.lua
under the function
how this code works, if player is creature and attacker is creature too it will remove from the dmg the percentage you want (as protection all) but a little different it removes x% from the dmg the player received, code explained in pvpbalance.lua
so this code won't work verses monsters only players, you can easily change it by removing the if function i will show you it down in the code,
pvpbalance.lua
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not creature or not attacker or creature == attacker then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if creature:isPlayer() and creature:getParty() and attacker:isPlayer() and attacker:getParty() then
if creature:getParty() == attacker:getParty() then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
end
if creature:isPlayer() and attacker:isPlayer() then -- remove attacker:isPlayer() to affect monsters fights
primaryDamage = math.floor(primaryDamage - (primaryDamage * 20 / 100)) -- for EK and pallies when they switch to HP
secondaryDamage = math.floor(secondaryDamage - (secondaryDamage * 20 / 100)) -- for EK and pallies when they switch to HP
local damage = (primaryDamage + secondaryDamage)
if damage < 0 then
damage = damage * -1
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not creature or not attacker or creature == attacker then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if creature:isPlayer() and creature:getParty() and attacker:isPlayer() and attacker:getParty() then
if creature:getParty() == attacker:getParty() then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
end
if creature:isPlayer() and attacker:isPlayer() then
if creature:getVocation():getId() == 3 or creature:getVocation():getId() == 7 then
primaryDamage = math.floor(primaryDamage - (primaryDamage * 12 / 100)) -- PALLIES on MP
secondaryDamage = math.floor(secondaryDamage - (secondaryDamage * 12 / 100)) -- PALLIES on MP
else
primaryDamage = math.floor(primaryDamage - (primaryDamage * 65 / 100)) -- MAGES (SORC/DRUID)
secondaryDamage = math.floor(secondaryDamage - (secondaryDamage * 65 / 100)) -- MAGES (SORC/DRUID)
end
local damage = (primaryDamage + secondaryDamage)
if damage < 0 then
damage = damage * -1
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
XML:
<event type="healthchange" name="PvpBalance" script="pvpbalance.lua" />
<event type="manachange" name="PvpBalanceMA" script="pvpbalance.lua" />
in login.lua
Code:
player:registerEvent("PvpBalance")
player:registerEvent("PvpBalanceMA")
in events.xml (set this to enabled = "1")
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />
in events/scripts/creature.lua
under the function
function Creature:onTargetCombat(target)
add this
Code:
target:registerEvent("PvpBalance")
target:registerEvent("PvpBalance")