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

Lua Better way to prevent a monster from dying

  • Thread starter Thread starter Evil Puncker
  • Start date Start date
E

Evil Puncker

Guest
I was thinking about doing a target dummy like in the old days, but was not able to figure out a nice way to do it, any ideas?

main points:
  • it should have full hp, but once being attacked it should not die but stay with 1 HP
  • it can still heal itself with it spells
  • it should still display the full damage number even if it have only 1 HP

I have tried both onPrepareDeath and onHealthChange but no luck 😝

TFS 1.3
 
Solution
2efe8fc0290705a9f10b33481be0000c.gif

I never used revscripts yet but you can adapt this to your revscripts style:

LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- if it's healing then allow it
    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType
    end

    -- if not attacker or attacker is not player then cancel
    if not attacker or not attacker:isPlayer() then
        return
    end

    local health = creature:getHealth()
    local incomingDamage = primaryDamage + secondaryDamage

    -- if health is > 1 and health - incomingDamage > 1 then return like normal
    if health > 1 and (health -...
it should still display the full damage number even if it have only 1 HP
onHealthChange if it's anything like onStatsChange from 0.3.7, only shows the final damage about to be applied to the creature, so if it only has 1 hp remaining, only 1 hp is the damage.. so you'd want to keep the creature at full life, instead of 1 hp.

I'd just leave it at full life, and heal it back the damage it took with an addevent with a 0 timer. lol

LUA:
local function healMonster(creature, value)
    local monster = Monster(creature)
    if monster then
        monster:addHealth(value)
    end
    return true
end

function creatureevent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isMonster() and attacker:isPlayer() then
        if creature:getName():lower() == "target dummy" then
            addEvent(healMonster, 0, creature:getId())
            return true
        end
    end
    return true
end
 
2efe8fc0290705a9f10b33481be0000c.gif

I never used revscripts yet but you can adapt this to your revscripts style:

LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- if it's healing then allow it
    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType
    end

    -- if not attacker or attacker is not player then cancel
    if not attacker or not attacker:isPlayer() then
        return
    end

    local health = creature:getHealth()
    local incomingDamage = primaryDamage + secondaryDamage

    -- if health is > 1 and health - incomingDamage > 1 then return like normal
    if health > 1 and (health - incomingDamage > 1) then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    -- otherswise we return our own message
    -- You can improve the script by editing the textcolor based off the type of attack (energy/fire/physical), right now it's just default red
    creature:addHealth(-health + 1)
    attacker:sendTextMessage(MESSAGE_EXPERIENCE, "You have dealt " .. incomingDamage .. " damage to the " .. creature:getName() .. ".", creature:getPosition(), incomingDamage, TEXTCOLOR_RED)
    return
end
 
Solution
I clearly don't have any experience with 1.0+. xD
I'm 90% sure I'm gonna install tfs 1.3 and start learning the new engines, cuz honestly I just feel bad for giving crappy advice.
I was going to use @imkingran script but somehow it was too hacky xD then your script gave me an idea, so I ended up making the monster to have 100.000/1.000.000 hp, and made a heal spell that will set his hp back to 100k every now and then, so he will always have "black" hp and never dies :P and yes, download 1.3 its kinda funny to play with
 
Back
Top