• 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 Magic Shield Toggle

Heroid

Active Member
Joined
Mar 7, 2011
Messages
331
Solutions
11
Reaction score
34
I need some help making a spell that will toggle Magic Shield on/off.
This is what I've got so far but it's really messy and I don't really know what I'm doing no more because I've been trying to get it to work by doing all kind of different things.
TFS 1.2
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_TICKS, 9999)
condition:setParameter(CONDITION_PARAM_SUBID, 103)
combat:setCondition(condition)

function onCastSpell(creature, variant)
    local player = creature:getPlayer()
    local pos = player:getPosition()
 
    if not player:getCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT, 103) then
        player:addCondition(condition)
        pos:sendMagicEffect(13)
        player:say("[ON]", TALKTYPE_MONSTER_SAY)
    elseif player:getCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT, 103) then
        player:removeCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT, 103)
        pos:sendMagicEffect(14)
        player:say("[OFF]", TALKTYPE_MONSTER_SAY)
end
return true
end
 
Last edited:
Solution
try this.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
combat:setCondition(condition)

function onCastSpell(creature, var)
    local pos = creature:getPosition()
    if not creature:getCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT) then
        pos:sendMagicEffect(13)
        creature:say("[ON]", TALKTYPE_MONSTER_SAY)
        return combat:execute(creature, var)
    end
    pos:sendMagicEffect(14)
    creature:say("[OFF]", TALKTYPE_MONSTER_SAY)
    return creature:removeCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
end
try this.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
combat:setCondition(condition)

function onCastSpell(creature, var)
    local pos = creature:getPosition()
    if not creature:getCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT) then
        pos:sendMagicEffect(13)
        creature:say("[ON]", TALKTYPE_MONSTER_SAY)
        return combat:execute(creature, var)
    end
    pos:sendMagicEffect(14)
    creature:say("[OFF]", TALKTYPE_MONSTER_SAY)
    return creature:removeCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
end
 
Solution
If you try with -1 in ticks, make sure the mana shield actually works.

In TFS 1.3 (atleast for me) the mana shield icon goes on and off just fine but it doesnt have any effect (still lose HP) . I just set a high amount of ticks to make it "forever".
 
If you try with -1 in ticks, make sure the mana shield actually works.

In TFS 1.3 (atleast for me) the mana shield icon goes on and off just fine but it doesnt have any effect (still lose HP) . I just set a high amount of ticks to make it "forever".
-1 = forever.
At least that's how it's been scripted in past tfs versions, and I don't see why they would change it otherwise.
 
try this.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
combat:setCondition(condition)

function onCastSpell(creature, var)
    local pos = creature:getPosition()
    if not creature:getCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT) then
        pos:sendMagicEffect(13)
        creature:say("[ON]", TALKTYPE_MONSTER_SAY)
        return combat:execute(creature, var)
    end
    pos:sendMagicEffect(14)
    creature:say("[OFF]", TALKTYPE_MONSTER_SAY)
    return creature:removeCondition(CONDITION_MANASHIELD, CONDITIONID_DEFAULT)
end
Works just as I want, thanks!
But as @BahamutxD said, -1 doesn't work as infinite for me either and keeps returning the damage to health instead of mana. Changing it to a high number made it work though.
 
-1 works for all conditions but manashield.
Tested on different versions, It always happens.

Probably a source problem? dunno.. Just set it to 24h.. its rare for someone to stay more than 24hours online without reloging even once.
 
Back
Top