• 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!

[TFS 1.2] Critical System Health/Mana

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
360
Solutions
1
Reaction score
76
Hi Otlanders,
This is my first contribution, all the scripts I have in the community and there will be an improvement I will contribute with you.

This script is a critical system, you can SEPARATELY configure the damage of sorcerer / druid and paladin / knight and it can also SEPARATELY configure the chance of each vocation to criticize.

data/creaturescripts/creaturescripts.xml
XML:
    <event type="healthchange" name="criticalHitSystemXHP" script="critical_hit_system.lua"/>
    <event type="manachange" name="criticalHitSystemXMP" script="critical_hit_system.lua"/>
data/creaturescripts/scripts/critical_hit_system.lua
Lua:
local config = {
    magic_effect = 173, -- magic effect you want to send when critical hit lands
    damage_magic = 1.8, -- Sorcerers and Druids
    damage_physical = 2.0 -- Paladins and Knights
}

local function getSkill(player)
    local vocation = player:getVocation()
    while vocation:getDemotion() do
        vocation = vocation:getDemotion()
    end

    local vocId = vocation:getId()
    if vocId == 1 or vocId == 2 then
        return player:getMagicLevel() * 0.05, config.damage_magic
    elseif vocId == 3 then
        return player:getEffectiveSkillLevel(SKILL_DISTANCE) * 0.07, config.damage_physical
    elseif vocId == 4 then
        local sword = player:getEffectiveSkillLevel(SKILL_SWORD)
        local club = player:getEffectiveSkillLevel(SKILL_CLUB)
        local axe = player:getEffectiveSkillLevel(SKILL_AXE)
        return math.max(sword, club, axe) * 0.07, config.damage_physical
    end
    return nil
end

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

     local chance, multiplier = getSkill(attacker)
    if not chance then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if math.random(100) <= chance then
        creature:getPosition():sendMagicEffect(config.magic_effect)
        return primaryDamage * multiplier, primaryType, secondaryDamage, secondaryType
    end
    
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onManaChange(creature, attacker, manaChange, origin)
    if not attacker:isPlayer() then
        return manaChange
    end

     local chance, multiplier = getSkill(attacker)
    if not chance then
        return manaChange
    end
 
   if math.random(100) <= chance then
        creature:getPosition():sendMagicEffect(config.magic_effect)
        return manaChange * multiplier
    end

    return manaChange
end
data/creaturescripts/login.lua
Lua:
    player:registerEvent("criticalHitSystemXHP")
    player:registerEvent("criticalHitSystemXMP")
 
i have this error, TFS 1.2
Use these scripts below, and you will have no problem
Lua:
local config = {
    magic_effect = 173, -- magic effect you want to send when critical hit lands
    damage_magic = 1.8, -- Sorcerers and Druids
    damage_physical = 2.0 -- Paladins and Knights
}

local function getSkill(player)
    local vocation = player:getVocation()
    while vocation:getDemotion() do
        vocation = vocation:getDemotion()
    end

    local vocId = vocation:getId()
    if vocId == 1 or vocId == 2 then
        return player:getMagicLevel() * 0.03, config.damage_magic
    elseif vocId == 3 then
        return player:getEffectiveSkillLevel(SKILL_DISTANCE) * 0.04, config.damage_physical
    elseif vocId == 4 then
        local sword = player:getEffectiveSkillLevel(SKILL_SWORD)
        local club = player:getEffectiveSkillLevel(SKILL_CLUB)
        local axe = player:getEffectiveSkillLevel(SKILL_AXE)
        return math.max(sword, club, axe) * 0.04, config.damage_physical
    end
    return nil
end

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    
    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

     local chance, multiplier = getSkill(attacker)
    if not chance then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if math.random(100) <= chance then
        creature:getPosition():sendMagicEffect(config.magic_effect)
        return primaryDamage * multiplier, primaryType, secondaryDamage, secondaryType
    end
    
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onManaChange(creature, attacker, manaChange, origin)
    if not attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    
    if not attacker:isPlayer() then
        return manaChange
    end

     local chance, multiplier = getSkill(attacker)
    if not chance then
        return manaChange
    end
 
   if math.random(100) <= chance then
        creature:getPosition():sendMagicEffect(config.magic_effect)
        return manaChange * multiplier
    end

    return manaChange
end
 
