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

[0.4] Elemental resistence

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, otlanders i got an idea:
I need a spells that add player % elemental resistence (fire, Energy, earth etc) for 35 secs
Also a 3x2 square that bring 100% elemental resistence when standing there :)
I really dont know where to start tho.
Im using tfs 0.4 r3774 (8.6)

Thanks
 
Hello elnelson.

Well, since you need to give elemental protection, we should check for some way to do this, but in source of 3777 no condition can provide this.

OK, so how about we just use the onStatsChange creature event registering the player when he login to server? Now, when this event occurs we need to check if it is an elemental damage, and if it is, we need to check for a storage to see how much time the player has from the elemental damage protection, if more than 0, then lets return the value of combat with the reduction you want.

So now if the player has time left in the storage and take elemental damage it will be reduced. In the spells just need to create a spell that adds the time now + the time of protection

I don't understand what you say about the 3x2 square, but I think you can use a onStatsChange to deny this elemental damage if player are in this position( in the case that this a fixed position, otherwise maybe you will need to use a actionId to inform that this ground is elemental protector)
 
So
Hello elnelson.

Well, since you need to give elemental protection, we should check for some way to do this, but in source of 3777 no condition can provide this.

OK, so how about we just use the onStatsChange creature event registering the player when he login to server? Now, when this event occurs we need to check if it is an elemental damage, and if it is, we need to check for a storage to see how much time the player has from the elemental damage protection, if more than 0, then lets return the value of combat with the reduction you want.

So now if the player has time left in the storage and take elemental damage it will be reduced. In the spells just need to create a spell that adds the time now + the time of protection

I don't understand what you say about the 3x2 square, but I think you can use a onStatsChange to deny this elemental damage if player are in this position( in the case that this a fixed position, otherwise maybe you will need to use a actionId to inform that this ground is elemental protector)
So, i will need to add a specific storage value to each spell (even monsters spells) and make those storage work with players?
The higher the value, the higher defense. Right?
Btw can u help me with a simple example?

In advance, thanks.
 
As TFS 0.4 has getCreatureStorage(uid, key) and doCreatureSetStorage(uid, key, value) methods and monsters can also use this you can make monster spells to give them this bonus, but you don't need to use one for each spell. It can be stackable or substitute the already applied defense.
*nature boss uses bonus spell* -> grant -50% damage earth for the next 40 seconds
20 seconds later
*nature boss uses bonus spell* -> grant -50% damage earth for the next 40 seconds (Throw away the remaining 20 seconds)

So you just need two storages for each element, ex:
Fire : StorageElementFireProtection, StorageElementFireProtectionTime

The script use only the storage, which all creatures have. So if that creature, has StorageElementFireProtectionTime > that the time now it will decrease StorageElementFireProtection as % of the damage value. register the event on player login, and on monsters that will use the spell.

Do you understand? Need anymore? I don't promise a script because I don't have a 0.4 ready to test it right now
 
As TFS 0.4 has getCreatureStorage(uid, key) and doCreatureSetStorage(uid, key, value) methods and monsters can also use this you can make monster spells to give them this bonus, but you don't need to use one for each spell. It can be stackable or substitute the already applied defense.
*nature boss uses bonus spell* -> grant -50% damage earth for the next 40 seconds
20 seconds later
*nature boss uses bonus spell* -> grant -50% damage earth for the next 40 seconds (Throw away the remaining 20 seconds)

So you just need two storages for each element, ex:
Fire : StorageElementFireProtection, StorageElementFireProtectionTime

The script use only the storage, which all creatures have. So if that creature, has StorageElementFireProtectionTime > that the time now it will decrease StorageElementFireProtection as % of the damage value. register the event on player login, and on monsters that will use the spell.

Do you understand? Need anymore? I don't promise a script because I don't have a 0.4 ready to test it right now

Okey i get it, but how can i link the damage to a storage?
 
Ok. So lets go

creature uses spell: (in the spell .lua file)
spell set EARTH_DEFENSE_STORAGE = 20
spell set EARTH_DEFENSE_TIME_STORAGE= timeNow + 40

creature receives damage:
if TYPE of damage is COMBAT_EARTHDAMAGE and creature EARTH_DEFENSE_TIME_STORAGE > timeNow then:
set value to value - (creature EARTH_DEFENSE_TIME_STORAGE)% of value

player login:
register("name of onstatschange event")

Understand now?
 
Ok. So lets go

creature uses spell: (in the spell .lua file)
spell set EARTH_DEFENSE_STORAGE = 20
spell set EARTH_DEFENSE_TIME_STORAGE= timeNow + 40

creature receives damage:
if TYPE of damage is COMBAT_EARTHDAMAGE and creature EARTH_DEFENSE_TIME_STORAGE > timeNow then:
set value to value - (creature EARTH_DEFENSE_TIME_STORAGE)% of value

player login:
register("name of onstatschange event")

Understand now?
Not really, let me introduce you my test file:

i created a creaturescript (elemental_resistance.lua)
but its a total failure, lets call it an advancement
Lua:
local ENERGY_DEF = 20
local ENERGY_DEF_TIME = os.time + 40
function onStatsChange(cid, target)
if getPlayerStorageValue(target, ENERGY_DEF_TIME) >= 1 and COMBAT_EARTHDAMAGE then
--idk what to put here tho.
return true
end
return true
end
[CODE]
 
Ok. So you don't now how to use storages. No problems, look. The problem is that you're not passing a storageId. You don't get from the storage os.time() + 40

