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

Spell Mirror && Absolute Shields: SP Edition with 3 counterattacks+MOD

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
Mirror && Ultimate Shields: SP Edition with 3 counterattacks+MOD

Energy | Earth | Poison | Fire | Ice | Holy | Death

* *\ /* *\
*_____* *________* *|* *________* *\_____*/
****** Mirror && Ultimate Shields ******/
** ** SP Edition by Cybermaster ** **/
****** * | * ******/
* *|* */
**/ \**/
*****/
*

Author: Cybermaster
Storages:
1361 > Used to count the charges of the druid´s shield.
1362 > Used to count the charges of the knight´s shield.

Description:
These are the Mirror and Absolute shields which protect the player from any elemental-based attacks, no matter they are direct or area-based, this defense nullifies any elemental attack. Both shields have charges, and can be recharged when the user casts the spell.

The first shield, which is for druids, reflects elemental attacks to the attacker, working as a mirror shield. The attack of the reflected attack depends of caster´s ML.
The higher the druid´s ML is, more charges the druid gets. You can choose between these three counterattacks:

-'damage' : counterattacks with the same value of damage to attacker, and same element.

-'condition' : counterattacks adding a condition depending of the element-based attack by the target. The condition consists of 5 rounds of 2 seconds with -10 of damage. Burned, dazzled, poisoned, frozen, energy or cursed.

-'both' : both counterattacks just mentioned(damage and condition)


The other shield for knights just nullifies the attack. The higher the knight´s magic level is, more charges the knight gets.


MOD: mods/shield.xml
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Shield" tfs="0.3.6pl1" author="Cybermaster" web="otland.net" enabled="yes">
<config name="shield_setup"><![CDATA[
    --[[
                 
                 *          *\ /*          *\  
          *_____* *________* *|* *________* *\_____*/
           ****** Mirror && Ultimate Shields ******/
            ** ** SP Edition by Cybermaster ** **/
                    ******  *MOD* ******/
                          *  *|*  */
                           **/ \**/
                            *****/                
                              *
    ]]--

    energy = createConditionObject(CONDITION_ENERGY)
    setConditionParam(energy, CONDITION_PARAM_DELAYED, 1)
    addDamageCondition(energy, 5, 2000, -10)

    poison = createConditionObject(CONDITION_POISON)
    setConditionParam(poison, CONDITION_PARAM_DELAYED, 1)
    addDamageCondition(poison, 5, 2000, -10)

    fire = createConditionObject(CONDITION_FIRE)
    setConditionParam(fire, CONDITION_PARAM_DELAYED, 1)
    addDamageCondition(fire, 5, 2000, -10)

    freezing = createConditionObject(CONDITION_FREEZING)
    setConditionParam(freezing, CONDITION_PARAM_DELAYED, 1)
    addDamageCondition(freezing, 5, 2000, -10)

    dazzled = createConditionObject(CONDITION_DAZZLED)
    setConditionParam(dazzled, CONDITION_PARAM_DELAYED, 1)
    addDamageCondition(dazzled, 5, 2000, -10)

    cursed = createConditionObject(CONDITION_CURSED)
    setConditionParam(cursed, CONDITION_PARAM_DELAYED, 1)
    addDamageCondition(cursed, 5, 2000, -10)
   
    --[[ AVAILABLE OPTIONS FOR MIRROR SHIELD'S COUNTERATTACK:
    'damage' : counterattacks with the same value of damage to attacker, and same element.
    'condition' : counterattacks adding a condition depending of the element-based attack by the target. The condition consists of 5 rounds of 2 seconds with -10 of damage. Burned, dazzled, poisoned, frozen, energy or cursed.
    'both' : both counterattacks just mentioned(damage and condition) ]]--

    mirrorCounterAttack = 'condition'
   
    e,d,k = { --combat type and distance shoot effect, and condition
            [COMBAT_ENERGYDAMAGE]   =   {35,energy  },
            [COMBAT_EARTHDAMAGE]    =   {29,poison  },
            [COMBAT_POISONDAMAGE]   =   {14,poison  },
            [COMBAT_FIREDAMAGE]     =   {3, fire    },
            [COMBAT_ICEDAMAGE]      =   {28,freezing},
            [COMBAT_HOLYDAMAGE]     =   {30,dazzled },
            [COMBAT_DEATHDAMAGE]    =   {31,cursed  }
            },
        1361, --storage to store druid's shield charges
        1362  --storage to store knight's shield charges
   
    --array of the shields charges (Magic Level, Charges)
    kina_array =    {
                        {2, 1}, {6, 2}, {10, 3}
                    }
   
    mage_array =    {
                        {20, 1}, {60, 2}, {100, 3}
                    }
   
    function doKnightShield(p, effect)
        local pos = {   --do not modify
            {x=p.x+1,y=p.y,z=p.z  },
            {x=p.x+1,y=p.y+1,z=p.z},
            {x=p.x,y=p.y+1,z=p.z  },
            {x=p.x-1,y=p.y+1,z=p.z},
            {x=p.x-1,y=p.y,z=p.z  },
            {x=p.x-1,y=p.y-1,z=p.z},
            {x=p.x,y=p.y-1,z=p.z  },
            {x=p.x+1,y=p.y-1,z=p.z}
        }
        for i = 1, #pos do
            doSendDistanceShoot(p, pos[i], effect)
        end
    end
   
    function getShieldCharges(cid, array)
        table.sort(array, function(a, b) return a[1] > b[1] end)
        for _, t in ipairs(array) do    
            if getPlayerMagLevel(cid) >= t[1] then
                return t[2]
            end
        end
        return array[1][2]
    end
]]></config>
       
