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

Lua Spell that reduces damage taken in 50%

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
TFS 1.3

Hello guys, I would like a spell that when the player cast, he receives 50% less damage to fire atacks for 5 seconds.
 
Solution
Thanks both of you, I will test it now.
Post automatically merged:

It did not work. I change everything you said, and no error appear on the TFS except this:



But then I tried the original script and also doesnt work and appear this error on TFS:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local protect = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
protect:setParameter(CONDITION_PARAM_SUBID, 56)
protect:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
protect:setParameter(CONDITION_PARAM_TICKS, 5 * 1000)
combat:addCondition(protect)

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
Lua:
function...
oww, nice. But how do I edit to be just fire and last for 5 seconds?
change this line for the amount of seconds, in the protection spell
protect:setParameter(CONDITION_PARAM_TICKS, 10 * 1000)
for the other, use this.
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and creature:isPlayer() then
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 56) then
            if primaryType == COMBAT_FIREDAMAGE then
                primaryDamage = primaryDamage / 2
            end
            if secondaryType == COMBAT_FIREDAMAGE then
                secondaryDamage = secondaryDamage / 2
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Thanks both of you, I will test it now.
Post automatically merged:

It did not work. I change everything you said, and no error appear on the TFS except this:

[Warning] Function Combat.setCondition was renamed to Combat.addCondition and will be removed in the future

But then I tried the original script and also doesnt work and appear this error on TFS:

[Warning] Function Combat.setCondition was renamed to Combat.addCondition and will be removed in the future
[Warning - Event::checkScript] Event onHealthChange not found. scripts/blockfire.lua
 
Last edited:
Thanks both of you, I will test it now.
Post automatically merged:

It did not work. I change everything you said, and no error appear on the TFS except this:



But then I tried the original script and also doesnt work and appear this error on TFS:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local protect = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
protect:setParameter(CONDITION_PARAM_SUBID, 56)
protect:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
protect:setParameter(CONDITION_PARAM_TICKS, 5 * 1000)
combat:addCondition(protect)

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and creature:isPlayer() then
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 56) then
            if primaryType == COMBAT_FIREDAMAGE then
                primaryDamage = primaryDamage / 2
            end
            if secondaryType == COMBAT_FIREDAMAGE then
                secondaryDamage = secondaryDamage / 2
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Solution
No erros on TFS, but it doesn't work. It shows the effect but I still get normal damage. I put "primaryDamage / 100" and "secondaryDamage / 100" just to see if I would get lower damage, but it's just normal damage. Any ideas to what might be going wrong?
 
No erros on TFS, but it doesn't work. It shows the effect but I still get normal damage. I put "primaryDamage / 100" and "secondaryDamage / 100" just to see if I would get lower damage, but it's just normal damage. Any ideas to what might be going wrong?
Try it with prints.

(and make sure you've registered the script in creaturescripts.xml as well as login.lua)
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
	print("--------")
	print("script start")
    if creature and creature:isPlayer() then
		print("is player")
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 56) then
			print("condition found")
            if primaryType == COMBAT_FIREDAMAGE then
				print("Primary damage type is FIRE.. reducing damage")
				print("Initial damage value: " .. primaryDamage)
                primaryDamage = primaryDamage / 2
				print("Modified damage value: " .. primaryDamage)
            end
            if secondaryType == COMBAT_FIREDAMAGE then
				print("Secondary damage type is FIRE.. reducing damage")
				print("Initial damage value: " .. secondaryDamage)
                secondaryDamage = secondaryDamage / 2
				print("Modified damage value: " .. secondaryDamage)
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
At creature script:
<event type="healthchange" name="blockfire" script="blockfire.lua"/>

Tested with the print:

--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
--------
script start
is player
 
At creature script:


Tested with the print:
When you are using the spell, are you getting the buff?
Untitled.png

-- edit
I'm asking because I tested the script myself and it's working.
So I'm wondering if the spell is not applying to you properly.

Assuming it's not working, can you post your spell.xml line for your spell?
 
Last edited:
I am not receiving the buff.

1611936585305.png

spell:

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local protect = Condition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT)
protect:setParameter(CONDITION_PARAM_SUBID, 56)
protect:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
protect:setParameter(CONDITION_PARAM_TICKS, 50 * 1000)
combat:addCondition(protect)

function onCastSpell(creature, var)
return combat:execute(creature, var)
end

Spell tag:

<instant group="attack" spellid="212" name="teste block" words="teste block" level="1" mana="10" direction="1" cooldown="8000" groupcooldown="2000" needlearn="0" script="support/blockfire.lua">
<vocation name="knight" />
</instant>
 
I am not receiving the buff.

View attachment 54334

spell:



Spell tag:
change your line, for this one
XML:
<instant group="attack" spellid="212" name="teste block" words="teste block" level="1" mana="10" selftarget="1" cooldown="8000" groupcooldown="2000" needlearn="0" script="support/blockfire.lua">
<vocation name="knight" />
</instant>
 
OMG, my bad. It works perfectly now. Felling so stupid for missing that error in the tag.
Thanks so much
Post automatically merged:

How do I make the caster be immobilized while the effect is active?
 
Last edited:
Back
Top