• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

CreatureEvent [TFS 1.3] Vocations Balancing [Easiest Way]

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
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
in creaturescripts.xml
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")
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
 
Have anyone tested this? Am a neewbie so i got to ask where do u put
pvpbalance.lua file?
 
Sorry i never saw notifications, Honestly I use it in my server it helps me alot to decrease the sent damage with a scale i control.
 
Just as a wonder, primaryDamage = math.floor(primaryDamage - (primaryDamage * 65 / 100)) -- MAGES (SORC/DRUID) is that the primary dmg *65 / 100 = 6,5 is that the dmg scale that is reduced with mage and the SecondaryDmG? Or how do u scale within normal control?
 
Just as a wonder, primaryDamage = math.floor(primaryDamage - (primaryDamage * 65 / 100)) -- MAGES (SORC/DRUID) is that the primary dmg *65 / 100 = 6,5 is that the dmg scale that is reduced with mage and the SecondaryDmG? Or how do u scale within normal control?
(secondaryDamage * 12 / 100) Better way is (secondaryDamage * 0.12),
I think good idea is to avoid multiple math operations if they are added unnecessarily and adds nothing to the operation.
65 / 100 = 0.65 so as Ascuas suggested better to use it as primaryDamage * 0.10 -- which means 10% reduced because 1000 * 0.10 = 900
 
65 / 100 = 0.65 so as Ascuas suggested better to use it as primaryDamage * 0.10 -- which means 10% reduced because 1000 * 0.10 = 900
1000 * 0.10 = 100 :D
For easy understand 1000 is "x" and 0.10 is "y".
For y 1 is equal to 100% and y is percent value of x.
Examples: If basic damage is 1000.

To reduce damage by 10% - 1000 * 0.9
Output is 900

To increase damage by 10% - 1000 * 1.1
Output is 1100
 
Back
Top