• 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 takes less damage from magic spells (I have lua, just not working?)

archer32

Member
Joined
Feb 3, 2011
Messages
88
Solutions
1
Reaction score
9
Hey there,

browse the forum and seen some older posts, they seem to work but not really

TFS 1.4 and using OTC

here is my lua spell
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

here is my lua creaturescript script

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_ENERGYDAMAGE then
                primaryDamage = primaryDamage / 2
            end
            if secondaryType == COMBAT_ENERGYDAMAGE then
                secondaryDamage = secondaryDamage / 2
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

i have edited the login.lua and all is well, i cast the spell but it blocks ALL damage, not just energy, it also blocks melee, fire, etc...
 
Last edited:
try.
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and creature:isPlayer() then
        local protectCondition = creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 56)
        if protectCondition then
            if primaryType == COMBAT_ENERGYDAMAGE then
                primaryDamage = primaryDamage / 2
            end
            if secondaryType == COMBAT_ENERGYDAMAGE then
                secondaryDamage = secondaryDamage / 2
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
try.
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and creature:isPlayer() then
        local protectCondition = creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 56)
        if protectCondition then
            if primaryType == COMBAT_ENERGYDAMAGE then
                primaryDamage = primaryDamage / 2
            end
            if secondaryType == COMBAT_ENERGYDAMAGE then
                secondaryDamage = secondaryDamage / 2
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Thank you for the response, it doesn't seem to do anything different though, I have been beating my head against the wall here on this..... hahaha, I am not sure why it is being a pain in the butt
Post automatically merged:

I guess let me walk you through the process of this, maybe I have something setup wrong somewhere.... I wouldn't doubt it

in data\creaturescripts\scripts I have the .lua spell with the function onHealthChange script
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and creature:isPlayer() then
        local protectCondition = creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 56)
        if protectCondition then
            if primaryType == COMBAT_ENERGYDAMAGE then
                primaryDamage = primaryDamage / 2
            end
            if secondaryType == COMBAT_ENERGYDAMAGE then
                secondaryDamage = secondaryDamage / 2
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

in the creaturescripts.xml I have the event type
XML:
<!--Spell Protection-->
    <event type="HealthChange" name="absorbpfm" script="absorbpfm.lua"/>

In the login.lua I have the registered event for the script
Lua:
player:registerEvent("absorbpfm")

then in the spell script I have (data/spells)
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

Do I need to reference this spell script differently? Maybe it is just protecting all damage itself
Post automatically merged:

I fixed this.. I forgot I created as 100% reduce damage script, I forgot to change the ID from 56 since I copy/pasta'd... what a idiot, anywho... thanks
 
Last edited:
Back
Top