• 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
in lua if player have 5 attack he can block one hit and one no because he work ever 1 second so in source better
if your server have war will get big laaag so in source better
this is my opinion why source better than lua
if you want it in source i can do for u :D
 
in lua if player have 5 attack he can block one hit and one no because he work ever 1 second so in source better
if your server have war will get big laaag so in source better
this is my opinion why source better than lua
if you want it in source i can do for u :D

i would love if u did, but as i said idk how to help you

the only thing i will do is, when u do the source part, i make the lua to post so people here on forum can use everything
 
in game.cpp in combatChangeHealth
after
int32_t damage = -healthChange;
add
Code:
if(target && target->getPlayer())
        {
            std::string value;
            target->getPlayer()->getStorage(xxxx, value); // xxxx ur storage number
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0)
              damage = (int64_t)std::floor (damage - damage * tmp /100);

            else if(tmp > 0)

                damage = 0;

        }

in combatChangeMana

after
bool deny = false;
CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
{
if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANALOSS, COMBAT_UNDEFINEDDAMAGE, manaChange))
deny = true;
}

if(deny)
return false;

add


Code:
if(target && target->getPlayer())
        {
            std::string value;
            target->getPlayer()->getStorage(xxxxx, value);  // xxxx ur storage number
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0)
              manaLoss = (int64_t)std::floor (manaLoss - manaLoss * tmp /100);

            else if(tmp > 0)

                manaLoss = 0;

        }

i hope this can help u :D
 
if under onStatsChange you put return false then no dmg will be done at all. if return true then 100% dmg will be done
if you want to make 50% reduce dmg then you have to use return false (0% dmg will be done) and use function onTargetCombatHealth

0.x after adding onStatsChange function allows to do all that stuff in lua and even much more

also you maybe have not declared STATSCHANGE_HEALTHLOSS in your constant. try to use 3 or 1.
if you have STATSCHANGE_HEALTHLOSS only then it wont work at all when player have utamo vita.
You have to use
if type == 1 or type == 3 then
 
Last edited:
============================================================================================================
@heba
============================================================================================================


in game.cpp in combatChangeHealth
after
int32_t damage = -healthChange;
add
Code:
if(target && target->getPlayer())
        {
            std::string value;
            target->getPlayer()->getStorage(xxxx, value); // xxxx ur storage number
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0)
              damage = (int64_t)std::floor (damage - damage * tmp /100);

            else if(tmp > 0)

                damage = 0;

        }

in combatChangeMana

after
bool deny = false;
CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
{
if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANALOSS, COMBAT_UNDEFINEDDAMAGE, manaChange))
deny = true;
}

if(deny)
return false;

add


Code:
if(target && target->getPlayer())
        {
            std::string value;
            target->getPlayer()->getStorage(xxxxx, value);  // xxxx ur storage number
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0)
              manaLoss = (int64_t)std::floor (manaLoss - manaLoss * tmp /100);

            else if(tmp > 0)

                manaLoss = 0;

        }

i hope this can help u :D

what is it?
int32_t tmp = (int32_t)(atoi(value.c_str()));

what is it?
std::string value;
why it is a string? if it is...

what is it?
(int64_t)std::floor

could you help me to transform the lua script
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

to your c++ code?
i tried this
Code:
        int32_t damage = -healthChange;
        if(target && target->getPlayer())
        {
            const Position& targetPos = target->getPosition();

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

            int32_t reflect_protect_storage = 1007
            int32_t dodge_protect_storage = 1008
            int32_t paralyze_protect_storage = 1009

            int32_t percent_reduction = 25;

            int32_t fire_protect_value, death_protect_value, ice_protect_value, energy_protect_value, holy_protect_value, earth_protect_value;
            int32_t reflect_protect_value, dodge_protect_value, paralyze_protect_value;
          
            target->getPlayer()->getStorage(fire_protect_storage, fire_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, death_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, ice_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, energy_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, holy_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, earth_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, reflect_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, dodge_protect_value);
            target->getPlayer()->getStorage(fire_protect_storage, paralyze_protect_value);

            // elemental protections
            // fire
            if(fire_protect_value > 0 && combatType == COMBAT_FIREDAMAGE)
            {
                damage = damage - ((damage * percent_reduction) / ( 100 ));
                addAnimatedText("FIRE PROTECT", targetPos, hitColor, buffer);
            }
            // death
            else if(death_protect_value > 0 && combatType == COMBAT_DEATHDAMAGE)
            {
                damage = damage - ((damage * percent_reduction) / ( 100 ));
            }
            // ice
            else if(ice_protect_value > 0 && combatType == COMBAT_ICEDAMAGE)
            {
                damage = damage - ((damage * percent_reduction) / ( 100 ));
            }
            // energy
            else if(energy_protect_value > 0 && combatType == COMBAT_ENERGYDAMAGE)
            {
                damage = damage - ((damage * percent_reduction) / ( 100 ));
            }
            // holy
            else if(holy_protect_value > 0 && combatType == COMBAT_HOLYDAMAGE)
            {
                damage = damage - ((damage * percent_reduction) / ( 100 ));
            }
            // earth
            else if(earth_protect_value > 0 && combatType == COMBAT_EARTHDAMAGE)
            {
                damage = damage - ((damage * percent_reduction) / ( 100 ));
            }

            // other protections
            if(reflect_protect_value > 0) {
                // i have no idea
            }
            if(dodge_protect_value > 0) {
                damage = 0;
            }
            if(paralyze_protect_value > 0) {
                // i have no idea
            }
        }











