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

TFS 1.X+ toggle magicshield

Tibia Demon

Member
Joined
Oct 15, 2020
Messages
80
Solutions
1
Reaction score
16
Location
Tibia
i want to toggle magicshield to all party members and leader too
I made this one but only work for leader and 1 party member but not all if 2 members or 3 or 4 only work for 1
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

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

function onCastSpell(creature, variant)
    local player = Player(creature)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local leader = party:getLeader()
    local members = party:getMembers()
    for i = 1, #members do
    if not creature:getCondition(CONDITION_MANASHIELD) then
        leader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        leader:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
        members[i]:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        members[i]:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
    return creature:addPartyCondition(combat, variant, condition, 120)
    end
    end
    local player = Player(creature)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local leader = party:getLeader()
    local members = party:getMembers()
    for i = 1, #members do
    leader:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    leader:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
    leader:removeCondition(CONDITION_MANASHIELD)
    members[i]:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    members[i]:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
    return members[i]:removeCondition(CONDITION_MANASHIELD)
end
end
 
Solution
error again
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/party/party_magicshield.lua:onCastSpell
data/spells/scripts/party/party_magicshield.lua:26: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: at 0x7ff648efa640
        [C]: in function 'ipairs'
        data/spells/scripts/party/party_magicshield.lua:26: in function <data/spells/scripts/party/party_magicshield.lua:9>
Yeah sorry didn't test.. just assumed it was a tile issue.

This should work.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

local magicShield =...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,699
Solutions
408
Reaction score
3,811
xml same only this one changed
group="healing" by group="support"
prints when spell work
Lua:
Party found.
Creature (Druid Sample) found within spell area.
-> Creature (Druid Sample) is in a party with caster (Sorcerer Sample).
-> Magic Shield Turned [ON]
Creature (Sorcerer Sample) found within spell area.
-> Creature (Sorcerer Sample) is in a party with caster (Sorcerer Sample).
-> Magic Shield Turned [ON]
prints when it don't work
Code:
Party found.
Lua Script Error: [Spell Interface]
data/spells/scripts/party/party_magicshield.lua:onCastSpell
data/spells/scripts/party/party_magicshield.lua:28: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: at 0x7ff648efa640
        [C]: in function 'ipairs'
        data/spells/scripts/party/party_magicshield.lua:28: in function <data/spells/scripts/party/party_magicshield.lua:9>
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

local magicShield = Condition(CONDITION_MANASHIELD)
magicShield:setParameter(CONDITION_PARAM_TICKS, -1)

function onCastSpell(creature, variant)
    local player = Player(creature)
    local party = player:getParty()
    
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end

    local leader = party:getLeader()
    local members = party:getMembers()
    
    local positions = combat:getPositions(creature, variant)
    
    for _, position in ipairs(positions) do
        local tile = Tile(position)
        if tile then
            for _, _creature in ipairs(tile:getCreatures()) do
                if table.contains(members, _creature) or _creature == leader then
                    if not _creature:hasCondition(CONDITION_MANASHIELD) then      
                        _creature:addCondition(magicShield)
                        _creature:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
                    else
                        _creature:removeCondition(CONDITION_MANASHIELD)
                        _creature:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
                    end
                end
            end
        end
    end
    return true
end
 
OP
OP
Tibia Demon

Tibia Demon

Member
Joined
Oct 15, 2020
Messages
80
Solutions
1
Reaction score
16
Location
Tibia
error again
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/party/party_magicshield.lua:onCastSpell
data/spells/scripts/party/party_magicshield.lua:26: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: at 0x7ff648efa640
        [C]: in function 'ipairs'
        data/spells/scripts/party/party_magicshield.lua:26: in function <data/spells/scripts/party/party_magicshield.lua:9>
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,699
Solutions
408
Reaction score
3,811
error again
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/party/party_magicshield.lua:onCastSpell
data/spells/scripts/party/party_magicshield.lua:26: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: at 0x7ff648efa640
        [C]: in function 'ipairs'
        data/spells/scripts/party/party_magicshield.lua:26: in function <data/spells/scripts/party/party_magicshield.lua:9>
Yeah sorry didn't test.. just assumed it was a tile issue.

This should work.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

local magicShield = Condition(CONDITION_MANASHIELD)
magicShield:setParameter(CONDITION_PARAM_TICKS, -1)

function onCastSpell(creature, variant)
    local player = Player(creature)
    local party = player:getParty()
    
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end

    local leader = party:getLeader()
    local members = party:getMembers()
    
    local positions = combat:getPositions(creature, variant)
    
    for _, position in ipairs(positions) do
        local tileCreatures = Tile(position):getCreatures()
        if tileCreatures then
            for _, _creature in ipairs(tileCreatures) do
                if table.contains(members, _creature) or _creature == leader then
                    if not _creature:hasCondition(CONDITION_MANASHIELD) then      
                        _creature:addCondition(magicShield)
                        _creature:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
                    else
                        _creature:removeCondition(CONDITION_MANASHIELD)
                        _creature:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
                    end
                end
            end
        end
    end
    return true
end
 
Solution
Top