• 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

T

Tibia Demon

Guest
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 =...
try

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(player, variant)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local partyLeader = party:getLeader()
    local pt = party:getMembers()
    for _, member in pairs(pt) do
        if member:getCondition(CONDITION_MANASHIELD) or partyLeader:getCondition(CONDITION_MANASHIELD) then
            partyLeader:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            partyLeader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            partyLeader:removeCondition(CONDITION_MANASHIELD)
            member:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            member:removeCondition(CONDITION_MANASHIELD)
        else
            partyLeader:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            partyLeader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            partyLeader:addCondition(condition)
            member:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            member:addCondition(condition)
        end
    end
end

keep in mind if a party member has utamo befor using that spell, it will remove his utamo ;D
 
try

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(player, variant)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local partyLeader = party:getLeader()
    local pt = party:getMembers()
    for _, member in pairs(pt) do
        if member:getCondition(CONDITION_MANASHIELD) or partyLeader:getCondition(CONDITION_MANASHIELD) then
            partyLeader:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            partyLeader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            partyLeader:removeCondition(CONDITION_MANASHIELD)
            member:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            member:removeCondition(CONDITION_MANASHIELD)
        else
            partyLeader:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            partyLeader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            partyLeader:addCondition(condition)
            member:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            member:addCondition(condition)
        end
    end
end

keep in mind if a party member has utamo befor using that spell, it will remove his utamo ;D

i tried on 3 mc all has no utamo and it is not working well.
1 said Magic Shield [OFF] even he had no magic shield
2 said Magic Shield [ON] but 1 of them only got magic shield condition added
 
i tried on 3 mc all has no utamo and it is not working well.
1 said Magic Shield [OFF] even he had no magic shield
2 said Magic Shield [ON] but 1 of them only got magic shield condition added
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)

function onCastSpell(player, variant)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local partyLeader = party:getLeader()
    local pt = party:getMembers()
    for _, member in pairs(pt) do
        if member:getCondition(CONDITION_MANASHIELD) then
            partyLeader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            partyLeader:removeCondition(CONDITION_MANASHIELD)
            member:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            member:removeCondition(CONDITION_MANASHIELD)
        elseif not member:getCondition(CONDITION_MANASHIELD) then
            partyLeader:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            partyLeader:addCondition(condition)
            member:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            member:addCondition(condition)
        end
    end
end
 
this one work but i can use it even if no party member in the screen or AREA_CIRCLE3X3 not like the other party spells when i try to use the other party spells like this
it don't work if there is no party member in AREA_CIRCLE3X3 i think because of this function addPartyCondition
 
i was trying to add this to check party members in area and how many but can not make it work
Lua:
    -- find all party members and confirm they are within an acceptable distance
    local members = party:getMembers()
    table.insert(members, party:getLeader())
    local casterPos, memberPos = caster:getPosition()
    for i = #members, 1, -1 do
        if caster ~= members[i] then
            memberPos = members[i]:getPosition()
            if casterPos:getDistance(memberPos) > distance.tiles then
                table.remove(members, i)
            elseif memberPos.z > casterPos.z + distance.floors or memberPos.z < casterPos.z - distance.floors then
                table.remove(members, i)
            end
        end
    end
    if #members < 2 then
            caster:sendCancelMessage("Party currently has fewer then 2 players in range.")
        return false
    end
 
I've kinda ignored this thread, because I don't understand what you want to happen, exactly.

Is it supposed to target all party members within range.. and swap their current magic shield status?

So if it's off, turn it on, and if it's on, turn it off?

And what do you do about the energy ring, that provides magic shield?
 
Is it supposed to target all party members within range.. and swap their current magic shield status?

So if it's off, turn it on, and if it's on, turn it off?
exactly that is what i want to do the scripts posted in this thread works but it is not checking if party members within range. i need it to check if they are in this range AREA_CIRCLE3X3
i didn't think about energy ring but can it check if condition by energy ring and if it is then it don't remove it?
or maybe if it is by energy ring then it deequip ring and remove condition?
 
You can use getDistanceBetween function aswell

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)

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

function onCastSpell(player, variant)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local partyLeader = party:getLeader()
    local pt = party:getMembers()
    for _, member in pairs(pt) do
        local mPos = member:getPosition()
        if getDistanceBetween(partyLeader:getPosition(), mPos) > 3 then
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "No party member in rage.")
            return false
        end
        if member:getCondition(CONDITION_MANASHIELD) then
            partyLeader:removeCondition(CONDITION_MANASHIELD)
            mPos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            member:removeCondition(CONDITION_MANASHIELD)
        elseif not member:getCondition(CONDITION_MANASHIELD) then
            partyLeader:addCondition(condition)
            mPos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            member:addCondition(condition)
        end
    end
    combat:execute(player, variant)
