• 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+ Full attack --balanced-- full defense in event/creature.lua script

tuduras

Well-Known Member
Joined
Jun 4, 2017
Messages
340
Solutions
2
Reaction score
58
when set full attack more dmg , when full defense less damage
Hello I added code to data/events/script/creature

LUA:
function Creature:onHealthChange(attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and attacker:isPlayer() then
        local mode = attacker:getFightMode()
        local multiplier = 1.0

        if mode == FIGHTMODE_ATTACK then
            multiplier = 1.5
        elseif mode == FIGHTMODE_DEFENSE then
            multiplier = 0.5
        end

        if multiplier ~= 1.0 then
            -- IMPORTANT: In TFS 1.x, damage values are negative (e.g., -50),
            -- so math.floor scales negative values downward more effectively.
            primaryDamage = math.floor(primaryDamage * multiplier)
            secondaryDamage = math.floor(secondaryDamage * multiplier)

            if mode == FIGHTMODE_ATTACK and math.random(1, 100) <= 20 then
                self:say("BOOM!", TALKTYPE_MONSTER_SAY)
                self:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            end
        end
    end

    -- KEY ELEMENT: You must return these values to the engine!
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

-- 2. HEALING AND DEFENSE MODIFICATION (When the player is the target)
if self:isPlayer() then
    local mode = self:getFightMode()

    -- Healing bonus while on Full Defense (primaryDamage > 0)
    if mode == FIGHTMODE_DEFENSE and primaryDamage > 0 then
        primaryDamage = math.ceil(primaryDamage * 1.25) -- +25% healing
        if math.random(1, 100) <= 30 then
            self:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end
    end

    -- BLOCK! effect while on Full Defense (primaryDamage < 0)
    if mode == FIGHTMODE_DEFENSE and primaryDamage < 0 then
        if math.random(1, 100) <= 25 then
            self:say("BLOCK!", TALKTYPE_MONSTER_SAY)
            self:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        end
    end
end

-- Standard engine handling
if hasEventCallback(EVENT_CALLBACK_ONHEALTHCHANGE) then
    return EventCallback(EVENT_CALLBACK_ONHEALTHCHANGE, self, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
else
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

and works only more healing when put full defense.

Can someone knows how to do it to work?
Maybe add somethink in data/scripts?
Best regards!
 
Solution
Talked with him on discord, tested and working

LUA:
local fightModeCombat = CreatureEvent("FightModeCombat")

function fightModeCombat.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType == COMBAT_HEALING or secondaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker and attacker:isPlayer() then
        if attacker:getFightMode() == 1 then
            primaryDamage = math.ceil(primaryDamage * 1.1)
            secondaryDamage = math.ceil(secondaryDamage * 1.1)
        end
    end

    if creature and creature:isPlayer() then
        if creature:getFightMode() == 3 then
            primaryDamage...
Talked with him on discord, tested and working

LUA:
local fightModeCombat = CreatureEvent("FightModeCombat")

function fightModeCombat.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType == COMBAT_HEALING or secondaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker and attacker:isPlayer() then
        if attacker:getFightMode() == 1 then
            primaryDamage = math.ceil(primaryDamage * 1.1)
            secondaryDamage = math.ceil(secondaryDamage * 1.1)
        end
    end

    if creature and creature:isPlayer() then
        if creature:getFightMode() == 3 then
            primaryDamage = math.floor(primaryDamage * 0.9)
            secondaryDamage = math.floor(secondaryDamage * 0.9)
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

fightModeCombat:register()
------------------------------------------------------------------------------------------------------------------------
local fightModeMana = CreatureEvent("FightModeMana")

function fightModeMana.onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType == COMBAT_HEALING or secondaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker and attacker:isPlayer() then
        if attacker:getFightMode() == 1 then
            primaryDamage = math.ceil(primaryDamage * 1.1)
            secondaryDamage = math.ceil(secondaryDamage * 1.1)
        end
    end

    if creature and creature:isPlayer() then
        if creature:getFightMode() == 3 then
            primaryDamage = math.floor(primaryDamage * 0.9)
            secondaryDamage = math.floor(secondaryDamage * 0.9)
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

fightModeMana:register()
------------------------------------------------------------------------------------------------------------------------
local ec = EventCallback

function ec.onTargetCombat(creature, target)
    target:registerEvent("FightModeCombat")
    target:registerEvent("FightModeMana")
    return RETURNVALUE_NOERROR
end

ec:register()
------------------------------------------------------------------------------------------------------------------------
local fightModeLogin = CreatureEvent("FightModeLogin")

function fightModeLogin.onLogin(player)
    player:registerEvent("FightModeCombat")
    player:registerEvent("FightModeMana")
    return true
end

fightModeLogin:register()
------------------------------------------------------------------------------------------------------------------------
 
Solution
Back
Top