• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Absorb barrier

beliar34

Member
Joined
Feb 28, 2012
Messages
307
Solutions
7
Reaction score
11
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Shield" author="C" enabled="yes">  
    <config name="shield_setup">
        <![CDATA[
            storage = 212123
            vocations = {7,8,9,10,11,12,72,82,83,84,85,86,87,102,103,104,105,106,107,18,19,20,21,22,23,78,28,29,30,31,32,33,76,34,35,36,37,38,39,79,52,53,54,55,56,57,58,59}
            spentMana = 1
            time = 10 -- in minutes
            condition = createConditionObject(CONDITION_INFIGHT)
            setConditionParam(condition, CONDITION_PARAM_TICKS, time*60*1000)
            function doFinish(cid)
                if isPlayer(cid) and getPlayerStorageValue(cid,storage) > 0 then
                    return doPlayerSetStorageValue(cid, storage, 0)
                end
            end
            function doWaste(cid)
                if isPlayer(cid) then
                    if getPlayerStorageValue(cid,storage) > 0 then
                        if getCreatureMana(cid) >= spentMana then 
                            doCreatureAddMana(cid, -spentMana)
                            doSendMagicEffect(getThingPos(cid), 93)
                            addEvent(doWaste, 1000, cid)
                        else
                            doPlayerSetStorageValue(cid, storage, 0)
                            doPlayerSendCancel(cid, 'Your shield has worn out.')
                        end
                    end
                end
            end
        ]]>
    </config>
    <event type="login" name="shield2" event="script">
        <![CDATA[
            domodlib('shield_setup')
            function onLogin(cid)
                registerCreatureEvent(cid, "shield3")
                doPlayerSetStorageValue(cid, storage, 0)
                return true
            end
        ]]>
    </event>
    <event type="statschange" name="shield3" event="script">
        <![CDATA[
            domodlib('shield_setup')
            function onStatsChange(cid, attacker, type, combat, value)
                if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
                    if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
        if value >= getCreatureHealth(cid) then
            doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
            doPlayerSendTextMessage(cid,27,"Your shield was broken.")
            setPlayerStorageValue(cid, storage, 0)
            return false
                        else
                            doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                            return false
                        end
                    end
                end
                return true
            end
        ]]>
    </event>
    <instant name="Absorb Shield" words="absorb shield" lvl="5" mana="0" soul="0" exhaustion="500" event="script">
        <text>
            <![CDATA[
                domodlib('shield_setup')
                function onCastSpell(cid, var)
        if exhaustion.get(cid, 230) then
        doPlayerSendCancel(cid, 'Slow down.')
        return true
        end
        exhaustion.set(cid, 230, 55)
                    if getPlayerStorageValue(cid, storage) > 0 then
                        doPlayerSendCancel(cid,'Your shield is still active.')
                        return false
                    end
                    doAddCondition(cid, condition)
                    doPlayerSetStorageValue(cid, storage, 1)
                    addEvent(doWaste, 1000, cid)
                    addEvent(doFinish, time*60*1000, cid)
                    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
                    doPlayerSendCancel(cid,'You have just enabled shield for "..time.." minutes.')
                    return true
                end
            ]]>
        </text>
        <vocation id="7;8;9;10;11;12;72;82;83;84;85;86;87;102;103;104;105;106;107;18;19;20;21;22;23;78;28;29;30;31;32;33;76;34;35;36;37;38;39;79;52;53;54;55;56;57;58;59"/>
    </instant>
</mod>

This code works in that way : give player barrier and got it till somebody (player or monster) hit him IN ONE HIT by his max health and then barrier is destroyed.
How i want to this code work : i want to add barrier based on max health But barrier is destroyed when player recieve a damage from diffrent sources equal to his max health

Quick sample:
how i want this script to work:
Player 10000 Health turn on barrier
Player X hits him by 2000
Player Z hits him by 5000
Player C hits hym by 2000
Player Z hits him by 1000
Barrier is destroyed
How this script works:
Player 10000 Health turn on barrier
Player X hits him by 2000
Player Z hits him by 5000
Player C hits hym by 2000
Player Z hits him by 1000
Barrier is still there
Player X hits him by 2000
Player Z hits him by 5000
Player C hits hym by 2000
Player Z hits him by 1000
barrier is still there
Player G hits him by 10000 or more
Barrier is destroyed
 
