• 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.2 Timed spell with life drain?

Verrine

Member
Joined
Mar 2, 2016
Messages
117
Reaction score
7
Hi I need spell that will return ammount of HP after cast for x seconds or just x hits
 
Sure it does...
Code:
local combat = Combat()

local c = {
    spellName = "Vampiric Touch", -- The spells name. Not the words you say to cast it.
    storage = 1401,
    timeStorage = 1402,
    cooldown = 240, -- Cooldown on the spell in seconds
    skillTime = 180, -- For this long the skill will be activated.
}

local exhaustion = {}

local function exhaustion.get(cid, storage)
    local player = Player(cid)
    if player then
        return player:getStorageValue(storage)
    end
end

local function exhaustion.set(cid, storage, value)
    local player = Player(cid)
    if player then
        player:setStorageValue(storage, value)
    end
end

function onCastSpell(creature, variant)

    if creature:isPlayer() then
        local cid = creature:getId()
        if not exhaustion.get(cid, c.storage) then
            exhaustion.set(cid, c.storage, c.cooldown)
            exhaustion.set(cid, c.timeStorage, c.skillTime)
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            creature:say("VAMPIRIC TOUCH!", TALKTYPE_MONSTER_SAY)
        else
            creature:sendCancelMessage(c.spellName .. " is still on " .. exhaustion.get(cid, c.storage) .. " seconds cooldown!")
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
        combat:execute(creature, variant)
    end
    return true
end

The rest is up to you... learn the language...
I did it yesterday, just problem with script, functions with exhaustion I have in libs-050.lua and spell just work but main problem that I posted here ->> https://otland.net/threads/vampiric-spell-for-tfs-1-2-timed.242593/#post-2349575 is only function OnHealthChange ;)
 
Code:
local config = {
    spellName = "Vampiric Rage",
    spellStorage = 1000,
    lifeStealPercent = 10
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker:getStorageValue(config.spellStorage) >= os.time() and primaryType == COMBAT_PHYSICALDAMAGE and origin == ORIGIN_MELEE then
        local lifeSteal = ((primaryDamage * config.lifeStealPercent) / 100)
        if doTargetCombatHealth(0, attacker, COMBAT_HEALING, lifeSteal, lifeSteal, CONST_ME_MAGIC_BLUE) then
            attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("You stole %d hitpoints from %s\n%s will last for %d seconds more."):format(lifeSteal, creature:getName(), config.spellName, attacker:getStorageValue(config.spellStorage) - os.time())
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
I did it yesterday, just problem with script, functions with exhaustion I have in libs-050.lua and spell just work but main problem that I posted here ->> https://otland.net/threads/vampiric-spell-for-tfs-1-2-timed.242593/#post-2349575 is only function OnHealthChange ;)
The problem isn't the language or the framework, the problem is you don't know how to program, which is essential to writing scripts.. you need to understand the logic and execution of a script in order to effectively write one.

What would you rather do, waste days like you have been doing on the support boards looking for a solution or a few minutes of your own time writing/editing or modifying a script, we are not going to be around forever, eventually you will need to know how to do things on your own.

Copying and pasting other people's work or code will only get you so far because you will still be at square one, with no knowledge... changing values and or fragments of code around does not make you an effective developer or programmer.
 
Code:
local config = {
    spellName = "Vampiric Rage",
    spellStorage = 1000,
    lifeStealPercent = 10
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker:getStorageValue(config.spellStorage) >= os.time() and primaryType == COMBAT_PHYSICALDAMAGE and origin == ORIGIN_MELEE then
        local lifeSteal = ((primaryDamage * config.lifeStealPercent) / 100)
        if doTargetCombatHealth(0, attacker, COMBAT_HEALING, lifeSteal, lifeSteal, CONST_ME_MAGIC_BLUE) then
            attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("You stole %d hitpoints from %s\n%s will last for %d seconds more."):format(lifeSteal, creature:getName(), config.spellName, attacker:getStorageValue(config.spellStorage) - os.time())
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

nothing, Im not getting anything, even when I deleted storages for test it I have no idea why this script doesnt react to my attacks.

There is one thing that I can miss. I did dualwielding on char that I testing it. Could it be a problem?

The problem isn't the language or the framework, the problem is you don't know how to program, which is essential to writing scripts.. you need to understand the logic and execution of a script in order to effectively write one.

What would you rather do, waste days like you have been doing on the support boards looking for a solution or a few minutes of your own time writing/editing or modifying a script, we are not going to be around forever, eventually you will need to know how to do things on your own.

Copying and pasting other people's work or code will only get you so far because you will still be at square one, with no knowledge... changing values and or fragments of code around does not make you an effective developer or programmer.

I got this, but I have read whole of this post https://otland.net/threads/tfs-1-0-critical-hit-permanent.212908/#post-2139419 and nothing. I cant get smth like this:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    attacker:sendTextMessage(MESSAGE_EVENT_ORANGE, "Attacker: " .. attacker:getName() .. "\n")
    attacker:sendTextMessage(MESSAGE_EVENT_ORANGE, "Victim: " .. creature:getName() .. "\n")

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
becouse when I with my character attack mob nothing happen just NOTHING only when monster attack me Im getting message.
For my own understand I did smth like this:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    attacker:sendTextMessage(MESSAGE_EVENT_ORANGE, "Attacker: " .. attacker:getName() .. "\n")
    attacker:sendTextMessage(MESSAGE_EVENT_ORANGE, "Victim: " .. creature:getName() .. "\n")

    creature:sendTextMessage(MESSAGE_EVENT_ORANGE, "Attacker: " .. attacker:getName() .. "\n")
    creature:sendTextMessage(MESSAGE_EVENT_ORANGE, "Victim: " .. creature:getName() .. "\n")
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
And still nothing, just nothing my attacks does not print anything, anything. Its wierd for me...
changed creature for attacker and vice versa. with 2 lines or 4 just sometimes getting errors in console bcs script want to print message to monster ohh cmon im a little frustrated of this situation. mby this dualwielding is a problem?


this code also wont return to me any HP
PHP:
local config = {
  spellName = "Vampiric Rage",
  storage = 1401,
  timeStorage = 1402,
  lifeStealPercent = 50, -- Percent of the damage you deal you will get in health.
  }

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if primaryType == COMBAT_PHYSICALDAMAGE and origin == ORIGIN_MELEE then
        local lifeSteal = ((primaryDamage * config.lifeStealPercent) / 100)
        if doTargetCombatHealth(0, attacker, COMBAT_HEALING, lifeSteal, lifeSteal, CONST_ME_MAGIC_BLUE) then
            attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("You stole %d hitpoints from %s\n%s will last for %d seconds more."):format(lifeSteal, creature:getName(), config.spellName))
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Tested with knight also so dualwielding wont be problem

meh ill try to reset whole server mby this would help
 
Last edited:
You have to register the event on the target.
Yes I did it
It heals me now when monsters attacking me instead taking my HP
When I attack monsters nothing happens
I think problem was that I used in past on health change function for resists
Also monsters draining life from me
PHP:
local resists = {

{120, COMBAT_DEATHDAMAGE, 20},
{121, COMBAT_EARTHDAMAGE, 20},
{122, COMBAT_ENERGYDAMAGE, 20},
{123, COMBAT_FIREDAMAGE, 20},
{124, COMBAT_ICEDAMAGE, 20},
{125, COMBAT_PHYSICALDAMAG, 20}

} -- {subId, damageType, resistancePercent}

local config = {
    spellName = "Vampiric Rage",
    storage = 1401,
    timeStorage = 1402,
    lifeStealPercent = 50, -- Percent of the damage you deal you will get in health.
    }
  
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
   end
    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    for i = 1, #resists do
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, resists[i][1]) then
            if primaryType == resists[i][2] then
                primaryDamage = (primaryDamage - (primaryDamage * (resists[i][3] / 100)))
            end
            if secondaryType == resists[i][2] then
                secondaryDamage = (secondaryDamage - (secondaryDamage * (resists[i][3] / 100)))
            end
        end
    end
    if not attacker or not attacker:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if primaryType == COMBAT_PHYSICALDAMAGE and origin == ORIGIN_MELEE then
        local lifeSteal = ((primaryDamage * config.lifeStealPercent) / 100)
        if doTargetCombatHealth(0, attacker, COMBAT_HEALING, lifeSteal, lifeSteal, CONST_ME_MAGIC_BLUE) then
            attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("You stole %d hitpoints from %s\n%s will last for %d seconds more."))
        end
    end

    return    primaryDamage, primaryType, secondaryDamage, secondaryType
