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

Help - Critical System bug

Wanheda

New Member
Joined
Feb 17, 2016
Messages
44
Solutions
2
Reaction score
4
hi guys, i have a problem in a Critical HIT system on my server. TFS 1.2
I was testing it in-game , when i realized that the character was not taking hit monsters , not losing life, only mana (with utamovita ) .
I removed the line of Creaturescripts.xml and returned to normal functioning .

<event type="healthchange" name="CriticalSystem" script="critical.lua"/>

Script:


function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not isPlayer(attacker) then return false end
if (attacker:getCriticalLevel() * 3) >= math.random (0, 1000) then
if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
primaryDamage = primaryDamage + math.ceil(primaryDamage * CRITICAL.PERCENT)
attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end


I do not know if the problem is that script or maybe it's something else, someone help me ?
 
It could be a little more specific ?


put it this way ?

Code:
if not isPlayer(attacker) then 
return false 
end

or delete?
 
It could be a little more specific ?


put it this way ?

Code:
if not isPlayer(attacker) then
return false
end

or delete?
Lua is pretty easy to read, this code says.
If the attacker is not a player, do absolutely nothing and return false, it means don't execute the code at all if a monster attacks the creature.
Creature being player or monster.
 
hi codex , could not, already tried several things , but i could not , (I'm not expert in .lua ) will have to remove the system, perhaps not this script .

Thanks for your help. : D
 
hi codex , could not, already tried several things , but i could not , (I'm not expert in .lua ) will have to remove the system, perhaps not this script .

Thanks for your help. : D
You don't have to remove the script, you just have to remove the code
Code:
if not isPlayer(attacker) then
return false
end
If you want a monster to do damage to the player, however monsters don't have levels (not by default atleast), you will need to modify the script so it works with monsters.
 
Something like this
Code:
    function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
        if attacker:isPlayer() then
            if (attacker:getCriticalLevel() * 3) >= math.random (0, 1000) then
                if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
                    primaryDamage = primaryDamage + math.ceil(primaryDamage * CRITICAL.PERCENT)
                    attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
                    creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
                end
            end
        end
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
@Codex NG ,
worked perfectly , but as you said, does not work on monsters. but the way you gave me is already very good. thank you so much. =D

5VzzGRA.png


@edit

@Codex NG

I edited the post to say that is giving the following error when stepping on fire field and take damage .


is giving the following error stepping on fire field:

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/critical.lua:onHealthChange
data/creaturescripts/scripts/critical.lua:2: attempt to index local 'attacker' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/critical.lua:2: in function <data/creaturescripts/scripts/critical.lua:1>


and this error when I use a fire sword:

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/critical.lua:onHealthChange
data/creaturescripts/scripts/critical.lua:2: attempt to call local 'attacker' (a userdata value)
stack traceback:
        [C]: in function 'attacker'
        data/creaturescripts/scripts/critical.lua:2: in function <data/creaturescripts/scripts/critical.lua:1>


I'm thinking that this script has no way . : /
 
Last edited:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker then -- is attacker not nil?
        if attacker:isPlayer() then -- is it a player attacking you?
            if (attacker:getCriticalLevel() * 3) >= math.random (0, 1000) then
                if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
                    primaryDamage = primaryDamage + math.ceil(primaryDamage * CRITICAL.PERCENT)
                    attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
                    creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Back
Top