• 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.X+ Critical system for TFS 1.3

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
898
Solutions
21
Reaction score
427
Location
Santiago - Chile
Hi again! I saw this critical system in a post and I wonder if someone can help me by setting up critical chances for axes, clubs, wands, all kind of distance weapons, and fist too, because is only running on sword skill local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD). This is the script:

Code:
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

Going to register to monsters by using this way, I dont know if this would affect the performance of the script?

  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

Thanks in advance!
 
Solution
Alright, back to the original question, your way is very hacky, but it will work and there is no better solution if you are not going to edit sources.
Your script is pretty fine and it shouldn't affect performance significally as there are worse things done in lua.
NGL pretty smart usage of onTargetCombat, gj.
I think you should think about hooking onAreaCombat too. I don't remember if area spells will trigger onTargetCombat, something to check.

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,496
Solutions
113
Reaction score
1,745
TFS 1.3 has critical system implemented by default.
criticalhitchance, criticalhitamount in items.xml to use it.

You can also use it dynamically using conditions
Lua:
local condition = Condition(CONDITION_ATTRIBUTES)
condition:setTicks(2000)
condition:setParameter(CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE, 50)
condition:setParameter(CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT, 50)
player:addCondition(condition) -- player gets increased critical hit chance and amount for 2 sec
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
898
Solutions
21
Reaction score
427
Location
Santiago - Chile
Oh ok! Got it. My last question, is this critical system you mentioned been one of the lastest updates for TFS 1.3? Because i'm using this OTX 3.8 by fablow and he recommended me to implement the system I posted. If it does support the criticalhitchance, criticalhitamount then thread should be solved.

He said to me
Code:
8.6 does not handle leech/critical system.
 

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,496
Solutions
113
Reaction score
1,745
Oh ok! Got it. My last question, is this critical system you mentioned been one of the lastest updates for TFS 1.3? Because i'm using this OTX 3.8 by fablow and he recommended me to implement the system I posted. If it does support the criticalhitchance, criticalhitamount then thread should be solved.

He said to me
Code:
8.6 does not handle leech/critical system.
No idea, latest tfs 1.3 does have it for some time now, your otx probably not. You can look it up in sources.
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
898
Solutions
21
Reaction score
427
Location
Santiago - Chile
Hmm. Guess not, I don't see it on config.lua or other place. Any chance to set multiple local conditions for the script, like I said in the main post?
Code:
local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD)

Maybe something like
Code:
local skill = attacker:getEffectiveSkillLevel(SKILL_AXE)
local skill2 = attacker:getEffectiveSkillLevel(SKILL_CLUB)
local skill3 = attacker:getEffectiveSkillLevel(SKILL_FIST)
local chance = (skill * 0.1)
local chance2 = (skill2 * 0.1)
local chance3 = (skill3 * 0.1)

Then do
Code:
if math.random(100) <= chance or  if math.random(100) <= chance2 or  if math.random(100) <= chance3 then

In a easiest way? Maybe generated by tables or other stuff. Thanks for responding @Nekiro
Btw sorry for not following the TFS 1.3 path, i'm too bad at source editing I would love to have this via LUA because is easier for me.
 

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,496
Solutions
113
Reaction score
1,745
Alright, back to the original question, your way is very hacky, but it will work and there is no better solution if you are not going to edit sources.
Your script is pretty fine and it shouldn't affect performance significally as there are worse things done in lua.
NGL pretty smart usage of onTargetCombat, gj.
I think you should think about hooking onAreaCombat too. I don't remember if area spells will trigger onTargetCombat, something to check.
 
Solution
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
898
Solutions
21
Reaction score
427
Location
Santiago - Chile
Then I should
Code:
function Creature:onAreaCombat(tile, isAggressive)
target:registerEvent("criticalHitSystemXHP")
and
Code:
<event class="Creature" method="onAreaCombat" enabled="1" />
right? Also wondering if necessary to do that with this system too by doing
Code:
function Creature:onAreaCombat(tile, isAggressive)
target:registerEvent("criticalHitSystemXHP")
target:registerEvent("PvpBalance")
target:registerEvent("PvpBalance")
Already maked the best anwer aswell, thanks for solving!
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
898
Solutions
21
Reaction score
427
Location
Santiago - Chile
@Nekiro Sorry for bumping, have an error when testing

test_criti.png

Code:
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 skill2 = attacker:getEffectiveSkillLevel(SKILL_CLUB)
    local skill3 = attacker:getEffectiveSkillLevel(SKILL_FIST)
    local skill = attacker:getEffectiveSkillLevel(SKILL_AXE)
    local chance = (skill * 0.1)
    local chance2 = (skill2 * 0.1)
    local chance3 = (skill3 * 0.1)

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

The error was
Code:
        creature:getPosition():sendMagicEffect(config.magic_effect)
To
Code:
        attacker:getPosition():sendMagicEffect(config.magic_effect)

And I registered bad the 🙄
Code:
    local skill = attacker:getEffectiveSkillLevel(SKILL_SWORD)
    local skill2 = attacker:getEffectiveSkillLevel(SKILL_CLUB)
    local skill3 = attacker:getEffectiveSkillLevel(SKILL_FIST)
    local skill = attacker:getEffectiveSkillLevel(SKILL_AXE)
    local chance = (skill * 0.1)
    local chance2 = (skill2 * 0.1)
    local chance3 = (skill3 * 0.1)
 
Last edited:
Top