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

Lua AddTime Storage

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
173
Reaction score
13
hello, is it possible to add time to this scripts on line 26 gives a storage to the monster, can it be given for a time of 20 seconds and remove it so that the same mechanics can be done again?
me use otbr tfs 1.3



Lua:
local config = {
    ["Blue Soul Stealer"] = {id = 37249, effect = CONST_ME_ICEATTACK, type = COMBAT_ICEDAMAGE},
    ["Green Soul Stealer"] = {id = 37250, effect = CONST_ME_PLANTATTACK, type = COMBAT_EARTHDAMAGE},
    ["Red Soul Stealer"] = {id = 37251, effect = CONST_ME_FIREAREA, type = COMBAT_FIREDAMAGE},
}
local area = createCombatArea(AREA_CIRCLE2X2)
local monsters = {"Red Soul Stealer", "Green Soul Stealer", "Blue Soul Stealer"}
local soulVortex = MoveEvent()

function soulVortex.onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() or creature:getMaster() then
        return true
    end
    local name = creature:getName()
    if not isInArray(monsters, name) then
        return true
    end
    local data = config[name]
    position:sendMagicEffect(CONST_ME_MORTAREA)
    local maiden = Creature("The Dread Maiden")
    if not maiden then
        return true
    end
    if data.id == item:getId() then
        local oldStorage = maiden:getStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls)
        maiden:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, oldStorage + 1)
    else
        if math.random(2) == 2 then
            doAreaCombatHealth(creature, data.type, creature:getPosition(), area, -750, -1250, data.effect)
        else
            doTargetCombatHealth(0, maiden, COMBAT_HEALING, 3500, 5500, CONST_ME_NONE)
        end
    end
    creature:remove()
    return true
end

soulVortex:type("stepin")

for index, value in pairs(config) do
    soulVortex:id(value.id)
end

soulVortex:register()

It should go back to the initial storage which I think would be the one in this script

Lua:
local theDreadMaidenHealth = CreatureEvent("theDreadMaidenHealth")

function theDreadMaidenHealth.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType == COMBAT_DEATHDAMAGE or secondaryType == COMBAT_DEATHDAMAGE then
        primaryType = COMBAT_HEALING
        primaryDamage = (primaryDamage + secondaryDamage)
        secondaryType = COMBAT_NONE
        secondaryDamage = 0
    end
    if primaryType ~= COMBAT_HEALING then
        local storage = creature:getStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls)
        local percentage = (storage + 1) * 3
        primaryDamage = primaryDamage * (math.min(150, percentage) / 100)
        secondaryDamage = secondaryDamage * (math.min(150, percentage) / 100)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
theDreadMaidenHealth:register()
 
Solution
Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: attempt to index local 'mob' (a number value)
stack traceback:
        [C]: in function '__index'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: in function <...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29>

Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:callback
luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29: in function...

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Aren't we all :<

Lua:
maiden:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, oldStorage + 1)

-- remove -1 from storage after 20seconds:
addEvent(function(mob, storage)
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 20 * 1000, mob, oldStorage + 1)

It should go back to the initial storage
which is?
 
OP
OP
A

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
173
Reaction score
13
Aren't we all :<

Lua:
maiden:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, oldStorage + 1)

-- remove -1 from storage after 20seconds:
addEvent(function(mob, storage)
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 20 * 1000, mob, oldStorage + 1)


which is?
I think it would be this, having this storage the monster is immune
Code:
local storage = creature:getStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls)



Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: attempt to index local 'mob' (a nil value)
stack traceback:
        [C]: in function '__index'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: in function <...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29>


scripts
Code:
local config = {
    ["Blue Soul Stealer"] = {id = 37249, effect = CONST_ME_ICEATTACK, type = COMBAT_ICEDAMAGE},
    ["Green Soul Stealer"] = {id = 37250, effect = CONST_ME_PLANTATTACK, type = COMBAT_EARTHDAMAGE},
    ["Red Soul Stealer"] = {id = 37251, effect = CONST_ME_FIREAREA, type = COMBAT_FIREDAMAGE},
}
local area = createCombatArea(AREA_CIRCLE2X2)
local monsters = {"Red Soul Stealer", "Green Soul Stealer", "Blue Soul Stealer"}
local soulVortex = MoveEvent()

function soulVortex.onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() or creature:getMaster() then
        return true
    end
    local name = creature:getName()
    if not isInArray(monsters, name) then
        return true
    end
    local data = config[name]
    position:sendMagicEffect(CONST_ME_MORTAREA)
    local maiden = Creature("The Dread Maiden")
    if not maiden then
        return true
    end
    if data.id == item:getId() then
        local oldStorage = maiden:getStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls)
        maiden:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, oldStorage + 1)

-- remove -1 from storage after 20seconds:
addEvent(function(mob, storage)
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 10 * 1000, mob, oldStorage + 1)
    else
        if math.random(2) == 2 then
            doAreaCombatHealth(creature, data.type, creature:getPosition(), area, -750, -1250, data.effect)
        else
            doTargetCombatHealth(0, maiden, COMBAT_HEALING, 3500, 5500, CONST_ME_NONE)
        end
    end
    creature:remove()
    return true
end

soulVortex:type("stepin")

for index, value in pairs(config) do
    soulVortex:id(value.id)
end

soulVortex:register()
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Lua:
-- remove -1 from storage after 20seconds:
addEvent(function(mob, storage)
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 10 * 1000, maiden, oldStorage + 1)
 
OP
OP
A

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
173
Reaction score
13
Lua:
-- remove -1 from storage after 20seconds:
addEvent(function(mob, storage)
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 10 * 1000, maiden, oldStorage + 1)
Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: attempt to index local 'mob' (a number value)
stack traceback:
        [C]: in function '__index'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: in function <...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29>

Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:callback
luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29: in function <...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:10>
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: attempt to index local 'mob' (a number value)
stack traceback:
        [C]: in function '__index'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:30: in function <...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29>

Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:callback
luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        ...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:29: in function <...quests/feaster_of_souls/the_dread_maiden/soul_vortex.lua:10>

🤔 try this
Lua:
-- remove -1 from storage after 20seconds:
addEvent(function(cid, storage)
    local mob = Creature(cid)
    if not mob then return end
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 10 * 1000, maiden:getId(), oldStorage + 1)
 
Solution
OP
OP
A

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
173
Reaction score
13
🤔 try this
Lua:
-- remove -1 from storage after 20seconds:
addEvent(function(cid, storage)
    local mob = Creature(cid)
    if not mob then return end
    mob:setStorageValue(Storage.Quest.FeasterOfSouls.Bosses.TheDreadMaiden.Souls, storage - 1)
end, 10 * 1000, maiden:getId(), oldStorage + 1)
perfect
 
Top