• 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 1.X+ [TFS 1.3]DemonOak from ORTS for my own 8.6(attempt to index global 'Storage' (a nil value)

Eduardo170

Well-Known Member
Joined
Jan 7, 2014
Messages
422
Solutions
3
Reaction score
66
Location
Caracas, Venezuela
I've been getting some errors in storage, I'm afraid this is because it is configured with other files on that server, somehow.
I think it's due to this
Code:
player:setStorageValue(Storage.DemonOak.Done, 1)
player:setStorageValue(Storage.DemonOak.Progress, 1)
Error.
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/quests/demon oak/demonOak.lua
data/actions/scripts/quests/demon oak/demonOak.lua:50: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/quests/demon oak/demonOak.lua:50: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/quests/demon oak/demonOak.lua


Code:
    <!-- Demon Oak -->
    <action itemid="8293" script="quests/demon oak/demonOak.lua" />
    <action fromuid="9008" touid="9011" script="quests/demon oak/demonOakChest.lua" />
    <action uniqueid="9007" script="quests/demon oak/demonOakGravestone.lua" />
DemonOak.lua
Code:
local config = {
    demonOakIds = {8288, 8289, 8290, 8291},
    sounds = {
        'MY ROOTS ARE SHARP AS A SCYTHE! FEEL IT?!?',
        'CURSE YOU!',
        'RISE, MINIONS, RISE FROM THE DEAD!!!!',
        'AHHHH! YOUR BLOOD MAKES ME STRONG!',
        'GET THE BONES, HELLHOUND! GET THEM!!',
        'GET THERE WHERE I CAN REACH YOU!!!',
        'ETERNAL PAIN AWAITS YOU! NICE REWARD, HUH?!?!',
        'YOU ARE GOING TO PAY FOR EACH HIT WITH DECADES OF TORTURE!!',
        'ARGG! TORTURE IT!! KILL IT SLOWLY MY MINION!!'
    },
    bonebeastChance = 90,
    bonebeastCount = 4,
    waves = 10,
    questArea = {
        fromPosition = {x = 1017, y = 1207, z = 7},
        toPosition = {x = 1036, y = 1219, z = 7}
    },
    summonPositions = {
        {x = 1025, y = 1210, z = 7},
        {x = 1023, y = 1211, z = 7},
        {x = 1022, y = 1213, z = 7},
        {x = 1024, y = 1216, z = 7},
        {x = 1027, y = 1216, z = 7},
        {x = 1030, y = 1216, z = 7},
        {x = 1032, y = 1213, z = 7},
        {x = 1030, y = 1210, z = 7}
    },
    summons = {
        [8288] = {
            [5] = {'Braindeath', 'Braindeath', 'Braindeath', 'Bonebeast'},
            [10] = {'Betrayed Wraith', 'Betrayed Wraith'}
        },
        [8289] = {
            [5] = {'Lich', 'Lich', 'Lich'},
            [10] = {'Dark Torturer', 'Blightwalker'}
        },
        [8290] = {
            [5] = {'Banshee', 'Banshee', 'Banshee'},
            [10] = {'Grim Reaper'}
        },
        [8291] = {
            [5] = {'Giant Spider', 'Giant Spider', 'Lich'},
            [10] = {'Undead Dragon', 'Hand of Cursed Fate'}
        }
    },
    storages = {
        [8288] = Storage.DemonOak.AxeBlowsBird,--AxeBlowsBird = 8288,
        [8289] = Storage.DemonOak.AxeBlowsLeft,--AxeBlowsLeft = 8289,
        [8290] = Storage.DemonOak.AxeBlowsRight, --AxeBlowsRight = 8290,
        [8291] = Storage.DemonOak.AxeBlowsFace --AxeBlowsFace = 8291
    }
}

local function getRandomSummonPosition()
    return config.summonPositions[math.random(#config.summonPositions)]
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray(config.demonOakIds, target.itemid) then
        return true
    end

    local totalProgress = 0
    for k,v in pairs(config.storages) do
        totalProgress = totalProgress + math.max(0, player:getStorageValue(v))
    end

    local spectators, hasMonsters = Game.getSpectators(DEMON_OAK_POSITION, false, false, 9, 9, 6, 6), false
    for i = 1, #spectators do
        if spectators[i]:isMonster() then
            hasMonsters = true
            break
        end
    end

    local isDefeated = totalProgress == (#config.demonOakIds * (config.waves + 1))
    if (config.killAllBeforeCut or isDefeated)
            and hasMonsters then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You need to kill all monsters first.')
        return true
    end

    if isDefeated then
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Tell Oldrak about your great victory against the demon oak.')
        player:setStorageValue(Storage.DemonOak.Done, 1)
        player:setStorageValue(Storage.DemonOak.Progress, 3)
        return true
    end

    local cStorage = config.storages[target.itemid]
    local progress = math.max(player:getStorageValue(cStorage), 1)
    if progress >= config.waves + 1 then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end

    local isLastCut = totalProgress == (#config.demonOakIds * (config.waves + 1) - 1)
    local summons = config.summons[target.itemid]
    if summons and summons[progress] then
        -- Summon a single demon on the last hit
        if isLastCut then
            Game.createMonster('Demon', getRandomSummonPosition(), false, true)

        -- Summon normal monsters otherwise
        else
            for i = 1, #summons[progress] do
                Game.createMonster(summons[progress][i], getRandomSummonPosition(), false, true)
            end
        end

    -- if it is not the 5th or 10th there is only a chance to summon bonebeasts
    elseif math.random(100) >= config.bonebeastChance then
        for i = 1, config.bonebeastCount do
            Game.createMonster('Bonebeast', getRandomSummonPosition(), false, true)
        end
    end

    player:say(isLastCut and 'HOW IS THAT POSSIBLE?!? MY MASTER WILL CRUSH YOU!! AHRRGGG!' or config.sounds[math.random(#config.sounds)], TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    toPosition:sendMagicEffect(CONST_ME_DRAWBLOOD)
    player:setStorageValue(cStorage, progress + 1)
    player:say('-krrrrak-', TALKTYPE_MONSTER_YELL, false, player, toPosition)
    doTargetCombatHealth(0, player, COMBAT_EARTHDAMAGE, -170, -210, CONST_ME_BIGPLANTS)
    return true
end

DemonOakChest.lua
Code:
local chests = {
    [9008] = {itemid = 2495, count = 1},
    [9009] = {itemid = 8905, count = 1},
    [9010] = {itemid = 8918, count = 1},
    [9011] = {itemid = 8851, count = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if chests[item.uid] then
        if player:getStorageValue(Storage.DemonOak.Done) ~= 2 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
            return true
        end

        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
            local article = itemType:getArticle()
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end

        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(Storage.DemonOak.Done, 3)
    end

    return true
end

DemonOakGravestone.lua
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.DemonOak.Done) == 2 then
        player:teleportTo(DEMON_OAK_REWARDROOM_POSITION)
        DEMON_OAK_REWARDROOM_POSITION:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end
end


Libs.lua
Code:
dofile('data/lib/demonOakQuest.lua')


DemonOakQuest.lua
Code:
DEMON_OAK_POSITION = Position(1027, 1213, 7)
DEMON_OAK_KICK_POSITION = Position(1027, 1202, 7)
DEMON_OAK_ENTER_POSITION = Position(1027, 1209, 7)
DEMON_OAK_REWARDROOM_POSITION = Position(1055, 1221, 8)



Code:
<!-- Demon Oak Quest -->
    <movevent event="StepIn" uniqueid="9000" script="quests/demon oak/entrance.lua" />
    <movevent event="StepIn" itemid="8292" script="quests/demon oak/areaDamage.lua" />
    <movevent event="StepIn" fromuid="9001" touid="9005" script="quests/demon oak/squares.lua" />
areaDamage.lua
Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if math.random(24) == 1 then
        doTargetCombatHealth(0, player, COMBAT_EARTHDAMAGE, -270, -310, CONST_ME_BIGPLANTS)
    end
    return true
end


entrance.lua
Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getStorageValue(Storage.DemonOak.Done) >= 1 then
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    if player:getLevel() < 120 then
        player:say("LEAVE LITTLE FISH, YOU ARE NOT WORTH IT!", TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    if player:getStorageValue(Storage.DemonOak.Squares) == 5 and #Game.getSpectators(DEMON_OAK_POSITION, false, true, 9, 9, 6, 6) == 0 then
        player:teleportTo(DEMON_OAK_ENTER_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:setStorageValue(Storage.DemonOak.Progress, 1)
        player:say("I AWAITED YOU! COME HERE AND GET YOUR REWARD!", TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    else
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    end
    return true
end

squares.lua
Code:
local voices = {
    'Release me and you will be rewarded greatefully!',
    'What is this? Demon Legs lying here? Someone might have lost them!',
    'I\'m trapped, come here and free me fast!!',
    'I can bring your beloved back from the dead, just release me!',
    'What a nice shiny golden armor. Come to me and you can have it!',
    'Find a way in here and release me! Pleeeease hurry!',
    'You can have my demon set, if you help me get out of here!'
}

local startUid = 9000
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local status = math.max(player:getStorageValue(Storage.DemonOak.Squares), 0)
    if item.uid - startUid == status + 1 then
        player:setStorageValue(Storage.DemonOak.Squares, status + 1)
        player:say(voices[math.random(#voices)], TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    end
    return true
end
 
Last edited:
Solution
E
just change

Storage.DemonOak.Done
and
Storage.DemonOak.Progress

to some storage numbers instead
I've been getting some errors in storage, I'm afraid this is because it is configured with other files on that server, somehow.
I think it's due to this
Code:
player:setStorageValue(Storage.DemonOak.Done, 1)
player:setStorageValue(Storage.DemonOak.Progress, 1)
Error.
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/quests/demon oak/demonOak.lua
data/actions/scripts/quests/demon oak/demonOak.lua:50: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/quests/demon oak/demonOak.lua:50: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/quests/demon oak/demonOak.lua


Code:
    <!-- Demon Oak -->
    <action itemid="8293" script="quests/demon oak/demonOak.lua" />
    <action fromuid="9008" touid="9011" script="quests/demon oak/demonOakChest.lua" />
    <action uniqueid="9007" script="quests/demon oak/demonOakGravestone.lua" />
DemonOak.lua
Code:
local config = {
    demonOakIds = {8288, 8289, 8290, 8291},
    sounds = {
        'MY ROOTS ARE SHARP AS A SCYTHE! FEEL IT?!?',
        'CURSE YOU!',
        'RISE, MINIONS, RISE FROM THE DEAD!!!!',
        'AHHHH! YOUR BLOOD MAKES ME STRONG!',
        'GET THE BONES, HELLHOUND! GET THEM!!',
        'GET THERE WHERE I CAN REACH YOU!!!',
        'ETERNAL PAIN AWAITS YOU! NICE REWARD, HUH?!?!',
        'YOU ARE GOING TO PAY FOR EACH HIT WITH DECADES OF TORTURE!!',
        'ARGG! TORTURE IT!! KILL IT SLOWLY MY MINION!!'
    },
    bonebeastChance = 90,
    bonebeastCount = 4,
    waves = 10,
    questArea = {
        fromPosition = {x = 1017, y = 1207, z = 7},
        toPosition = {x = 1036, y = 1219, z = 7}
    },
    summonPositions = {
        {x = 1025, y = 1210, z = 7},
        {x = 1023, y = 1211, z = 7},
        {x = 1022, y = 1213, z = 7},
        {x = 1024, y = 1216, z = 7},
        {x = 1027, y = 1216, z = 7},
        {x = 1030, y = 1216, z = 7},
        {x = 1032, y = 1213, z = 7},
        {x = 1030, y = 1210, z = 7}
    },
    summons = {
        [8288] = {
            [5] = {'Braindeath', 'Braindeath', 'Braindeath', 'Bonebeast'},
            [10] = {'Betrayed Wraith', 'Betrayed Wraith'}
        },
        [8289] = {
            [5] = {'Lich', 'Lich', 'Lich'},
            [10] = {'Dark Torturer', 'Blightwalker'}
        },
        [8290] = {
            [5] = {'Banshee', 'Banshee', 'Banshee'},
            [10] = {'Grim Reaper'}
        },
        [8291] = {
            [5] = {'Giant Spider', 'Giant Spider', 'Lich'},
            [10] = {'Undead Dragon', 'Hand of Cursed Fate'}
        }
    },
    storages = {
        [8288] = Storage.DemonOak.AxeBlowsBird,--AxeBlowsBird = 8288,
        [8289] = Storage.DemonOak.AxeBlowsLeft,--AxeBlowsLeft = 8289,
        [8290] = Storage.DemonOak.AxeBlowsRight, --AxeBlowsRight = 8290,
        [8291] = Storage.DemonOak.AxeBlowsFace --AxeBlowsFace = 8291
    }
}

local function getRandomSummonPosition()
    return config.summonPositions[math.random(#config.summonPositions)]
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray(config.demonOakIds, target.itemid) then
        return true
    end

    local totalProgress = 0
    for k,v in pairs(config.storages) do
        totalProgress = totalProgress + math.max(0, player:getStorageValue(v))
    end

    local spectators, hasMonsters = Game.getSpectators(DEMON_OAK_POSITION, false, false, 9, 9, 6, 6), false
    for i = 1, #spectators do
        if spectators[i]:isMonster() then
            hasMonsters = true
            break
        end
    end

    local isDefeated = totalProgress == (#config.demonOakIds * (config.waves + 1))
    if (config.killAllBeforeCut or isDefeated)
            and hasMonsters then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You need to kill all monsters first.')
        return true
    end

    if isDefeated then
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Tell Oldrak about your great victory against the demon oak.')
        player:setStorageValue(Storage.DemonOak.Done, 1)
        player:setStorageValue(Storage.DemonOak.Progress, 3)
        return true
    end

    local cStorage = config.storages[target.itemid]
    local progress = math.max(player:getStorageValue(cStorage), 1)
    if progress >= config.waves + 1 then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end

    local isLastCut = totalProgress == (#config.demonOakIds * (config.waves + 1) - 1)
    local summons = config.summons[target.itemid]
    if summons and summons[progress] then
        -- Summon a single demon on the last hit
        if isLastCut then
            Game.createMonster('Demon', getRandomSummonPosition(), false, true)

        -- Summon normal monsters otherwise
        else
            for i = 1, #summons[progress] do
                Game.createMonster(summons[progress][i], getRandomSummonPosition(), false, true)
            end
        end

    -- if it is not the 5th or 10th there is only a chance to summon bonebeasts
    elseif math.random(100) >= config.bonebeastChance then
        for i = 1, config.bonebeastCount do
            Game.createMonster('Bonebeast', getRandomSummonPosition(), false, true)
        end
    end

    player:say(isLastCut and 'HOW IS THAT POSSIBLE?!? MY MASTER WILL CRUSH YOU!! AHRRGGG!' or config.sounds[math.random(#config.sounds)], TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    toPosition:sendMagicEffect(CONST_ME_DRAWBLOOD)
    player:setStorageValue(cStorage, progress + 1)
    player:say('-krrrrak-', TALKTYPE_MONSTER_YELL, false, player, toPosition)
    doTargetCombatHealth(0, player, COMBAT_EARTHDAMAGE, -170, -210, CONST_ME_BIGPLANTS)
    return true
end

DemonOakChest.lua
Code:
local chests = {
    [9008] = {itemid = 2495, count = 1},
    [9009] = {itemid = 8905, count = 1},
    [9010] = {itemid = 8918, count = 1},
    [9011] = {itemid = 8851, count = 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if chests[item.uid] then
        if player:getStorageValue(Storage.DemonOak.Done) ~= 2 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
            return true
        end

        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
            local article = itemType:getArticle()
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end

        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(Storage.DemonOak.Done, 3)
    end

    return true
end

DemonOakGravestone.lua
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.DemonOak.Done) == 2 then
        player:teleportTo(DEMON_OAK_REWARDROOM_POSITION)
        DEMON_OAK_REWARDROOM_POSITION:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end
end


Libs.lua
Code:
dofile('data/lib/demonOakQuest.lua')


DemonOakQuest.lua
Code:
DEMON_OAK_POSITION = Position(1027, 1213, 7)
DEMON_OAK_KICK_POSITION = Position(1027, 1202, 7)
DEMON_OAK_ENTER_POSITION = Position(1027, 1209, 7)
DEMON_OAK_REWARDROOM_POSITION = Position(1055, 1221, 8)



Code:
<!-- Demon Oak Quest -->
    <movevent event="StepIn" uniqueid="9000" script="quests/demon oak/entrance.lua" />
    <movevent event="StepIn" itemid="8292" script="quests/demon oak/areaDamage.lua" />
    <movevent event="StepIn" fromuid="9001" touid="9005" script="quests/demon oak/squares.lua" />
areaDamage.lua
Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if math.random(24) == 1 then
        doTargetCombatHealth(0, player, COMBAT_EARTHDAMAGE, -270, -310, CONST_ME_BIGPLANTS)
    end
    return true
end


entrance.lua
Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getStorageValue(Storage.DemonOak.Done) >= 1 then
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    if player:getLevel() < 120 then
        player:say("LEAVE LITTLE FISH, YOU ARE NOT WORTH IT!", TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    if player:getStorageValue(Storage.DemonOak.Squares) == 5 and #Game.getSpectators(DEMON_OAK_POSITION, false, true, 9, 9, 6, 6) == 0 then
        player:teleportTo(DEMON_OAK_ENTER_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:setStorageValue(Storage.DemonOak.Progress, 1)
        player:say("I AWAITED YOU! COME HERE AND GET YOUR REWARD!", TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    else
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    end
    return true
end

squares.lua
Code:
local voices = {
    'Release me and you will be rewarded greatefully!',
    'What is this? Demon Legs lying here? Someone might have lost them!',
    'I\'m trapped, come here and free me fast!!',
    'I can bring your beloved back from the dead, just release me!',
    'What a nice shiny golden armor. Come to me and you can have it!',
    'Find a way in here and release me! Pleeeease hurry!',
    'You can have my demon set, if you help me get out of here!'
}

local startUid = 9000
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local status = math.max(player:getStorageValue(Storage.DemonOak.Squares), 0)
    if item.uid - startUid == status + 1 then
        player:setStorageValue(Storage.DemonOak.Squares, status + 1)
        player:say(voices[math.random(#voices)], TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    end
    return true
end


try this one.

Lua:
local config = {
    demonOakIds = {8288, 8289, 8290, 8291},
    sounds = {
        'MY ROOTS ARE SHARP AS A SCYTHE! FEEL IT?!?',
        'CURSE YOU!',
        'RISE, MINIONS, RISE FROM THE DEAD!!!!',
        'AHHHH! YOUR BLOOD MAKES ME STRONG!',
        'GET THE BONES, HELLHOUND! GET THEM!!',
        'GET THERE WHERE I CAN REACH YOU!!!',
        'ETERNAL PAIN AWAITS YOU! NICE REWARD, HUH?!?!',
        'YOU ARE GOING TO PAY FOR EACH HIT WITH DECADES OF TORTURE!!',
        'ARGG! TORTURE IT!! KILL IT SLOWLY MY MINION!!'
    },
    bonebeastChance = 90,
    bonebeastCount = 4,
    waves = 10,
    questArea = {
        fromPosition = {x = 32706, y = 32345, z = 7},
        toPosition = {x = 32725, y = 32357, z = 7}
    },
    summonPositions = {
        {x = 32714, y = 32348, z = 7},
        {x = 32712, y = 32349, z = 7},
        {x = 32711, y = 32351, z = 7},
        {x = 32713, y = 32354, z = 7},
        {x = 32716, y = 32354, z = 7},
        {x = 32719, y = 32354, z = 7},
        {x = 32721, y = 32351, z = 7},
        {x = 32719, y = 32348, z = 7}
    },
    summons = {
        [8288] = {
            [5] = {'Spectre', 'Blightwalker', 'Braindeath', 'Demon'},
            [10] = {'Betrayed Wraith', 'Betrayed Wraith'}
        },
        [8289] = {
            [5] = {'Plaguesmith', 'Plaguesmith', 'Blightwalker'},
            [10] = {'Dark Torturer', 'Blightwalker'}
        },
        [8290] = {
            [5] = {'Banshee', 'Plaguesmith', 'Hellhound'},
            [10] = {'Grim Reaper'}
        },
        [8291] = {
            [5] = {'Plaguesmith', 'Hellhound', 'Hellhound'},
            [10] = {'Undead Dragon', 'Hand of Cursed Fate'}
        }
    },
    storages = {
        [8288] = Storage.DemonOak.AxeBlowsBird,
        [8289] = Storage.DemonOak.AxeBlowsLeft,
        [8290] = Storage.DemonOak.AxeBlowsRight,
        [8291] = Storage.DemonOak.AxeBlowsFace
    }
}

local function getRandomSummonPosition()
    return config.summonPositions[math.random(#config.summonPositions)]
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray(config.demonOakIds, target.itemid) then
        return true
    end

    local totalProgress = 0
    for k,v in pairs(config.storages) do
        totalProgress = totalProgress + math.max(0, player:getStorageValue(v))
    end

    local spectators, hasMonsters = Game.getSpectators(DEMON_OAK_POSITION, false, false, 9, 9, 6, 6), false
    for i = 1, #spectators do
        if spectators[i]:isMonster() then
            hasMonsters = true
            break
        end
    end

    local isDefeated = totalProgress == (#config.demonOakIds * (config.waves + 1))
    if (config.killAllBeforeCut or isDefeated)
            and hasMonsters then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You need to kill all monsters first.')
        return true
    end

    if isDefeated then
        player:teleportTo(DEMON_OAK_KICK_POSITION)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Tell Oldrak about your great victory against the demon oak.')
        player:setStorageValue(Storage.DemonOak.Done, 1)
        player:setStorageValue(Storage.DemonOak.Progress, 3)
        return true
    end

    local cStorage = config.storages[target.itemid]
    local progress = math.max(player:getStorageValue(cStorage), 1)
    if progress >= config.waves + 1 then
        toPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end

    local isLastCut = totalProgress == (#config.demonOakIds * (config.waves + 1) - 1)
    local summons = config.summons[target.itemid]
    if summons and summons[progress] then
        -- Summon a single demon on the last hit
        if isLastCut then
            Game.createMonster('Demon', getRandomSummonPosition(), false, true)

        -- Summon normal monsters otherwise
        else
            for i = 1, #summons[progress] do
                Game.createMonster(summons[progress][i], getRandomSummonPosition(), false, true)
            end
        end

    -- if it is not the 5th or 10th there is only a chance to summon bonebeasts
    elseif math.random(100) >= config.bonebeastChance then
        for i = 1, config.bonebeastCount do
            Game.createMonster('Bonebeast', getRandomSummonPosition(), false, true)
        end
    end

    player:say(isLastCut and 'HOW IS THAT POSSIBLE?!? MY MASTER WILL CRUSH YOU!! AHRRGGG!' or config.sounds[math.random(#config.sounds)], TALKTYPE_MONSTER_YELL, false, player, DEMON_OAK_POSITION)
    toPosition:sendMagicEffect(CONST_ME_DRAWBLOOD)
    player:setStorageValue(cStorage, progress + 1)
    player:say('-krrrrak-', TALKTYPE_MONSTER_YELL, false, player, toPosition)
    doTargetCombatHealth(0, player, COMBAT_EARTHDAMAGE, -170, -210, CONST_ME_BIGPLANTS)
    return true
end
 
It's probably copied from ORTS.
And a tip is to not remove it, if you are writing a server from scratch or adding new things it's better to use a lib file for storages, easier to see what free values you have and if you need to change them you just have to edit 1 file insted of 1-10 files that use that value.
 
Back
Top