Use these scripts below, and you will have no problem
Lua:
local config = {
    magic_effect = 173, -- magic effect you want to send when critical hit lands
    damage_magic = 1.8, -- Sorcerers and Druids
    damage_physical = 2.0 -- Paladins and Knights
}

local function getSkill(player)
    local vocation = player:getVocation()
    while vocation:getDemotion() do
        vocation = vocation:getDemotion()
    end

    local vocId = vocation:getId()
    if vocId == 1 or vocId == 2 then
        return player:getMagicLevel() * 0.03, config.damage_magic
    elseif vocId == 3 then
        return player:getEffectiveSkillLevel(SKILL_DISTANCE) * 0.04, config.damage_physical
    elseif vocId == 4 then
        local sword = player:getEffectiveSkillLevel(SKILL_SWORD)
        local club = player:getEffectiveSkillLevel(SKILL_CLUB)
        local axe = player:getEffectiveSkillLevel(SKILL_AXE)
        return math.max(sword, club, axe) * 0.04, config.damage_physical
    end
    return nil
end

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
   
    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

     local chance, multiplier = getSkill(attacker)
    if not chance then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if math.random(100) <= chance then
        creature:getPosition():sendMagicEffect(config.magic_effect)
        return primaryDamage * multiplier, primaryType, secondaryDamage, secondaryType
    end
   
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onManaChange(creature, attacker, manaChange, origin)
    if not attacker then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
   
    if not attacker:isPlayer() then
        return manaChange
    end

     local chance, multiplier = getSkill(attacker)
    if not chance then
        return manaChange
    end

   if math.random(100) <= chance then
        creature:getPosition():sendMagicEffect(config.magic_effect)
        return manaChange * multiplier
    end

    return manaChange
end

Now all mana potions dont work ;(
 
Now all mana potions dont work ;(
mana potion has nothing to do with the script. It must be another mistake you made!
Post automatically merged:

Yes I can :)
@Edit:
Hm i don't need add script to monsters?
ya, use within each monsters.xml the code below

XML:
<script>
        <event name="criticalHitSystemXHP"/>
</script>
 
ya, use within each monsters.xml the code below

  1. Open data/events/events.xml
  2. Find <event class="Creature" method="onTargetCombat" enabled="0" /> and change enabled="0" to enabled="1"
  3. Open data/events/scripts/creature.lua
  4. Find function Creature:onTargetCombat(target) and add there target:registerEvent("criticalHitSystemXHP")

so you don't need to register every xml file
 
1596113687393.png


have this error when use mana potion

change if not attacker then to if primaryType ~= 64 then
 
Last edited:
Lua:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/critical_hit_system.lua:onManaChange
data/creaturescripts/scripts/critical_hit_system.lua:46: attempt to index local 'attacker' (a nil value)
edit:
Lua:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/critical_hit_system.lua:onHealthChange
data/creaturescripts/scripts/critical_hit_system.lua:28: attempt to index local 'attacker' (a nil value)
tfs 1.2

edit2

solved, add mising
Lua:
vocId
 
Last edited:
XML:
   <event type="healthchange" name="criticalHitSystemXHP" script="critical_hit_system.lua"/>
    <event type="manachange" name="criticalHitSystemXMP" script="critical_hit_system.lua"/>

Didnt know that it considers damage to mana and damage to health differently.

I'm using TFS 1.3 (downgraded by Nekiro for tibia 8.6), and I've added a system from this forum that adds effects to weapons, would these work together?

i.e.: Since the swords still deal a primary damage, it could crit even if it has other effects from another system.
 
XML:
   <event type="healthchange" name="criticalHitSystemXHP" script="critical_hit_system.lua"/>
    <event type="manachange" name="criticalHitSystemXMP" script="critical_hit_system.lua"/>

Didnt know that it considers damage to mana and damage to health differently.

I'm using TFS 1.3 (downgraded by Nekiro for tibia 8.6), and I've added a system from this forum that adds effects to weapons, would these work together?

i.e.: Since the swords still deal a primary damage, it could crit even if it has other effects from another system.
I think so, just testing to know 100%
 
how to modify so that the critic would be influenced by the skill club?
the higher the level, the greater the chance and value
I intend to use it in a derivative, there are several vocations, how would it look?
 
You need to be careful when handling onManaChange and onHealthChange as any missed scenarios will cause an error and the creature/player to do 0 damage/healing.

Health Potions and Mana Potions both trigger onHeathChange and onManaChange and need to be specifically excluded:
i.e.
 
Back
Top