Choose some number like: 59602 to be the ENERGY_DEF
and then use this as an index to get or set the value of that storage. Did you get it? Is like a space that you can use to store extra information about the creature

ex:

Lua:
local ENERGY_DEF = 59602

doCreatureSetStorage(cid, ENERGY_DEF, 40)
getCreatureStorage(cid, ENERGY_DEF) -- Returns 40
 
Ok. So you don't now how to use storages. No problems, look. The problem is that you're not passing a storageId. You don't get from the storage os.time() + 40

Choose some number like: 59602 to be the ENERGY_DEF
and then use this as an index to get or set the value of that storage. Did you get it? Is like a space that you can use to store extra information about the creature

ex:

Lua:
local ENERGY_DEF = 59602

doCreatureSetStorage(cid, ENERGY_DEF, 40)
getCreatureStorage(cid, ENERGY_DEF) -- Returns 40


still getting confused i dont know how the storage will raise energy defense
 
Well, we going to handle all the damage that the creature will receive, and then cancel them and do the reduced damage. But to now how much of the damage we should reduce, and if reduction is enabled after using the spell, we need to have this saved in something, so we use the player to save on storage


Maybe this can clarify? I don't test, and it can be wrong, but just to help

Lua:
-- Elemental Damage Bonus

-- Since we need to cancel the damage and use doTargetCombatHealth
-- that calls onStatsChange again, lets hold which player is actually
-- taking damage and ignore the next onStatsChange
local ignoreNext = {}

-- Storages
-- As local for simplicity. But can be global
local STRG_BONUS_DEF_EARTH = 294242
local STRG_BONUS_DEF_EARTH_TIME = 294243

function onStatsChange(cid, attacker, type, combat, value)
    if ignoreNext[cid] then -- onStatsChange already processed for this player, ignore
        ignoreNext[cid] = nil
        return true
    end

    -- No other creature is in the action. Ignore
    if not attacker then
        return true
    end

    -- Not a damage? Just ignore
    if not type == STATSCHANGE_HEALTHLOSS and not type == STATSCHANGE_MANALOSS then
        return true
    end

    -- Earth damage, lets check for bonus
    if combat == COMBAT_EARTHDAMAGE then
        -- Lets check defense bonus first
        local hasDefBonus = getCreatureStorage(cid, STRG_BONUS_DEF_EARTH_TIME) > os.time()
        if hasDefBonus then
            -- Ok, bonus is enabled for now, lets get how much of it
            local defBonus = getCreatureStorage(cid, STRG_BONUS_DEF_EARTH)
            defBonus = (defBonus * value / 100) -- Lets get as percent
            value = value - defBonus -- Reduce the damage by the bonus percent
            if value > 0 then -- If value is less than 0 just cancel the damage
                -- if more than 0, lets do another damage event
                -- but first, don't forget to make it be ignored
                ignoreNext[cid] = true
                doTargetCombatHealth(attacker, cid, type, -value, -value, effect) -- Do another damage event
            end
            return false -- Lets cancel this damage
        end
    end

    return true
end
 
Last edited:
Well, we going to handle all the damage that the creature will receive, and then cancel them and do the reduced damage. But to now how much of the damage we should reduce, and if reduction is enabled after using the spell, we need to have this saved in something, so we use the player to save on storage


Maybe this can clarify? I don't test, and it can be wrong, but just to help

Lua:
-- Elemental Damage Bonus

-- Since we need to cancel the damage and use doTargetCombatHealth
-- that calls onStatsChange again, lets hold which player is actually
-- taking damage and ignore the next onStatsChange
local ignoreNext = {}

-- Storages
-- As local for simplicity. But can be global
local STRG_BONUS_DEF_EARTH = 294242
local STRG_BONUS_DEF_EARTH_TIME = 294243

function onStatsChange(cid, attacker, type, combat, value)
    if ignoreNext[cid] then -- onStatsChange already processed for this player, ignore
        ignoreNext[cid] = nil
        return true
    end

    -- No other creature is in the action. Ignore
    if not attacker then
        return true
    end

    -- Not a damage? Just ignore
    if not type == STATSCHANGE_HEALTHLOSS and not type == STATSCHANGE_MANALOSS then
        return true
    end

    -- Earth damage, lets check for bonus
    if combat == COMBAT_EARTHDAMAGE then
        -- Lets check defense bonus first
        local hasDefBonus = getCreatureStorage(cid, STRG_BONUS_DEF_EARTH_TIME) > os.time()
        if hasDefBonus then
            -- Ok, bonus is enabled for now, lets get how much of it
            local defBonus = getCreatureStorage(cid, STRG_BONUS_DEF_EARTH)
            defBonus = (defBonus * value / 100) -- Lets get as percent
            value = value - defBonus -- Reduce the damage by the bonus percent
            if value > 0 then -- If value is less than 0 just cancel the damage
                -- if more than 0, lets do another damage event
                -- but first, don't forget to make it be ignored
                ignoreNext[cid] = true
                doTargetCombatHealth(attacker, cid, type, -value, -value, effect) -- Do another damage event
            end
            return false -- Lets cancel this damage
        end
    end

    return true
end
gonna test now, i must put this storage (294242) a value of 100 to have 100% earth resistance, right?
seems not working
 
Yes, just set it to a number % that you like, and the STRG_BONUS_DEF_EARTH_TIME to os.time() + seconds enabled. Don't worry if not working, it was just to give you a base, but it's something like that
 
Back
Top