end

I moved the code to my resist.lua and something happen now (becouse I can use function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) only once?)
 
Last edited:
when I made once again new script with this code:
Code:
local config = {
    spellName = "Vampiric Rage",
    storage = 1401,
    timeStorage = 1402,
    lifeStealPercent = 50, -- Percent of the damage you deal you will get in health.
    }


function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    --if primaryType == COMBAT_PHYSICALDAMAGE then
        local lifeSteal = ((primaryDamage * config.lifeStealPercent) / 100)
        doTargetCombatHealth(0, attacker, COMBAT_HEALING, lifeSteal, lifeSteal, CONST_ME_MAGIC_BLUE)
        attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("You stole %d hitpoints from %s\n%s will last for %d seconds more."))
        --end


    --return primaryDamage, primaryType, secondaryDamage, secondaryType
    return true
end
registered it also as
Code:
<event type="healthchange" name="vampiric" script="berserker/vampiric.lua"/>

monsters attacking me getting hp but when Im hitting them I have nothing.
I know that I need to make If to restrict this function for players with storage BUT this is easier way to test this when it just work all the time so I dont need to wait for cooldowns etc.
Im just asking now why this function execute only on monsters attacking players?
Why this function does not execute with players attacking monsters?
 
Just make a talkaction script to setstorage value(s), if you already don't have one. Then just add an if getStorageValue(....) then bla bla to test it
 
Just make a talkaction script to setstorage value(s), if you already don't have one. Then just add an if getStorageValue(....) then bla bla to test it
okay but You think it will help me alot? If script does not want to execute on my attacks even without restrict? so what will storage change? Ill get it and problem will stay, function dont want to react for my attacks on monsters. Am I wrong?

anyway that what @Printer posted should work, I wanted to do it in different way but ok I thought thats my mistake, now I see that I cant just do it on my datapack/TFS engine mby I need to compile fresh version and check it, srsly duno where is the problem...

In act of desperate I just pasted this:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if math.random(100) <= 50 then
        if origin == ORIGIN_MELEE then
            creature:say("SKULLBASH!", TALKTYPE_MONSTER_SAY)
        elseif origin == ORIGIN_RANGED then
            creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
        end
        return primaryDamage * 10, primaryType, secondaryDamage, secondaryType
    end
 
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
and what? CRITICAL HITS WORK FOR MONSTERS ATTACKING ME
I can attack them for 100000 years and nothing special happens god damn
 
Last edited:
Back
Top