• 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

Yeah, I originally said 1.2 because I had only tested it in my 1.2 server, but it's the same system as I released with my alchemy system so it should be fine with 1.1 as well. @Sir Knighter
 
Last edited:
how it would work if I use this system for a spell?
as would be the code?
 
how it would work if I use this system for a spell?
as would be the code?

Same as in the first post example. It's just a condition, like poison, haste, paralyze, etc. so just create your spell normally, and make sure to set the subId of the condition to the correct value for the effect you want.
 
Same as in the first post example. It's just a condition, like poison, haste, paralyze, etc. so just create your spell normally, and make sure to set the subId of the condition to the correct value for the effect you want.

I think he's asking if you would make the .lua of the spell
 
I think he's asking if you would make the .lua of the spell
I didn't get that at all xD if that's the case,
how it would work if I use this system for a spell?
as would be the code?
basically a modified version of the haste spell. Should work as far as I know. xD
Code:
local t = 60 * 1000 -- length of time for effect
local v = 10 -- percentage of damage to resist


local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local resist = Condition(CONDITION_ATTRIBUTES)
resist:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
resist:setParameter(CONDITION_PARAM_SUBID, 108) -- set subid as per main script to achieve desired effect
resist:setParameter(CONDITION_PARAM_TICKS, t)
player:setStorageValue(5, v)
combat:setCondition(resist)

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
 
i add drown damage (i like water spells for druids)

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_DROWNDAMAGE},
    {109, COMBAT_FIREDAMAGE}, {110, COMBAT_EARTHDAMAGE}, {111, COMBAT_ENERGYDAMAGE}, {112, COMBAT_ICEDAMAGE}, {113, COMBAT_HOLYDAMAGE}, {114, COMBAT_DEATHDAMAGE}, {115, COMBAT_PHYSICALDAMAGE}, {116, COMBAT_DROWNDAMAGE},
    {117, COMBAT_FIREDAMAGE}, {118, COMBAT_EARTHDAMAGE}, {119, COMBAT_ENERGYDAMAGE}, {120, COMBAT_ICEDAMAGE}, {121, COMBAT_HOLYDAMAGE}, {122, COMBAT_DEATHDAMAGE}, {123, COMBAT_PHYSICALDAMAGE}, {124, COMBAT_DROWNDAMAGE},
    {125, COMBAT_FIREDAMAGE}, {126, COMBAT_EARTHDAMAGE}, {127, COMBAT_ENERGYDAMAGE}, {128, COMBAT_ICEDAMAGE}, {129, COMBAT_HOLYDAMAGE}, {130, COMBAT_DEATHDAMAGE}, {131, COMBAT_PHYSICALDAMAGE}, {132, COMBAT_DROWNDAMAGE},
}
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_DROWNDAMAGE] = CONST_ME_LOSEENERGY,
    [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
 
help pls \/


Lua Script Error: [Test Interface]
data/spells/scripts/support/resist.lua
data/spells/scripts/support/resist.lua:13: attempt to index global 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/spells/scripts/support/resist.lua:13: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/support/resist.lua
 
So i have added the script to creaturescripts/scripts
What should I input in creaturescripts?
I' ve put this:
Code:
<event type="creaturescript" name="creaturescript" script="creaturescript.lua" />
Script doesnt work (it does shows a buff icon, but doesnt change fire damage I recive from monsters or firefields)
edit:
changed event type to: healthchange
Still doesnt work

Edit2:
I figured it out. I also had to register the event on login.
For anyone having same problem:
Just edit login.lua in creaturescripts and paste this:
Code:
player:registerEvent("healthchange")
 
Last edited:
I have a question about this script - there is an error in console saying that event onCastSpell doesnt exist. My .lua file looks like the one above made by RazorBlade. I guess I should somehow register(?) the event in onCastSpell but I dont really know how to do it.
 
Back
Top