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

CreatureEvent [TFS 1.2] Conditions: Resist, Absorb, Reflect, Deflect

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,015
Solutions
3
Reaction score
629
Location
Canada
Hello everyone. I've seen some people looking for conditions for resistance and I know @beastn wants this system specifically :p

Figured I'd release my code for resist, absorb, reflect, deflect
Resist: reduce damage by x%
Absorb: reduce damage by x%, heal x%
Reflect: take full damage, deal x% to attacker
Deflect: reduce damage by x%, deal x% to attacker

It's a bit of a mess since it's not something I originally planned to release and there might be bits and pieces of other stuff that isn't used cause I often leave unused variables lying around :p
I'm not gonna go about writing all the xml code and a full system for usage. That's up to you :D
This is the important stuff.
creaturescript.lua:
Code:
local res = {
    {101, COMBAT_FIREDAMAGE}, {102, COMBAT_EARTHDAMAGE}, {103, COMBAT_ENERGYDAMAGE}, {104, COMBAT_ICEDAMAGE}, {105, COMBAT_HOLYDAMAGE}, {106, COMBAT_DEATHDAMAGE}, {107, COMBAT_PHYSICALDAMAGE}, {108, COMBAT_PHYSICALDAMAGE},
    {109, COMBAT_FIREDAMAGE},{110, COMBAT_EARTHDAMAGE}, {111, COMBAT_ENERGYDAMAGE}, {112, COMBAT_ICEDAMAGE}, {113, COMBAT_HOLYDAMAGE}, {114, COMBAT_DEATHDAMAGE}, {115, COMBAT_PHYSICALDAMAGE}, {116, COMBAT_PHYSICALDAMAGE},
    {117, COMBAT_FIREDAMAGE}, {118, COMBAT_EARTHDAMAGE}, {119, COMBAT_ENERGYDAMAGE}, {120, COMBAT_ICEDAMAGE}, {121, COMBAT_HOLYDAMAGE}, {122, COMBAT_DEATHDAMAGE}, {123, COMBAT_PHYSICALDAMAGE}, {124, COMBAT_PHYSICALDAMAGE},
    {125, COMBAT_FIREDAMAGE}, {126, COMBAT_EARTHDAMAGE}, {127, COMBAT_ENERGYDAMAGE}, {128, COMBAT_ICEDAMAGE}, {129, COMBAT_HOLYDAMAGE}, {130, COMBAT_DEATHDAMAGE}, {131, COMBAT_PHYSICALDAMAGE}, {132, COMBAT_PHYSICALDAMAGE},
}
local refs = {
    [COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
    [COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
    [COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
    [COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
    [COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
    [COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
    [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA
}
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if primaryType == COMBAT_HEALING then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 11) then
            if primaryType == COMBAT_DROWNDAMAGE then
                primaryDamage = 0
            end
            if secondaryType == COMBAT_DROWNDAMAGE then
                secondaryDamage = 0
            end
        end
        for i = 1, 8 do -- resist
            if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
                if primaryType == res[i][2] or i == 8 then
                    primaryDamage = (primaryDamage - (primaryDamage * (creature:getStorageValue(5) / 100)))
                end
                if secondaryType == res[i][2] or i == 8 then
                    secondaryDamage = (secondaryDamage - (secondaryDamage * (creature:getStorageValue(5) / 100)))
                end
            end
        end
        for i = 9, 16 do -- reflect
            if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
                if not attacker then
                    return primaryDamage, primaryType, secondaryDamage, secondaryType
                end
                if primaryType == res[i][2] or i == 16 then
                    local a = math.floor(primaryDamage * (creature:getStorageValue(5) / 100))
                    if attacker:isMonster() then
                        local m = MonsterType(attacker:getName())
                        local e = m:getElementList()
                        local f = m:getCombatImmunities()
                        if type(f) == "number" then
                            if f == primaryType then
                                a = 0
                            end
                        else
                            for i, j in pairs(f) do
                                if i == primaryType then
                                    a = 0
                                end
                            end
                        end
                        if type(e) == "number" then
                            if e == primaryType then
                                if e > 0 then
                                    a = (a - (a * (e / 100)))
                                else
                                    a = (a + (a * ((e * -1) / 100)))
                                end
                            end
                        else
                            for i, j in pairs(e) do
                                if i == primaryType then
                                    if j > 0 then
                                        a = (a - (a * (j / 100)))
                                    else
                                        a = (a + (a * ((j * -1) / 100)))
                                    end
                                end
                            end
                        end
                    end
                    doTargetCombatHealth(creature, attacker, primaryType, a, a, refs[primaryType])
                end
            end
        end
        for i = 17, 24 do -- deflect
            if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
                if not attacker then
                    return primaryDamage, primaryType, secondaryDamage, secondaryType
                end
                if primaryType == res[i][2] or i == 24 then
                    local a = math.floor(primaryDamage * (creature:getStorageValue(5) / 100))
                    if attacker:isMonster() then
                   
                        local m = MonsterType(attacker:getName())
                        local e = m:getElementList()
                        local f = m:getCombatImmunities()
                        if type(f) == "number" then
                            if f == primaryType then
                                a = 0
                            end
                        else
                            for i, j in pairs(f) do
                                if i == primaryType then
                                    a = 0
                                end
                            end
                        end
                        if type(e) == "number" then
                            if e == primaryType then
                                if e > 0 then
                                    a = (a - (a * (e / 100)))
                                else
                                    a = (a + (a * ((e * -1) / 100)))
                                end
                            end
                        else
                            for i, j in pairs(e) do
                                if i == primaryType then
                                    if j > 0 then
                                        a = (a - (a * (j / 100)))
                                    else
                                        a = (a + (a * ((j * -1) / 100)))
                                    end
                                end
                            end
                        end
                    end
                    doTargetCombatHealth(creature, attacker, primaryType, a, a, refs[primaryType])
                    primaryDamage = (primaryDamage - (primaryDamage * (creature:getStorageValue(5) / 100)))
                    secondaryDamage = (secondaryDamage - (secondaryDamage * (creature:getStorageValue(5) / 100)))
                end
            end
        end
        for i = 25, 32 do
            if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
                if primaryType == res[i][2] or i == 32 then
                    local a = math.floor(primaryDamage * (creature:getStorageValue(5) / 100))
                    creature:addHealth(a)
                    primaryDamage = (primaryDamage - (primaryDamage * (creature:getStorageValue(5) / 100)))
                    secondaryDamage = (secondaryDamage - (secondaryDamage * (creature:getStorageValue(5) / 100)))
                end
            end
        end
    end
    if primaryDamage == 0 and secondaryDamage == 0 and creature:isPlayer() then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

example of setting the condition to the player:
Code:
local t = 60 * 1000
local v = 10
local resist = Condition(CONDITION_ATTRIBUTES)
resist:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
resist:setParameter(CONDITION_PARAM_SUBID, 108)
resist:setParameter(CONDITION_PARAM_TICKS, t)
player:addCondition(resist)
player:setStorageValue(5, v)

Can't guarantee this will work for certain versions, I run TFS 1.2 and it works, so if it doesn't, modify the code :p
 
Did you checked the damage values with the reflect and deflect thing? I don't know if those elements/immunities are needed at all...
Nice script btw :D
 
Last time I tested it, everything worked as intended. the way it deals the damage doesn't seem to factor in the resistances of the attacker so they always took full damage even if they were fully immune to that type
 
I don't know if you still have the video that I sent to you, but if you look carefully at it you'll see when I reflect the fire attack to the fire elemental he doesn't get any dmg :eek:
 
When I tested on a fire devil, he took full damage from a reflected fire attack, and he should be immune
 
ZOMG YES!!!!!! THANKS!!
 
Very nice. I would have to say the way you went about making this shows alot of ingenuity for sure. Great release, thank you for the release, and as for anything else you have to release I will be looking out for it :D
 
Very nice. I would have to say the way you went about making this shows alot of ingenuity for sure. Great release, thank you for the release, and as for anything else you have to release I will be looking out for it :D

Glad you liked it :p I'm debating on releasing my crafting system and my alchemy system. Both are skyrim-style and took a really long time but I haven't fully decided if I want to run my own server and keep them unique or just release them :p
 
Glad you liked it :p I'm debating on releasing my crafting system and my alchemy system. Both are skyrim-style and took a really long time but I haven't fully decided if I want to run my own server and keep them unique or just release them :p
giphy.gif
 

I'll think about it :p
They're pretty messy so if I release them, I'll have to do a lot of cleanup and make sure there's no bugs or anything :p and I'll probably have to test on a fresh build of tfs 1.1 since nobody is using 1.2 yet :c

I'll think about it tonight and maybe I'll release them tomorrow if I have a chance to fix them up
 
I'll think about it :p
They're pretty messy so if I release them, I'll have to do a lot of cleanup and make sure there's no bugs or anything :p and I'll probably have to test on a fresh build of tfs 1.1 since nobody is using 1.2 yet :c

I'll think about it tonight and maybe I'll release them tomorrow if I have a chance to fix them up
Whoo!! Looking forward too it ;) I use 1.2 haha
 
don't forget @Colors, I didn't release it all to you ;D

plus your version doesn't work properly cause I found a bunch of bugs after the fact xD

either way, I'll probably fix it up tomorrow before work and release it, I'd like to support custom servers by offering custom features for free. I've had just about enough of constant download and run rl maps

@beastn
 
Last edited:
You would you little traitor
No :mad:
don't forget @Colors, I didn't release it all to you ;D

plus your version doesn't work properly cause I found a bunch of bugs after the fact xD

either way, I'll probably fix it up tomorrow before work and release it, I'd like to support custom servers by offering custom features for free. I've had just about enough of constant download and run rl maps

@beastn

Did you found bugs and you didn't tell me? </3
 
local res = { {101, COMBAT_FIREDAMAGE}, {102, COMBAT_EARTHDAMAGE}, {103, COMBAT_ENERGYDAMAGE}, {104, COMBAT_ICEDAMAGE}, {105, COMBAT_HOLYDAMAGE}, {106, COMBAT_DEATHDAMAGE}, {107, COMBAT_PHYSICALDAMAGE}, {108, COMBAT_PHYSICALDAMAGE}, {109, COMBAT_FIREDAMAGE},{110, COMBAT_EARTHDAMAGE}, {111, COMBAT_ENERGYDAMAGE}, {112, COMBAT_ICEDAMAGE}, {113, COMBAT_HOLYDAMAGE}, {114, COMBAT_DEATHDAMAGE}, {115, COMBAT_PHYSICALDAMAGE}, {116, COMBAT_PHYSICALDAMAGE}, {117, COMBAT_FIREDAMAGE}, {118, COMBAT_EARTHDAMAGE}, {119, COMBAT_ENERGYDAMAGE}, {120, COMBAT_ICEDAMAGE}, {121, COMBAT_HOLYDAMAGE}, {122, COMBAT_DEATHDAMAGE}, {123, COMBAT_PHYSICALDAMAGE}, {124, COMBAT_PHYSICALDAMAGE}, {125, COMBAT_FIREDAMAGE}, {126, COMBAT_EARTHDAMAGE}, {127, COMBAT_ENERGYDAMAGE}, {128, COMBAT_ICEDAMAGE}, {129, COMBAT_HOLYDAMAGE}, {130, COMBAT_DEATHDAMAGE}, {131, COMBAT_PHYSICALDAMAGE}, {132, COMBAT_PHYSICALDAMAGE}, }
what happens if I add: {133, dragon_damage,} ?
Or we can't use custom damagetypes?

kk, great release! But alot to improve.
I created system, if non-existinting damage type is added to table, it automatically generates the receiver.
also I don't get it why your table is so big. I got only 6 values and 6 types, and does the same thing like your code.
 
Back
Top