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 OnHealthChangeSure 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...
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
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.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
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.
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
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
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
Yes I did itYou have to register the event on the target.
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
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
<event type="healthchange" name="vampiric" script="berserker/vampiric.lua"/>
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?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
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
registered it on login.lua and in creaturescripts, how can I register it on the monster?Are you sure that you register it on the monster and not on the player.