end
 
Last edited:
i edited it to this one
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 condition = Condition(CONDITION_MANASHIELD)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

function onCastSpell(player, variant)
    local party = player:getParty()
    if not party then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    local partyLeader = party:getLeader()
    local pt = party:getMembers()
    for _, member in pairs(pt) do
        local mPos = member:getPosition()
        if getDistanceBetween(partyLeader:getPosition(), mPos) > 3 then
            if partyLeader:getCondition(CONDITION_MANASHIELD) then
                partyLeader:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
                partyLeader:removeCondition(CONDITION_MANASHIELD)
                elseif not partyLeader:getCondition(CONDITION_MANASHIELD) then
                partyLeader:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
                partyLeader:addCondition(condition)
            end
            return combat:execute(player, variant)
        end      
        if getDistanceBetween(partyLeader:getPosition(), mPos) > 3 then
            return false
        end
        if member:getCondition(CONDITION_MANASHIELD) then
            mPos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
            member:removeCondition(CONDITION_MANASHIELD)
            elseif not member:getCondition(CONDITION_MANASHIELD) then
            mPos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            member:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
            member:addCondition(condition)
        end
    end
    if partyLeader:getCondition(CONDITION_MANASHIELD) then
        partyLeader:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
        partyLeader:removeCondition(CONDITION_MANASHIELD)
        elseif not partyLeader:getCondition(CONDITION_MANASHIELD) then
        partyLeader:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
        partyLeader:addCondition(condition)
    end
    return combat:execute(player, variant)
end
cuz in yours when there is 2 players. 1 have utamo and 1 don't have utamo it get confused with leader so leader go like on and off in same time. and it was not showing the combat area too.
script above working 100% as i need but i know it is not best way to write it. if someone can write it on a better way and fix my mistakes.
 
Inverts a party members magic shield status.

If off, turns on.
If on, turns off.
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)
        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
    return true
end
 
it get confused in members pos i think cause the up stairs monsters
error :
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:10>
 
it get confused in members pos i think cause the up stairs monsters
error :
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:10>
I can't seem to replicate your issue of it not working randomly?

1 = works, 2 = not work

In your video it's like this
1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 1, 2, 2

I've spawned monsters all around, up and below and on same ground
I've had different party's sitting side by side, and non-party people.

I don't understand how yours is not working randomly.. ._.

I just took over the exura for testing.
Maybe your line looks different?
XML:
    <instant group="healing" spellid="1" name="Light Healing" words="exura" level="8" mana="20" aggressive="0" selftarget="1" cooldown="1000" groupcooldown="1000" needlearn="0" script="healing/light_healing.lua">
        <vocation name="Sorcerer" />
        <vocation name="Druid" />
        <vocation name="Paladin" />
        <vocation name="Master Sorcerer" />
        <vocation name="Elder Druid" />
        <vocation name="Royal Paladin" />
    </instant>

If that's not the issue, can you try it with prints, and show us what prints when the spell doesn't 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)
    print("-------")
    local player = Player(creature)
    local party = player:getParty()
    
    if not party then
        print("Not in a party.")
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not in a party.")
        return false
    end
    
    print("Party found.")
    local leader = party:getLeader()
    local members = party:getMembers()
    
    local positions = combat:getPositions(creature, variant)
    
    for _, position in ipairs(positions) do
        local tile = Tile(position)
        for _, _creature in ipairs(tile:getCreatures()) do
            print("Creature (" .. _creature:getName() .. ") found within spell area.")
            if table.contains(members, _creature) or _creature == leader then
                print("-> Creature (" .. _creature:getName() .. ") is in a party with caster (" .. creature:getName() .. ").")
                if not _creature:hasCondition(CONDITION_MANASHIELD) then      
                    _creature:addCondition(magicShield)
                    _creature:say("Magic Shield [ON]", TALKTYPE_MONSTER_SAY)
                    print("-> Magic Shield Turned [ON]")
                else
                    _creature:removeCondition(CONDITION_MANASHIELD)
                    _creature:say("Magic Shield [OFF]", TALKTYPE_MONSTER_SAY)
                    print("-> Magic Shield Turned [OFF]")
                end
            end
        end
    end
    return true
end

Untitled.png
 
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>
 
Back
Top