Solution
I repeat again what i want to do here :
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
        if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
            if value >= getPlayerStorageValue(cid, storage) then
                doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
                doPlayerSendTextMessage(cid,27,"Your shield was broken.")
                setPlayerStorageValue(cid, storage, 0)
                return false
            else
                setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - value)...
@Xikini

@Thexamx how to change damage to -storagevalue ? i want to make this that way :

setcreaturestoragevalue x = creaturemaxhealth

setcreaturestoragevalue - COMBAT_HEALING

if creaturestoragevalue x >= 0 then break shield, but i dont know how to write this correctly :)
 
Last edited by a moderator:
What you want is pretty easy.
Set the player's storage 12345, as an example, with the value :maxhealth:.
Then, use this code:

Code:
function onHealthChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if player:getStorageValue(12345) > 0 then
        player:setStorageValue(12345, player:getStorageValue(12345) - (primaryDamage + secondaryDamage))
        return 0, 0, 0, 0
    end

    return -primaryDamage, primaryType, -secondaryDamage, -secondaryType
end

There is many other details you should think about, but this is the idea.
 
What you want is pretty easy.
Set the player's storage 12345, as an example, with the value :maxhealth:.
Then, use this code:

Code:
function onHealthChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if player:getStorageValue(12345) > 0 then
        player:setStorageValue(12345, player:getStorageValue(12345) - (primaryDamage + secondaryDamage))
        return 0, 0, 0, 0
    end

    return -primaryDamage, primaryType, -secondaryDamage, -secondaryType
end

There is many other details you should think about, but this is the idea.
Not this distro my friend, TFS 0.3.5 :)

i just need to change this code :
Code:
domodlib('shield_setup')
            function onStatsChange(cid, attacker, type, combat, value)
                if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
                    if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
        if value >= getCreatureHealth(cid) then
            doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
            doPlayerSendTextMessage(cid,27,"Your shield was broken.")
            setPlayerStorageValue(cid, storage, 0)
            return false
                        else
                            doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                            return false
                        end
                    end
                end
                return true
            end

Code:
PlayerSetStorageValue(cid, 12345, getCreatureMaxHealth(cid))



and



domodlib('shield_setup')
            function onStatsChange(cid, attacker, type, combat, value)
                if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
                    if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
                    doPlayerSetStorageValue(cid, 12345, -value(cid))
        if getPlayerStorageValue(cid, 12345) >= 0 then
            doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
            doPlayerSendTextMessage(cid,27,"Your shield was broken.")
            setPlayerStorageValue(cid, storage, 0)
            return false
                        else
                            doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                            return false
                        end
                    end
                end
                return true
            end

