• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[TFS 1.x]CRITICAL SYSTEM. How to fix it?

Kibako

New Member
Joined
Feb 9, 2016
Messages
1
Reaction score
0
Hello. I have a problem with this script.

It works on a human but doesn't work on monsters. I want it to work also on mosnters.


Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local player = Player(attacker)
    if not player then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    local multiplier = 100
    if (attacker:getSkillLevel(axe)) >= math.random (1, 100)  and isPlayer(attacker) then
        if isInArray({ORIGIN_MELEE, ORIGIN_RANGED}, origin) and primaryType ~= COMBAT_HEALING then
            primaryDamage = math.ceil(primaryDamage*(multiplier))
            attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
        end
        end
   
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
As Marcelo metioned, you have to register it to the monsters.

Either you do that through the monster xml files or just use monster script interface and do something like this:
Code:
function onCreatureAppear(self, creature)
    if self == creature then
        self:registerEvent("HealthChange")
    end
end


And i would edit your code to something like this:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker:isPlayer() and isInArray({ORIGIN_MELEE, ORIGIN_RANGED}, origin) then
        local multiplier = 100
        if attacker:getSkillLevel(axe) >= math.random (100) then
            primaryDamage = math.ceil(primaryDamage * multiplier)
            attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Last edited:
I just gave it a try: (Not yours printer)
21:51 Knight Test loses 27 hitpoints due to your attack.
21:51 Knight Test loses 1 hitpoint due to your attack.
21:51 Knight Test loses 759 hitpoints due to your attack.
21:51 Warning! The murder of Knight Test was not justified.

I think I am more chocked than Knight Test is. :eek:

Their must be an easier way to simply apply it to all targets/healthchanges within the code.


Kind Regards,
Eldin.
 
Last edited:
Back
Top