• 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 0.X Block/Reduce damage on LUA

runsicky

Member
Joined
Apr 19, 2018
Messages
80
Reaction score
12
I'm trying to bring Charm/Imbuements to my server 8.6

I was able to change attacks stuff, add, remove, anything i want on attack on LUA

But on receive damage on LUA i could manage and even put to work

The only thing i found on forum working about it was this topic
block damage if have x amount of storage (https://otland.net/threads/block-damage-if-have-x-amount-of-storage.254180/) fixed by @Shadowsong

I tried to put his script to work in my server and got this
Code:
-- your stackoverflow protection would be triggered after receiving damaged, then removed after 0.1 seconds allowing for another attack to be blocked after 0.1 seconds, but if you receive more instances of damage during this 0.1 second period, they will not be blocked. But it's not safe at all cuz it can still happen that 2 creatures are attacking you at once, one attack will be blocked, the second will be received within these 0.1 seconds, and stack overflow will happen.

local stackOverflow = 815500 -- make sure stack overflow doesn't happen, don't change this
local stackOverFlowModifier = 77001 -- storage key for damage reduction
local dmg_receive_limit = 100 -- miliseconds between which these blocks are not triggering




local fire_protect_storage = 1001
local death_protect_storage = 1002
local ice_protect_storage = 1003
local energy_protect_storage = 1004
local holy_protect_storage = 1005
local earth_protect_storage = 1006

local reflect_protect_storage = 1007
local dodge_protect_storage = 1008
local paralyze_protect_storage = 1009

local percent_reduction = 25

function StackOverFlowFunction(cid)
    if isCreature(cid) then
        doPlayerSetStorageValue(cid, stackOverflow, -1)
    end
end

function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and attacker ~= nil and getPlayerStorageValue(cid, stackOverflow) == -1 then
    -- add overflowstorage
    doPlayerSetStorageValue(cid, stackOverflow, 1) -- set storage value before the creature takes another hit to avoid overflow
    local modifierValue = getPlayerStorageValue(cid, stackOverFlowModifier)
    modifierValue = (modifierValue == -1) and 0 or modifierValue


    -- protections
    print(getPlayerStorageValue(cid, fire_protect_storage))
    -- FIRE
    if combat == COMBAT_FIREDAMAGE and getPlayerStorageValue(cid, fire_protect_storage) > 0 then
        local damage = value - (value * (percent_reduction / 100))
        if type == STATSCHANGE_HEALTHLOSS then
            doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
        else
            doTargetCombatMana(attacker, cid, -damage, -damage, 255)
        end
        doSendAnimatedText(getThingPos(cid), "Fire Protect", TEXTCOLOR_WHITE)
        addEvent(StackOverFlowFunction, dmg_receive_limit, cid)
        return false
    -- DEATH
    elseif combat == COMBAT_DEATHDAMAGE and getPlayerStorageValue(cid, death_protect_storage) > 0 then
        doSendAnimatedText(getThingPos(cid), "Death Protect", TEXTCOLOR_WHITE)
    -- ICE
    elseif combat == COMBAT_ICEDAMAGE and getPlayerStorageValue(cid, ice_protect_storage) > 0 then
        doSendAnimatedText(getThingPos(cid), "Ice Protect", TEXTCOLOR_WHITE)
    -- ENERGY
    elseif combat == COMBAT_ENERGYDAMAGE and getPlayerStorageValue(cid, energy_protect_storage) > 0 then
        doSendAnimatedText(getThingPos(cid), "Energy Protect", TEXTCOLOR_WHITE)
    -- HOLY
    elseif combat == COMBAT_HOLYDAMAGE and getPlayerStorageValue(cid, holy_protect_storage) > 0 then
        doSendAnimatedText(getThingPos(cid), "Holy Protect", TEXTCOLOR_WHITE)
    -- EARTH
    elseif combat == COMBAT_EARTHDAMAGE and getPlayerStorageValue(cid, earth_protect_storage) > 0 then
        doSendAnimatedText(getThingPos(cid), "Earth Protect", TEXTCOLOR_WHITE)
    end







    -- REFLECT
    if(getPlayerStorageValue(cid, reflect_protect_storage) > 0) then
        if math.random(1, 10) == 1 then -- 10%
            doSendAnimatedText(getThingPos(cid), "REFLECT!", TEXTCOLOR_WHITE)
            -- Changed this so the reflected damage will be the same damage as recieved and also will count as the player hitting him and not the server hitting him. --
            setPlayerStorageValue(cid, stackOverflow, 1)
            doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
            return false
        end
    end
    -- DODGE
    if(getPlayerStorageValue(cid, dodge_protect_storage) > 0) then
        if math.random(1, 10) == 1 then
            doSendAnimatedText(getThingPos(cid), "DODGE!", TEXTCOLOR_WHITE)
            value = 0
            setPlayerStorageValue(cid, stackOverflow, 1)
            doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
            return false
        end
    end
    -- PARALYZE
    if(getPlayerStorageValue(cid, dodge_protect_storage) > 0) then
        doSendAnimatedText(getThingPos(cid), "PARALYZE!", TEXTCOLOR_WHITE)
        if not getCreatureCondition(attacker, CONDITION_PARALYZE) then
            local condition = createConditionObject(CONDITION_PARALYZE)
            setConditionParam(condition, CONDITION_PARAM_TICKS, 1000)
            setConditionFormula(condition, -0.5, 0, -0.5, 0)
            doAddCondition(attacker, condition)
            return false
        end
    end
    return true
end
end

But when i attack someone with
Code:
    -- FIRE
    if combat == COMBAT_FIREDAMAGE and getPlayerStorageValue(cid, fire_protect_storage) > 0 then

It just says 'Fire Protect', from:
Code:
doSendAnimatedText(getThingPos(cid), "Fire Protect", TEXTCOLOR_WHITE)

But no damage is done, player don't lose life, don't show nothing

What do i'm doing wrong?
 
Solution
i was add elseif to block other damage but we don't need this anymore
you can do it for vocation
example
knight can block more paladin and mage if have same value of storage
Thanks for the code guys I was looking for something like his
Post automatically merged:


Could you share your imbuiment system for 0.4 pls

everything else can be done on lua by following this topic: Lua - Imbuements System to 8.60 [0.4] (https://otland.net/threads/imbuements-system-to-8-60-0-4.265853/)
i didnt make the rest, i'll do after understand this part on this topic, but everything else is there


i tested it and work fine with me u can use something like this
Code:
        if(target && target->getPlayer())
        {
            std::string value;
            target->getPlayer()->getStorage(1001, value);
            int32_t reductPercent = (int32_t)(atoi(value.c_str()));
            if(reductPercent > 0 && combatType == COMBAT_FIREDAMAGE)
                damage = (int64_t)std::floor (damage - damage * reductPercent /100);
        }

it works, i tested here too, even with that else if

i was just trying to understand why did u put that else if

just ignore then?
remove that?
 
i was add elseif to block other damage but we don't need this anymore
you can do it for vocation
example
knight can block more paladin and mage if have same value of storage
 
Solution
Back
Top