============================================================================================================
@andu
============================================================================================================




if under onStatsChange you put return false then no dmg will be done at all. if return true then 100% dmg will be done

Hmm good to know return false dont make the damage work...

if you want to make 50% reduce dmg then you have to use return false (0% dmg will be done) and use function onTargetCombatHealth

i don't found the onTargetCombatHealth


0.x after adding onStatsChange function allows to do all that stuff in lua and even much more

But it wouldn't lag?
in lua if player have 5 attack it can block one hit and one no because he work ever 1 second so in source better
if there was a war it wouldnt make a big lag?

also you maybe have not declared STATSCHANGE_HEALTHLOSS in your constant. try to use 3 or 1.
if you have STATSCHANGE_HEALTHLOSS only then it wont work at all when player have utamo vita.
You have to use
if type == 1 or type == 3 then

If it was the way i will test with and without and show the results
 
Last edited:
my cod will work for all damage all you have to do put what i said in game.cpp and use spell add xxxx storage (same in source ) for x time and it will work
i’m use mobile now
 
my cod will work for all damage all you have to do put what i said in game.cpp and use spell add xxxx storage (same in source ) for x time and it will work
i’m use mobile now

what are u mean?

this storages fire_protect_storage (1001) for example is to reduce fire types damage, not all damages
so as holy, energy, death...

every time player equips an item with imbuiments he will recive 1001 + 1

so will reduce more percentage deppeding how many items with fire_protection he have (how higher is the 1001 storage)
 
this cod will block fire damage maybe this u want
Code:
if(target && target->getPlayer())
        {
            std::string value;
            target->getPlayer()->getStorage(xxxx, value); // xxxx ur storage number
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);

            else if(tmp > 0)

                damage = 0;

        }

this code work like if player have storage + 70 will block 70% from the damage if have storage + 100+ will block 100% from damage
 
What do i doing wrong?