<event type="login" name="shield_register" event="script"><![CDATA[
    function onLogin(cid)
        registerCreatureEvent(cid,'shield')
    return true
    end]]>
</event>
       
<event type="statschange" name="shield" event="script"><![CDATA[
    domodlib('shield_setup')
    function onStatsChange(cid, attacker, type, combat, value)
        if isDruid(cid) and isCreature(attacker) and e[combat] and getCreatureStorage(cid, d) > 0 then
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
            doCreatureSetStorage(cid, d, getCreatureStorage(cid, d)-1)      
            doSendDistanceShoot(getThingPos(cid), getThingPos(attacker), e[combat][1])
            doPlayerSendCancel(cid, 'Your mirror shield has '.. (getCreatureStorage(cid,d) > 0 and getCreatureStorage(cid,d) or 'no') ..' charges left.')
            if mirrorCounterAttack == 'condition' then
                doTargetCombatCondition(cid, attacker, e[combat][2], CONST_ME_MAGIC_RED)
            elseif mirrorCounterAttack == 'damage' then
                doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_MAGIC_RED)
            elseif mirrorCounterAttack == 'both' then
                doTargetCombatCondition(cid, attacker, e[combat][2], CONST_ME_MAGIC_RED)
                doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_MAGIC_RED)
            end
            return false
        elseif isKnight(cid) and isCreature(attacker) and e[combat] and getCreatureStorage(cid, k) > 0 then
            doKnightShield(getThingPos(cid), e[combat][1])
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
            doCreatureSetStorage(cid, k, getCreatureStorage(cid, k)-1)
            doPlayerSendCancel(cid, 'Your ultimate shield has '.. (getCreatureStorage(cid,k) > 0 and getCreatureStorage(cid,k) or 'no') ..' charges left.')
            return false
        end
        return true
    end]]>
</event>
         
<instant name="Ultimate Shield" words="utamo max" lvl="60" mana="100" soul="3" exhaustion="2000" event="script">
    <text><![CDATA[
        domodlib('shield_setup')
        function onCastSpell(cid, var)
            if getCreatureStorage(cid, k) > 0 then
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                doPlayerSendCancel(cid,'Your ultimate shield still has '.. getCreatureStorage(cid, k) ..' charges.')
                return false
            end
   
            doCreatureSetStorage(cid, k, getShieldCharges(cid, kina_array))
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
            doPlayerSendCancel(cid,'You have just enabled your ultimate shield with '.. getCreatureStorage(cid, k) ..' charges.')
            return true
        end]]>
    </text><vocation id="4;8"/>
</instant>

<instant name="Mirror Shield" words="utamo gran" lvl="60" mana="300" soul="3" exhaustion="2000" event="script"><text>
    <![CDATA[
        domodlib('shield_setup')
        function onCastSpell(cid, var)
            if getCreatureStorage(cid, d) > 0 then
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                doPlayerSendCancel(cid,'Your mirror shield still has '.. getCreatureStorage(cid, d) ..' charges.')
                return false
            end
   
            doCreatureSetStorage(cid, d, getShieldCharges(cid, mage_array))
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
            doPlayerSendCancel(cid,'You have just enabled your mirror shield with '.. getCreatureStorage(cid, d) ..' charges.')
            return true
        end]]>
    </text><vocation id="2;6"/>
</instant>
</mod>

