if its easy to do it can be random but if it would be random I would make it like 18-20% of hitshould the drain be random, e.g 1-20% of the hit or constant?
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.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
does not work with 1.2Try this:
function onStatsChange(cid, attacker, type, combat, value)
there is no function likeThats my problem nowCode:function onStatsChange(cid, attacker, type, combat, value)
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
maybe if u search a lil bit harderthere is no function likeThats my problem nowCode:function onStatsChange(cid, attacker, type, combat, value)
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
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
<event type="statschange" name="vampiricTouch" event="script" value="vampiric touch.lua"/>
as far as I know, you must register it as a creatureevent(e.g cid) if you want it to work on monsters.
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
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
ok in my TFS this function only works for mobs, players attacks doesnt matters when I removed ifs and just left attacker:say and magic efests also healing only mobs heal themself when I attack monster nothing happensmaybe if u search a lil bit harder
https://otland.net/threads/tfs-1-0-critical-hit-permanent.212908/#post-2139419
Sure it does...does not work with 1.2
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