code
Code:
        int32_t damage = -healthChange;
        int32_t tmp;
        // def imbu (elemental protections) 1
        if(target && target->getPlayer())
        {
            std::string value;
            // fire protection
            target->getPlayer()->getStorage(1001, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
                addAnimatedText("FIRE PROTECT", targetPos, hitColor, buffer);
            else if(tmp > 0)
                damage = 0;
            // death protection
            target->getPlayer()->getStorage(1002, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_DEATHDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // ice protection
            target->getPlayer()->getStorage(1003, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_ICEDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // energy protection
            target->getPlayer()->getStorage(1004, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_ENERGYDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // holy protection
            target->getPlayer()->getStorage(1005, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_HOLYDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // earth protection
            target->getPlayer()->getStorage(1006, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_EARTHDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
        }

errors
 
just change combat
Code:
if(target && target->getPlayer())
        {
            std::string tmp = "0";
        target->getPlayer()->getStorage(xxxx, value); 
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE) // fire protection
              damage = (int64_t)std::floor (damage - damage * tmp /100);

            else if(tmp > 0)

                damage = 0;

        }

combat u can use this
COMBAT_FIREDAMAGE
COMBAT_ENERGYDAMAGE
COMBAT_EARTHDAMAGE:
COMBAT_ICEDAMAGE:
COMBAT_HOLYDAMAGE:
COMBAT_DEATHDAMAGE:
COMBAT_PHYSICALDAMAGE:
 
just change combat
Code:
if(target && target->getPlayer())
        {
            std::string tmp = "0";
        target->getPlayer()->getStorage(xxxx, value);
            int32_t tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE) // fire protection
              damage = (int64_t)std::floor (damage - damage * tmp /100);

            else if(tmp > 0)

                damage = 0;

        }

combat u can use this
COMBAT_FIREDAMAGE
COMBAT_ENERGYDAMAGE
COMBAT_EARTHDAMAGE:
COMBAT_ICEDAMAGE:
COMBAT_HOLYDAMAGE:
COMBAT_DEATHDAMAGE:
COMBAT_PHYSICALDAMAGE:

Thats what i tried
I need to change the type and the storage, different types have differents storages

What i've dont wrong?


Code:
        int32_t damage = -healthChange;
        int32_t tmp;
        // def imbu (elemental protections) 1
        if(target && target->getPlayer())
        {
            std::string value;
            // fire protection
            target->getPlayer()->getStorage(1001, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
                addAnimatedText("FIRE PROTECT", targetPos, hitColor, buffer);
            else if(tmp > 0)
                damage = 0;
            // death protection
            target->getPlayer()->getStorage(1002, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_DEATHDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // ice protection
            target->getPlayer()->getStorage(1003, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_ICEDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // energy protection
            target->getPlayer()->getStorage(1004, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_ENERGYDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // holy protection
            target->getPlayer()->getStorage(1005, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_HOLYDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
            // earth protection
            target->getPlayer()->getStorage(1006, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(value < 0) value = 0;
            if(tmp > 0 && combatType == COMBAT_EARTHDAMAGE)
              damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0)
                damage = 0;
        }

errors
 
Code:
int32_t damage = -healthChange;
     // fire protection
          if(target && target->getPlayer())
           {
            std::string value;
            target->getPlayer()->getStorage(1001, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            addAnimatedText("FIRE PROTECT", targetPos, hitColor, buffer);
            else if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
                 damage = 0;

        }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // death protection
           if(target && target->getPlayer())
            {
            std::string value;
            target->getPlayer()->getStorage(1002, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_DEATHDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_DEATHDAMAGE)
             damage = 0;

        }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // ice protection
           if(target && target->getPlayer())
           { 
           std::string value;
            target->getPlayer()->getStorage(1003, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_ICEDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_ICEDAMAGE)
             damage = 0;
                }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // energy protection
            if(target && target->getPlayer())
            {
            std::string value;
            target->getPlayer()->getStorage(1004, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_ENERGYDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_ENERGYDAMAGE)
             damage = 0;
                }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // holy protection
           if(target && target->getPlayer())
            {
            std::string value;
            target->getPlayer()->getStorage(1005, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_HOLYDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_HOLYDAMAGE)
            damage = 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // earth protection
            if(target && target->getPlayer())
             {
            std::string value;
            target->getPlayer()->getStorage(1006, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_EARTHDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_EARTHDAMAGE)
            damage = 0;
        }
 
Code:
int32_t damage = -healthChange;
     // fire protection
          if(target && target->getPlayer())
           {
            std::string value;
            target->getPlayer()->getStorage(1001, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            addAnimatedText("FIRE PROTECT", targetPos, hitColor, buffer);
            else if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
                 damage = 0;

        }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // death protection
           if(target && target->getPlayer())
            {
            std::string value;
            target->getPlayer()->getStorage(1002, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_DEATHDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_DEATHDAMAGE)
             damage = 0;

        }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // ice protection
           if(target && target->getPlayer())
           {
           std::string value;
            target->getPlayer()->getStorage(1003, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_ICEDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_ICEDAMAGE)
             damage = 0;
                }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // energy protection
            if(target && target->getPlayer())
            {
            std::string value;
            target->getPlayer()->getStorage(1004, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_ENERGYDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_ENERGYDAMAGE)
             damage = 0;
                }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // holy protection
           if(target && target->getPlayer())
            {
            std::string value;
            target->getPlayer()->getStorage(1005, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_HOLYDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_HOLYDAMAGE)
            damage = 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
            // earth protection
            if(target && target->getPlayer())
             {
            std::string value;
            target->getPlayer()->getStorage(1006, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_EARTHDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            else if(tmp > 0 && combatType == COMBAT_EARTHDAMAGE)
            damage = 0;
        }

I don't understand one thing
What u want to do with this else if?

It isn't the same thing to the IF?

fire protection for example
Code:
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
        // fire protection
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
        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);
            }
            else if(reductPercent > 0 && combatType == COMBAT_FIREDAMAGE)
                damage = 0;
        }


Code:
if(reductPercent > 0 && combatType == COMBAT_FIREDAMAGE) {
else if(reductPercent > 0 && combatType == COMBAT_FIREDAMAGE)
 
sorry with elseif
add !=
will be like
else if(reductPercent > 0 && combatType != COMBAT_FIREDAMAGE)
damage = 0;
to no protected other damage
 
sorry with elseif
add !=
will be like
else if(reductPercent > 0 && combatType != COMBAT_FIREDAMAGE)
damage = 0;
to no protected other damage

i still not understand...
Code:
            if(reductPercent > 0 && combatType == COMBAT_FIREDAMAGE) {
                damage = (int64_t)std::floor (damage - damage * reductPercent /100);
            }
this means, if player have fire protect and damage is fire: reduce some % depeding on storage value


Code:
else if(reductPercent > 0 && combatType != COMBAT_FIREDAMAGE)

this means if player have fire protect and damage is not fire it set damage to 0?
why?
 
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);
        }
 
Thanks for the code guys I was looking for something like his
Post automatically merged:

i still not understand...
Code:
            if(reductPercent > 0 && combatType == COMBAT_FIREDAMAGE) {
                damage = (int64_t)std::floor (damage - damage * reductPercent /100);
            }
this means, if player have fire protect and damage is fire: reduce some % depeding on storage value


Code:
else if(reductPercent > 0 && combatType != COMBAT_FIREDAMAGE)

this means if player have fire protect and damage is not fire it set damage to 0?
why?
Could you share your imbuiment system for 0.4 pls
 
Back
Top