LUA Setup (If you use MOD you don't need these!)
> data/creaturescripts/creaturescripts.xml
Lua:
<event type="statschange" name="shield" event="script" value="shield.lua"/>

> data/creaturescripts/scripts/login.lua
Lua:
registerCreatureEvent(cid, "shield")

>
data/creaturescripts/scripts/shield.lua

Lua:
--[[
              
             *          *\ /*          *\  
      *_____* *________* *|* *________* *\_____*/
       ****** Mirror && Ultimate Shields ******/
        ** ** SP Edition by Cybermaster ** **/
                ******  * |  * ******/ 
                      *  *|*  */
                       **/ \**/
                        *****/                 
                          *
]]--

local energy = createConditionObject(CONDITION_ENERGY)
setConditionParam(energy, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(energy, 5, 2000, -10) 

local poison = createConditionObject(CONDITION_POISON)
setConditionParam(poison, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(poison, 5, 2000, -10)

local fire = createConditionObject(CONDITION_FIRE)
setConditionParam(fire, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(fire, 5, 2000, -10)

local freezing = createConditionObject(CONDITION_FREEZING)
setConditionParam(freezing, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(freezing, 5, 2000, -10)

local dazzled = createConditionObject(CONDITION_DAZZLED)
setConditionParam(dazzled, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(dazzled, 5, 2000, -10)

local cursed = createConditionObject(CONDITION_CURSED)
setConditionParam(cursed, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(cursed, 5, 2000, -10)

local mirrorCounterAttack = 'damage' --OPTIONS: 'condition'/'damage'/'both'
local e,d,k = { --combat type and distance shoot effect, and storages
        [COMBAT_ENERGYDAMAGE]   =   {35,energy  },
        [COMBAT_EARTHDAMAGE]    =   {29,poison  },
        [COMBAT_POISONDAMAGE]   =   {14,poison  },
        [COMBAT_FIREDAMAGE]     =   {3, fire    },
        [COMBAT_ICEDAMAGE]      =   {28,freezing},
        [COMBAT_HOLYDAMAGE]     =   {30,dazzled },
        [COMBAT_DEATHDAMAGE]    =   {31,cursed  }
        },
    1361, --druid
    1362  --kina 

function doKinaShield(p, effect)
    local pos = {   --do not modify
        {x=p.x+1,y=p.y,z=p.z  },
        {x=p.x+1,y=p.y+1,z=p.z},
        {x=p.x,y=p.y+1,z=p.z  },
        {x=p.x-1,y=p.y+1,z=p.z},
        {x=p.x-1,y=p.y,z=p.z  },
        {x=p.x-1,y=p.y-1,z=p.z},
        {x=p.x,y=p.y-1,z=p.z  },
        {x=p.x+1,y=p.y-1,z=p.z}
    }
    for i = 1, #pos do
        doSendDistanceShoot(p, pos[i], effect)
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if isDruid(cid) and isCreature(attacker) and e[combat] and getCreatureStorage(cid, d) > 0 then
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
        doCreatureSetStorage(cid, d, getCreatureStorage(cid, d)-1)       
        doSendDistanceShoot(getThingPos(cid), getThingPos(attacker), e[combat][1])
        doPlayerSendCancel(cid, 'Your mirror shield has '.. (getCreatureStorage(cid,d) > 0 and getCreatureStorage(cid,d) or 'no') ..' charges left.')
        if mirrorCounterAttack == 'condition' then
            doTargetCombatCondition(cid, attacker, e[combat][2], CONST_ME_MAGIC_RED)
        elseif mirrorCounterAttack == 'damage' then
            doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_MAGIC_RED)
        elseif mirrorCounterAttack == 'both' then
            doTargetCombatCondition(cid, attacker, e[combat][2], CONST_ME_MAGIC_RED)
            doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_MAGIC_RED)
        end
        return false
    elseif isKnight(cid) and isCreature(attacker) and e[combat] and getCreatureStorage(cid, k) > 0 then
        doKinaShield(getThingPos(cid), e[combat][1])
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
        doCreatureSetStorage(cid, k, getCreatureStorage(cid, k)-1)
        doPlayerSendCancel(cid, 'Your ultimate shield has '.. (getCreatureStorage(cid,k) > 0 and getCreatureStorage(cid,k) or 'no') ..' charges left.')
        return false
    end
    return true
end

> data/spells/scripts/mageshield.lua
Lua:
--storage to store the charges of druid's mirror shield & charges by magic level
local storage, d = 1361, {{20, 1},{60, 2},{100, 3}}

function getShieldCharges(cid)
    table.sort(d, function(a, b) return a[1] > b[1] end)
    for _, t in ipairs(d) do    
        if getPlayerMagLevel(cid) >= t[1] then 
            return t[2]
        end
    end
    return d[1][2]
end

function onCastSpell(cid, var)
    if getCreatureStorage(cid, storage) > 0 then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid,'Your mirror shield still has '.. getCreatureStorage(cid, storage) ..' charges.')
        return false
    end
    
    doCreatureSetStorage(cid, storage, getShieldCharges(cid))
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
    doPlayerSendCancel(cid,'You have just enabled your mirror shield with '.. getCreatureStorage(cid, storage) ..' charges.')
    return true
end

> data/spells/scripts/kinashield.lua
Lua:
--storage to store the charges of knight's ultimate shield & charges by magic level
local storage, d = 1362, {{2, 1},{6, 2},{10, 3}}

function getShieldCharges(cid)
    table.sort(d, function(a, b) return a[1] > b[1] end)
    for _, t in ipairs(d) do    
        if getPlayerMagLevel(cid) >= t[1] then 
            return t[2]
        end
    end
    return d[1][2]
end

function onCastSpell(cid, var)
    if getCreatureStorage(cid, storage) > 0 then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid,'Your ultimate shield still has '.. getCreatureStorage(cid, storage) ..' charges.')
        return false
    end
    
    doCreatureSetStorage(cid, storage, getShieldCharges(cid))
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
    doPlayerSendCancel(cid,'You have just enabled your ultimate shield with '.. getCreatureStorage(cid, storage) ..' charges.')
    return true
end

> data/spells/spells.xml
Lua:
 <instant name="Ultimate Shield" words="utamo max" lvl="60" mana="200" prem="0" exhaustion="2000" needlearn="0" script="kinashield.lua">
    <vocation id="4"/>
    <vocation id="8"/>
</instant>

<instant name="Mirror Shield" words="utamo gran" lvl="60" mana="600" prem="0" exhaustion="2000" needlearn="0" script="mageshield.lua">
    <vocation id="2"/>
    <vocation id="6"/>
</instant>

:peace:
 
Last edited:
well its kinda weird, has worked fine on 0.3.6
 
Wow i will use in my new server, for vocation "Templar Guardian" Thanks!!
 
this script has been tested and has worked 100% before on latest tfs
if someone can see any issue and make the solution i´d thank the "fix"
 
yoo i just tried the druid one and it absorbed the damage and reflected an effect, but it didnt do damage back to the attacker... i tried changing levels, damages and MLs to see if it worked but i got the same error

PHP:
[11/02/2010 19:03:02] [Error - CreatureScript Interface] 
[11/02/2010 19:03:02] data/creaturescripts/scripts/elemshield.lua:onStatsChange
[11/02/2010 19:03:02] Description: 
[11/02/2010 19:03:02] data/creaturescripts/scripts/elemshield.lua:27: attempt to index local 'attacker' (a number value)
[11/02/2010 19:03:02] stack traceback:
[11/02/2010 19:03:02] 	data/creaturescripts/scripts/elemshield.lua:27: in function <data/creaturescripts/scripts/elemshield.lua:24>

[11/02/2010 19:03:09] [Error - CreatureScript Interface] 
[11/02/2010 19:03:09] data/creaturescripts/scripts/elemshield.lua:onStatsChange
[11/02/2010 19:03:09] Description: 
[11/02/2010 19:03:09] data/creaturescripts/scripts/elemshield.lua:27: attempt to index local 'attacker' (a number value)
[11/02/2010 19:03:09] stack traceback:
[11/02/2010 19:03:09] 	data/creaturescripts/scripts/elemshield.lua:27: in function <data/creaturescripts/scripts/elemshield.lua:24>

in short, i didnt receive any damage and it deflected the type of effect back to the other player, but it didnt do any damage back to the player who attacked :p hope it helps :D!

im gona test the knight one ;]

EDIT: The knight one works like a charm <3 yo niceee work sonnnnn you outdid yourself with these 2 spells, very niceee :D i asked for something like this in one of my threads but ehh nothing haha very good job ;]

keep up the good work (^.^)! just try and see whats wrong with the druid one :p
 
Last edited:
ye, i know the problem
ill fix it as soon as i get free time

change attacker.uid to attacker
and the other prob is in doremovecreaturehealth, its in decimal so thats why its bugged
 
alrightt, i changed what you said and it worked perfectly! now the only thing it had weird was that when the attacker receives damage from the mage shield, the damage doesnt show... example

i attack the druid, i receive 20 damage... but the 20 damage doesnt show in the screen... it just takes away the 20 damage so you can see your hp dropping from the HP bar but you cant see it on your player like the little 20 in red colors or w.e lol

dunno if you wanna fix it but hey there it is =] still love the spell :p
 
sorry for double post but, cybermaster... do you think its possible to add a condition? example if i get attacked i dont only reflect damage but the attacker is paralyzed or hes set on fire :D? to add conditions to this script would be awesome <3
let me know :D
 
doCreatureAddHealth(attacker, -(getPlayerMagLevel(cid) * 1.5)) end should be changed somehow to doCombat with -(getPlayerMagLevel(cid) * 1.5)formula and damage type the same as used by attacker(it will look way better, reflect will be more realistic)
 
bump for a good set of spells.

plan on using these on my server =] thanks for the hard work
 
sure, screenshoots later
 
i'll update it then, with conditions
 
Back
Top