• 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
 
TFS 1.2 pardon...
I did smth like exori hur and this returns hp but i want it from autoattacks (edited thread title)
 
what is easier to do ofc drain over time would be better

I mean someone hits mob or player for 100 and heal himself for 20 hp (20%) of his hit so drain over hit

once again Becouse my english isnt good enough

player cast spell -> earn buff for x seconds -> hit mob for 100 (for example) -> earn 20% hp of his damage
 
if its easy to do it can be random but if it would be random I would make it like 18-20% of hit
so I think there is no point to make it random
it's definitely not difficult to implement. Please provide all the things you want to be included in this script and I'll fix it shortly or someone else most likely will.
 
thats all I think
spell for x seconds that gives "buff"
during buff player get % of damage done as healing (lifedrain)
% of drain can be random if its easy to do
It would be nice if player have this buff arrow during spell
thats all
 
there is no function like
Code:
function onStatsChange(cid, attacker, type, combat, value)
Thats my problem now
I found this - https://github.com/otland/forgottenserver/wiki/Interface:Creature-Events#onHealthChange

but how can I use it now? duno
also it wont work on mob hp change just on players hp change
Code:
local shoottypes = {
[COMBAT_NONE] = {CONST_ANI_SNOWBALL, CONST_ME_DRAWBLOOD},
[COMBAT_PHYSICALDAMAGE] = {CONST_ANI_LARGEROCK, CONST_ME_DRAWBLOOD},
[COMBAT_ENERGYDAMAGE] = {CONST_ANI_ENERGY, CONST_ME_ENERGYHIT},
[COMBAT_EARTHDAMAGE] = {CONST_ANI_EARTH, CONST_ME_POISONAREA},
[COMBAT_FIREDAMAGE] = {CONST_ANI_FIRE, CONST_ME_TELEPORT},
[COMBAT_UNDEFINEDDAMAGE] = {CONST_ANI_LARGEROCK, CONST_ME_DRAWBLOOD},
[COMBAT_LIFEDRAIN] = {CONST_ANI_INFERNALBOLT, CONST_ME_MAGIC_RED},
[COMBAT_MANADRAIN] = {CONST_ANI_POWERBOLT, CONST_ME_TELEPORT},
[COMBAT_HEALING] = {CONST_ANI_LARGEROCK, CONST_ME_DRAWBLOOD},
[COMBAT_DROWNDAMAGE] = {CONST_ANI_ENERGYBALL, CONST_ME_LOSEENERGY},
[COMBAT_ICEDAMAGE] = {CONST_ANI_ICE, CONST_ME_ICEATTACK},
[COMBAT_HOLYDAMAGE] = {CONST_ANI_HOLY, CONST_ME_HOLYDAMAGE},
[COMBAT_DEATHDAMAGE] = {CONST_ANI_DEATH, CONST_ME_MORTAREA}
}


function onChangeHealth(cid, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
if attacker ~= cid then
if math.random(1, 100) <= 7 then
reflect_dmg = -primaryDamage
reflect_type = primaryType
if primaryType == COMBAT_HEALING then
reflect_dmg = primaryDamage
reflect_type = COMBAT_PHYSICALDAMAGE
end
local t = Monster(cid):getTargetList()
if #t > 0 then
doSendDistanceShoot(getThingPos(cid), t[math.random(1, #t)]:getPosition(), shoottypes[reflect_type][1])
doTargetCombatHealth(cid, t[math.random(1, #t)], reflect_type, reflect_dmg * 0.5, reflect_dmg * 1.5, shoottypes[reflect_type][2])
end
end
end
return true
end

Example of usage by zbizu
 
Code:
local config = {
    spellName = "Vampiric Rage",
    storage = 1401,
    timeStorage = 1402,
    lifeStealPercent = 20, -- Percent of the damage you deal you will get in health.
    }


function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker:getExhaustion(config.storage) <= 0 then
        if origin == ORIGIN_MELEE then
            attacker:addHealth((primaryDamage * (config.lifeStealPercent / 100)))
            doSendMagicEffect(getPlayerPosition(creature), CONST_ME_MAGIC_RED)
            doSendMagicEffect(getPlayerPosition(attacker), CONST_ME_MAGIC_RED)
            attacker:say("+" .. (primaryDamage * (config.lifeStealPercent / 100)) .. " HP", TALKTYPE_MONSTER_SAY)
        
            --doPlayerSendTextMessage(attacker, MESSAGE_STATUS_DEFAULT, "You stole " .. math.ceil(value * (config.lifeStealPercent / 100)) .. " health from " .. getPlayerName(cid) .. "\n" .. config.spellName .. " will last for " .. exhaustion.get(attacker, config.timeStorage) .. " seconds more.")
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType 
end

I did smth like this but now I need to register this event.
In topic with lifesteal there is something like :
Code:
<event type="statschange" name="vampiricTouch" event="script" value="vampiric touch.lua"/>

I guess event type statschange wont work so what should I do?
 
as far as I know, you must register it as a creatureevent(e.g cid) if you want it to work on monsters.

in this script :
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 attacker:isPlayer() then
   if attacker:getExhaustion(config.timeStorage) > 0 then
     if origin == ORIGIN_MELEE then
       --attacker:addHealth((primaryDamage * (config.lifeStealPercent / 100)))
       attacker:addHealth(50)
  doSendMagicEffect(getPlayerPosition(creature), CONST_ME_MAGIC_RED)
  doSendMagicEffect(getPlayerPosition(attacker), CONST_ME_MAGIC_RED)
       attacker:say("+" .. (primaryDamage * (config.lifeStealPercent / 100)) .. " HP", TALKTYPE_MONSTER_SAY)
  
  --doPlayerSendTextMessage(attacker, MESSAGE_STATUS_DEFAULT, "You stole " .. math.ceil(value * (config.lifeStealPercent / 100)) .. " health from " .. getPlayerName(cid) .. "\n" .. config.spellName .. " will last for " .. exhaustion.get(attacker, config.timeStorage) .. " seconds more.")
  end
   else
     return primaryDamage, primaryType, secondaryDamage, secondaryType 
  end
   end
  
end

Im not getting any health, attacker:getExhaustion(config.timeStorage) should return seconds from last spell cast as this function says:
Code:
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end
/\ this is in 050-functions
 
does not work with 1.2
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 = {}

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

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...
 
Last edited:
Back
Top