• 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] Need Critical hit system

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hi
maybe someone have critical system script? That works like this, lets say you have "10 sword fighting you have 1% chance to hit critical hit", "20 sword fighting you have 2% chance to hit critical hit", "30 sword fighting you have 3% chance to hit critical hit" and etc and when you hit critical hit it sends some kind of magic effect and thats it.
 
Solution

Try this:

1. Create file critical_hit_system.lua in data\creaturescripts\scripts and add the following:

Lua:
local config = {
    magic_effect = 15, -- magic effect you want to send when critical hit lands
    damage_multiplier = 10 -- default damage * 10 = critical damage
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD)
    local chance = (skill...
Try this:

1. Create file critical_hit_system.lua in data\creaturescripts\scripts and add the following:

Lua:
local config = {
    magic_effect = 15, -- magic effect you want to send when critical hit lands
    damage_multiplier = 10 -- default damage * 10 = critical damage
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD)
    local chance = (skill * 0.1)
 
    if math.random(100) <= chance then
        attacker:getPosition():sendMagicEffect(config.magic_effect)
        return primaryDamage * config.damage_multiplier, primaryType, secondaryDamage, secondaryType
    end
   
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

2. In data\creaturescripts\creaturescripts.xml add this line at the top, inside <creaturescripts>

Lua:
<event type="healthchange" name="criticalHitSystemX" script="critical_hit_system.lua"/>

3. In data\creaturescripts\scripts\login.lua under player:registerEvent("PlayerDeath"), add the following line:

Lua:
player:registerEvent("criticalHitSystemX")

4. This step is optional, and only required if you want to make this work with monsters - you will have to add that code for each monster that you want the critical hit system to work with. Under </flags>, add the following:

XML:
<script>
        <event name="criticalHitSystemX"/>
</script>

Hi, can someone explain to me how primaryDamage works?
Get the highest Skill worth? Sum with weapon damage? How it works?
 
Try this:

1. Create file critical_hit_system.lua in data\creaturescripts\scripts and add the following:

Lua:
local config = {
    magic_effect = 15, -- magic effect you want to send when critical hit lands
    damage_multiplier = 10 -- default damage * 10 = critical damage
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD)
    local chance = (skill * 0.1)

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

2. In data\creaturescripts\creaturescripts.xml add this line at the top, inside <creaturescripts>

Lua:
<event type="healthchange" name="criticalHitSystemX" script="critical_hit_system.lua"/>

3. In data\creaturescripts\scripts\login.lua under player:registerEvent("PlayerDeath"), add the following line:

Lua:
player:registerEvent("criticalHitSystemX")

4. This step is optional, and only required if you want to make this work with monsters - you will have to add that code for each monster that you want the critical hit system to work with. Under </flags>, add the following:

XML:
<script>
        <event name="criticalHitSystemX"/>
</script>
Hello,
Would it be possible to add "local skill", sword, ax, club, distance, magic level, to each skill a "chance" of critical hit?
 
Try this:

1. Create file critical_hit_system.lua in data\creaturescripts\scripts and add the following:

Lua:
local config = {
    magic_effect = 15, -- magic effect you want to send when critical hit lands
    damage_multiplier = 10 -- default damage * 10 = critical damage
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD)
    local chance = (skill * 0.1)

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

2. In data\creaturescripts\creaturescripts.xml add this line at the top, inside <creaturescripts>

Lua:
<event type="healthchange" name="criticalHitSystemX" script="critical_hit_system.lua"/>

3. In data\creaturescripts\scripts\login.lua under player:registerEvent("PlayerDeath"), add the following line:

Lua:
player:registerEvent("criticalHitSystemX")

4. This step is optional, and only required if you want to make this work with monsters - you will have to add that code for each monster that you want the critical hit system to work with. Under </flags>, add the following:

XML:
<script>
        <event name="criticalHitSystemX"/>
</script>


I have problem.

<event type="healthchange" name="criticalHitSystemX" script="critical_hit_system.lua"/>

It says on the console that the type "healthchange" is not valid, or does not exist. Something like. Mine is TFS 1.2
 
Back
Top