This should work ?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Shield" author="C" enabled="yes"> 
    <config name="shield_setup">
        <![CDATA[
            storage = 212123
        hape = 9123123
        menda = getPlayerStorageValue(cid, hape)
            vocations = {7,8,9,10,11,12,72,82,83,84,85,86,87,102,103,104,105,106,107,18,19,20,21,22,23,78,28,29,30,31,32,33,76,34,35,36,37,38,39,79,52,53,54,55,56,57,58,59}
            spentMana = 1
            time = 10 -- in minutes
            condition = createConditionObject(CONDITION_INFIGHT)
            setConditionParam(condition, CONDITION_PARAM_TICKS, time*60*1000)
            function doFinish(cid)
                if isPlayer(cid) and getPlayerStorageValue(cid,storage) > 0 then
                    return doPlayerSetStorageValue(cid, storage, 0)
                end
            end
            function doWaste(cid)
                if isPlayer(cid) then
                    if getPlayerStorageValue(cid,storage) > 0 then
                        if getCreatureMana(cid) >= spentMana then
                            doCreatureAddMana(cid, -spentMana)
                            doSendMagicEffect(getThingPos(cid), 93)
                            addEvent(doWaste, 1000, cid)
                        else
                            doPlayerSetStorageValue(cid, storage, 0)
                            doPlayerSendCancel(cid, 'Your shield has worn out.')
                        end
                    end
                end
            end
        ]]>
    </config>
    <event type="login" name="shield2" event="script">
        <![CDATA[
            domodlib('shield_setup')
            function onLogin(cid)
                registerCreatureEvent(cid, "shield3")
                doPlayerSetStorageValue(cid, storage, 0)
                return true
            end
        ]]>
    </event>
    <event type="statschange" name="shield3" event="script">
        <![CDATA[
            domodlib('shield_setup')
            function onStatsChange(cid, attacker, type, combat, value)
                if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
                    if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
                    doPlayerSetStorageValue(cid, hape, getPlayerStorageValue(cid, hape) - value(cid))
        if getPlayerStorageValue(cid, hape) <= 0 then
            doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
            doPlayerSendTextMessage(cid,27,"Your shield was broken.")
            setPlayerStorageValue(cid, storage, 0)
            return false
                        else
                            doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                            return false
                        end
                    end
                end
                return true
            end
        ]]>
    </event>
    <instant name="Absorb Shield" words="absorb shield" lvl="50" mana="0" soul="0" exhaustion="500" event="script">
        <text>
            <![CDATA[
                domodlib('shield_setup')
                function onCastSpell(cid, var)
        if exhaustion.get(cid, 230) then
        doPlayerSendCancel(cid, 'Slow down.')
        return true
        end
        exhaustion.set(cid, 230, 1)
                    if getPlayerStorageValue(cid, storage) > 0 then
                        doPlayerSendCancel(cid,'Your shield is still active.')
                        return false
                    end
                    doAddCondition(cid, condition)
                    doPlayerSetStorageValue(cid, storage, 1)
            doPlayerSetStorageValue(cid, hape, getCreatureMaxHealth(cid))
                    addEvent(doWaste, 1000, cid)
                    addEvent(doFinish, time*60*1000, cid)
                    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
                    doPlayerSendCancel(cid,'You have just enabled shield for "..time.." minutes.')
                    return true
                end
            ]]>
        </text>
        <vocation id="7;8;9;10;11;12;72;82;83;84;85;86;87;102;103;104;105;106;107;18;19;20;21;22;23;78;28;29;30;31;32;33;76;34;35;36;37;38;39;79;52;53;54;55;56;57;58;59"/>
    </instant>
</mod>

My whole code but still dont work, where is problem ?
no errors in console ;(
 
Last edited by a moderator:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
        if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
            if value >= getPlayerStorageValue(cid, storage) then
                doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
                doPlayerSendTextMessage(cid,27,"Your shield was broken.")
                setPlayerStorageValue(cid, storage, 0)
                return false
            else
                setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - value)
                doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                return false
            end
        end
    end

    return true
end
This should do I think.
 
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
        if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
            if value >= getPlayerStorageValue(cid, storage) then
                doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
                doPlayerSendTextMessage(cid,27,"Your shield was broken.")
                setPlayerStorageValue(cid, storage, 0)
                return false
            else
                setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - value)
                doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                return false
            end
        end
    end

    return true
end
This should do I think.
i dont see why this should work ? XD
did you read my whole post?
 
I repeat again what i want to do here :
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
        if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
            if value >= getPlayerStorageValue(cid, storage) then
                doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
                doPlayerSendTextMessage(cid,27,"Your shield was broken.")
                setPlayerStorageValue(cid, storage, 0)
                return false
            else
                setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - value)
                doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                return false
            end
        end
    end
    return true
end
Storage Value "storage" is set to 0 when storage value "hape" is 0 or less, damage to player is deleting from storage value "hape"

I want to make barrier that holds that damage equal to playermaxhealth, so i set storage "hape" to maxplayerhealth and then i want to delete "damage value" from value of hape storage ...

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Shield" author="C" enabled="yes">  
    <config name="shield_setup">
        <![CDATA[
            storage = 212123
        hape = 9123123
        menda = getPlayerStorageValue(cid, hape)
            vocations = {7,8,9,10,11,12,72,82,83,84,85,86,87,102,103,104,105,106,107,18,19,20,21,22,23,78,28,29,30,31,32,33,76,34,35,36,37,38,39,79,52,53,54,55,56,57,58,59}
            spentMana = 1
            time = 10 -- in minutes
            condition = createConditionObject(CONDITION_INFIGHT)
            setConditionParam(condition, CONDITION_PARAM_TICKS, time*60*1000)
            function doFinish(cid)
                if isPlayer(cid) and getPlayerStorageValue(cid,storage) > 0 then
                    return doPlayerSetStorageValue(cid, storage, 0)
                end
            end
            function doWaste(cid)
                if isPlayer(cid) then
                    if getPlayerStorageValue(cid,storage) > 0 then
                        if getCreatureMana(cid) >= spentMana then 
                            doCreatureAddMana(cid, -spentMana)
                            doSendMagicEffect(getThingPos(cid), 93)
                            addEvent(doWaste, 1000, cid)
                        else
                            doPlayerSetStorageValue(cid, storage, 0)
                            doPlayerSendCancel(cid, 'Your shield has worn out.')
                        end
                    end
                end
            end
        ]]>
    </config>
    <event type="login" name="shield2" event="script">
        <![CDATA[
            domodlib('shield_setup')
            function onLogin(cid)
                registerCreatureEvent(cid, "shield3")
                doPlayerSetStorageValue(cid, storage, 0)
                return true
            end
        ]]>
    </event>
    <event type="statschange" name="shield3" event="script">
        <![CDATA[
            domodlib('shield_setup')
            function onStatsChange(cid, attacker, type, combat, value)
                if isPlayer(cid) and getPlayerStorageValue(cid, storage) > 0 then
                    if isInArray(vocations, getPlayerVocation(cid)) and combat ~= COMBAT_HEALING and isCreature(attacker) then
                    setPlayerStorageValue(cid, hape, getPlayerStorageValue(cid, hape) - value)
        if getPlayerStorageValue(cid, hape) <= 0 then
            doSendAnimatedText(getThingPos(cid), TEXTCOLOR_DARKORANGE, 'BREAK')
            doPlayerSendTextMessage(cid,27,"Your shield was broken.")
            setPlayerStorageValue(cid, storage, 0)
            return false
                        else
                            doPlayerSendTextMessage(cid,27, "Shield : absorbed "..value.." hit points.")
                            return false
                        end
                    end
                end
                return true
            end
        ]]>
    </event>
    <instant name="Absorb Shield" words="absorb shield" lvl="50" mana="0" soul="0" exhaustion="500" event="script">
        <text>
            <![CDATA[
                domodlib('shield_setup')
                function onCastSpell(cid, var)
        if exhaustion.get(cid, 230) then
        doPlayerSendCancel(cid, 'Slow down.')
        return true
        end
        exhaustion.set(cid, 230, 1)
                    if getPlayerStorageValue(cid, storage) > 0 then
                        doPlayerSendCancel(cid,'Your shield is still active.')
                        return false
                    end
                    doAddCondition(cid, condition)
                    doPlayerSetStorageValue(cid, storage, 1)
            doPlayerSetStorageValue(cid, hape, getCreatureMaxHealth(cid))
                    addEvent(doWaste, 1000, cid)
                    addEvent(doFinish, time*60*1000, cid)
                    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
                    doPlayerSendCancel(cid,'You have just enabled shield for "..time.." minutes.')
                    return true
                end
            ]]>
        </text>
        <vocation id="7;8;9;10;11;12;72;82;83;84;85;86;87;102;103;104;105;106;107;18;19;20;21;22;23;78;28;29;30;31;32;33;76;34;35;36;37;38;39;79;52;53;54;55;56;57;58;59"/>
    </instant>
</mod>

FINAL WORKING SCRIPT

:)
 
Last edited by a moderator:
Solution
Back
Top