• 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 Task Sys... (Need Some Help Here)

duuh duuh

New Member
Joined
Jul 13, 2011
Messages
43
Reaction score
0
Well, im making a global project and I was wondering how can I fix this issue here.. I want the Demon Oak quest same as tibia-rl... When player obtain 100 task points and finish the Demons task (6666 monsters), the NPC Grizzly Adams give him a Holy Icon and then following to the wiki tutorial...

Issues: Grizzly Adams isn't finishing the Demon Task and have no Holy Icon... And Oak quest it's buggy! (follow scripts)...

grizzly adams (1st half of script)
Code:
grizzly adams.lua
[CODE]local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local choose = {}
local cancel = {}
local available = {}

local grizzlyAdamsConfig = {
    ranks = {
        --NOTE: The variable 'name' is not necessary to be declared. I let it so people who wants to change the script will now wich item is each one.
        huntsMan_rank = {
            {id=11208, buy=0, sell=50, name='antlers'},
            {id=10549, buy=0, sell=100, name='bloody pincers'},
            {id=11183, buy=0, sell=35, name='crab pincers'},
            {id=10573, buy=0, sell=55, name='cyclops toe'},
            {id=10564, buy=0, sell=30, name='frosty ear of a troll'},
            {id=11193, buy=0, sell=600, name='hydra head'},
            {id=11366, buy=0, sell=80, name='lancer beetle shell'},
            {id=10578, buy=0, sell=420, name='mutated bat ear'},
            {id=11222, buy=0, sell=400, name='sabretooth'},
            {id=11367, buy=0, sell=20, name='sandcrawler shell'},
            {id=10547, buy=0, sell=280, name='scarab pincers'},
            {id=11365, buy=0, sell=60, name='terramite legs'},
            {id=11363, buy=0, sell=170, name='terramite shell'},
            {id=11184, buy=0, sell=95, name='terrorbird beak'},

            {id=7398, buy=0, sell=500, name='cyclops trophy'},
            {id=11315, buy=0, sell=15000, name='draken trophy'},
            {id=11336, buy=0, sell=8000, name='lizard trophy'},
            {id=7401, buy=0, sell=500, name='minotaur trophy'}
        },

        bigGameHunter_rank = {
            {id=7397, buy=0, sell=3000, name='deer trophy'},
            {id=7400, buy=0, sell=3000, name='lion trophy'},
            {id=7394, buy=0, sell=3000, name='wolf trophy'}
        },

        trophyHunter_rank = {
            {id=7393, buy=0, sell=40000, name='demon trophy'},
            {id=7396, buy=0, sell=20000, name='behemoth trophy'},
            {id=7399, buy=0, sell=10000, name='dragon lord trophy'},

            {id=10518, buy=1000, sell=0, name='demon backpack'},
        },
    }
}

local items, data = {}
for i = 1, #grizzlyAdamsConfig.ranks.huntsMan_rank do
    data = grizzlyAdamsConfig.ranks.huntsMan_rank[i]
    items[data.id] = {id = data.id, buy = data.buy, sell = data.sell, name = ItemType(data.id):getName():lower()}
end
for i = 1, #grizzlyAdamsConfig.ranks.bigGameHunter_rank do
    data = grizzlyAdamsConfig.ranks.bigGameHunter_rank[i]
    items[data.id] = {id = data.id, buy = data.buy, sell = data.sell, name = ItemType(data.id):getName():lower()}
end
for i = 1, #grizzlyAdamsConfig.ranks.trophyHunter_rank do
    data = grizzlyAdamsConfig.ranks.trophyHunter_rank[i]
    items[data.id] = {id = data.id, buy = data.buy, sell = data.sell, name = ItemType(data.id):getName():lower()}
end

local function greetCallback(cid)
    local player = Player(cid)
    if player:getStorageValue(JOIN_STOR) == -1 then
        npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|. Would you like to join the \'Paw and Fur - Hunting Elite\'?')
    else
        npcHandler:setMessage(MESSAGE_GREET, 'Welcome back old chap. What brings you here this time?')
    end
    return true
end

local function getTradeItems(t)
    local list, obj = {}
    for i = 1, #t do
        obj = t[i]
        list[obj.id] = {id = obj.id, buy = obj.buy, sell = obj.sell, name = ItemType(obj.id):getName():lower()}
    end
    return list
end

local function joinTables(old, new)
    for k, v in pairs(new) do
        old[k] = v
    end
    return old
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then return false end

    local player = Player(cid)
    if msgcontains('trade', msg) then
        local tradeItems = {}
        if player:getPawAndFurRank() >= 2 then
            tradeItems = grizzlyAdamsConfig.ranks.huntsMan_rank
            if player:getPawAndFurRank() == 4 then
                tradeItems = joinTables(tradeItems, grizzlyAdamsConfig.ranks.bigGameHunter_rank)
            elseif player:getPawAndFurRank() == 5 or player:getPawAndFurRank() == 6 then
                tradeItems = joinTables(tradeItems, grizzlyAdamsConfig.ranks.bigGameHunter_rank)
                tradeItems = joinTables(tradeItems, grizzlyAdamsConfig.ranks.trophyHunter_rank)
            end
            openShopWindow(cid, tradeItems, onBuy, onSell)
            return npcHandler:say('It\'s my offer.', cid)
        else
            return npcHandler:say('You don\'t have any rank.', cid)
        end
    elseif (msgcontains('join', msg) or msgcontains('yes', msg))
            and npcHandler.topic[cid] == 0
            and player:getStorageValue(JOIN_STOR) ~= 1 then
        player:setStorageValue(JOIN_STOR, 1)
        npcHandler:say('Great!, now you can start tasks.', cid) --I'm not sure if this is as real tibia. I let this piece of code because it was in the original file.
    elseif isInArray({'tasks', 'task', 'mission'}, msg:lower()) then
        local can = player:getTasks()
        if player:getStorageValue(JOIN_STOR) == -1 then
            return npcHandler:say('You\'ll have to {join}, to get any {tasks}.',cid)
        end
        if #can > 0 then
            local text = ''
            local sep = ', '
            table.sort(can, function(a, b) return a < b end)
            local t = 0
            local id
            for i = 1, #can do
                id = can[i]
                t = t + 1
                if t == #can - 1 then
                    sep = ' and '
                elseif t == #can then
                    sep = '.'
                end
                text = text .. '{' .. (tasks[id].name or tasks[id].raceName) .. '}' .. sep
            end
            npcHandler:say('The current task' .. (#can > 1 and 's' or '') .. ' that you can choose ' .. (#can > 1 and 'are' or 'is') .. ' ' .. text, cid)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say('I don\'t have any task for you right now.', cid)
        end
    elseif msg ~= '' and player:canStartTask(msg) then
        if #player:getStartedTasks() >= tasksByPlayer then
            npcHandler:say('Sorry, but you already started ' .. tasksByPlayer .. ' tasks. You can check their {status} or {cancel} a task.', cid)
            return true
        end
 
grizzly adams (2nd half of script)
Code:
        local task = getTaskByName(msg)
        if task and player:getStorageValue(QUESTSTORAGE_BASE + task) > 0 then
            return false
        end
        npcHandler:say('In this task you must defeat ' .. tasks[task].killsRequired .. ' ' .. tasks[task].raceName .. '. Are you sure that you want to start this task?', cid)
        choose[cid] = task
        npcHandler.topic[cid] = 1
    elseif msg:lower() == 'yes' and npcHandler.topic[cid] == 1 then
        player:setStorageValue(QUESTSTORAGE_BASE + choose[cid], 1)
        player:setStorageValue(KILLSSTORAGE_BASE + choose[cid], 0)
        npcHandler:say('Excellent! You can check the {status} of your task saying {report} to me. Also you can {cancel} tasks to.', cid)
        choose[cid] = nil
        npcHandler.topic[cid] = 0
    elseif msgcontains('status', msg) then
        local started = player:getStartedTasks()
        if started and #started > 0 then
            local text = ''
            local sep = ', '
            table.sort(started, (function(a, b) return (a < b) end))
            local t = 0
            local id
            for i = 1, #started do
                id = started[i]
                t = t + 1
                if t == #started - 1 then
                    sep = ' and '
                elseif t == #started then
                    sep = '.'
                end
                text = text .. 'Task name: ' .. tasks[id].raceName .. '. Current kills: ' .. player:getStorageValue(KILLSSTORAGE_BASE + id) .. '.\n'
            end
            npcHandler:say({'The status of your current tasks is:\n' .. text}, cid)
        else
            npcHandler:say('You haven\'t started any task yet.', cid)
        end
    elseif msgcontains('report', msg) then
        local started = player:getStartedTasks()
        local finishedAtLeastOne = false
        local finished = 0
        if started and #started > 0 then
            local id, reward
            for i = 1, #started do
                id = started[i]
                if player:getStorageValue(KILLSSTORAGE_BASE + id) >= tasks[id].killsRequired then
                    for j = 1, #tasks[id].rewards do
                        reward = tasks[id].rewards[j]
                        local deny = false
                        if reward.storage then
                            if player:getStorageValue(reward.storage[1]) >= reward.storage[2] then
                                deny = true
                            end
                        end
                        if isInArray({REWARD_MONEY, 'money'}, reward.type:lower()) and not deny then
                            player:addMoney(reward.value[1])
                        elseif isInArray({REWARD_EXP, 'exp', 'experience'}, reward.type:lower()) and not deny then
                            player:addExperience(reward.value[1], true)
                        elseif isInArray({REWARD_ACHIEVEMENT, 'achievement', 'ach'}, reward.type:lower()) and not deny then
                            player:addAchievement(reward.value[1])
                        elseif isInArray({REWARD_STORAGE, 'storage', 'stor'}, reward.type:lower()) and not deny then
                            player:setStorageValue(reward.value[1], reward.value[2])
                        elseif isInArray({REWARD_POINT, 'points', 'point'}, reward.type:lower()) and not deny then
                            player:setStorageValue(POINTSSTORAGE, getPlayerTasksPoints(cid) + reward.value[1])
                        elseif isInArray({REWARD_ITEM, 'item', 'items', 'object'}, reward.type:lower()) and not deny then
                            player:addItem(reward.value[1], reward.value[2])
                        end

                        if reward.storage then
                            player:setStorageValue(reward.storage[1], reward.storage[2])
                        end
                    end

                    player:setStorageValue(QUESTSTORAGE_BASE + id, (tasks[id].norepeatable and 2 or 0))
                    player:setStorageValue(KILLSSTORAGE_BASE + id, -1)
                    player:setStorageValue(REPEATSTORAGE_BASE + id, math.max(player:getStorageValue(REPEATSTORAGE_BASE + id), 0))
                    player:setStorageValue(REPEATSTORAGE_BASE + id, player:getStorageValue(REPEATSTORAGE_BASE + id) + 1)
                    finishedAtLeastOne = true
                    finished = finished + 1
                end
            end
            if not finishedAtLeastOne then
                local started = player:getStartedTasks()
                if started and #started > 0 then
                    local text = ''
                    local sep = ', '
                    table.sort(started, (function(a, b) return (a < b) end))
                    local t = 0
                    local id
                    for i = 1, #started do
                        id = started[i]
                        t = t + 1
                        if (t == #started - 1) then
                            sep = ' and '
                        elseif (t == #started) then
                            sep = '.'
                        end
                        text = text .. '{' .. (tasks[id].name or tasks[id].raceName) .. '}' .. sep
                    end
                    npcHandler:say('The current task' .. (#started > 1 and 's' or '') .. ' that you started ' .. (#started > 1 and 'are' or 'is') .. ' ' .. text, cid)
                end
            else
 
grizzly adams (3rd half of script)
Code:
                npcHandler:say('Awesome! you finished ' .. (finished > 1 and 'various' or 'a') .. ' task' .. (finished > 1 and 's' or '') .. '. Talk to me again if you want to start a {task}.', cid)
            end
        else
            npcHandler:say('You haven\'t started any task yet.', cid)
        end
    elseif msg:lower() == 'started' then
        local started = player:getStartedTasks()
        if started and #started > 0 then
            local text = ''
            local sep = ', '
            table.sort(started, (function(a, b) return (a < b) end))
            local t = 0
            local id
            for i = 1, #started do
                id = started[i]
                t = t + 1
                if t == #started - 1 then
                    sep = ' and '
                elseif t == #started then
                    sep = '.'
                end
                text = text .. '{' .. (tasks[id].name or tasks[id].raceName) .. '}' .. sep
            end

            npcHandler:say('The current task' .. (#started > 1 and 's' or '') .. ' that you started ' .. (#started > 1 and 'are' or 'is') .. ' ' .. text, cid)
        else
            npcHandler:say('You haven\'t started any task yet.', cid)
        end
    elseif msg:lower() == 'cancel' then
        local started = player:getStartedTasks()
        local task = getTaskByName(msg)
        local text = ''
        local sep = ', '
        table.sort(started, (function(a, b) return (a < b) end))
        local t = 0
        local id
        for i = 1, #started do
            id = started[i]
            t = t + 1
            if t == #started - 1 then
                sep = ' or '
            elseif t == #started then
                sep = '?'
            end
            text = text .. '{' .. (tasks[id].name or tasks[id].raceName) .. '}' .. sep
        end
        if started and #started > 0 then
            npcHandler:say('Cancelling a task will make the counter restart. Which of these tasks you want cancel?' .. (#started > 1 and '' or '') .. ' ' .. text, cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say('You haven\'t started any task yet.', cid)
        end
    elseif getTaskByName(msg) and npcHandler.topic[cid] == 2 and isInArray(getPlayerStartedTasks(cid), getTaskByName(msg)) then
        local task = getTaskByName(msg)
        if player:getStorageValue(KILLSSTORAGE_BASE + task) > 0 then
            npcHandler:say('You currently killed ' .. player:getStorageValue(KILLSSTORAGE_BASE + task) .. '/' .. tasks[task].killsRequired .. ' ' .. tasks[task].raceName .. '. Cancelling this task will restart the count. Are you sure you want to cancel this task?', cid)
        else
            npcHandler:say('Are you sure you want to cancel this task?', cid)
        end
        npcHandler.topic[cid] = 3
        cancel[cid] = task
    elseif getTaskByName(msg) and npcHandler.topic[cid] == 1 and isInArray(getPlayerStartedTasks(cid), getTaskByName(msg)) then
        local task = getTaskByName(msg)
        if player:getStorageValue(KILLSSTORAGE_BASE + task) > 0 then
            npcHandler:say('You currently killed ' .. player:getStorageValue(KILLSSTORAGE_BASE + task) .. '/' .. tasks[task].killsRequired .. ' ' .. tasks[task].raceName .. '.', cid)
        else
            npcHandler:say('You currently killed 0/' .. tasks[task].killsRequired .. ' ' .. tasks[task].raceName .. '.', cid)
        end
        npcHandler.topic[cid] = 0
    elseif msg:lower() == 'yes' and npcHandler.topic[cid] == 3 then
        player:setStorageValue(QUESTSTORAGE_BASE + cancel[cid], -1)
        player:setStorageValue(KILLSSTORAGE_BASE + cancel[cid], -1)
        npcHandler:say('You have cancelled the task ' .. (tasks[cancel[cid]].name or tasks[cancel[cid]].raceName) .. '.', cid)
        npcHandler.topic[cid] = 0
    elseif isInArray({'points', 'rank'}, msg:lower()) then
        if player:getPawAndFurPoints() < 1 then
            npcHandler:say('At this time, you have ' .. player:getPawAndFurPoints() .. ' Paw & Fur points. You ' .. (player:getPawAndFurRank() == 6 and 'are an Elite Hunter' or player:getPawAndFurRank() == 5 and 'are a Trophy Hunter' or player:getPawAndFurRank() == 4 and 'are a Big Game Hunter' or player:getPawAndFurRank() == 3 and 'are a Ranger' or player:getPawAndFurRank() == 2 and 'are a Huntsman' or player:getPawAndFurRank() == 1 and 'are a Member'  or 'haven\'t been ranked yet') .. '.', cid)
        else
            npcHandler:say('At this time, you have ' .. player:getPawAndFurPoints() .. ' Paw & Fur points. You ' .. (player:getPawAndFurRank() == 6 and 'are an Elite Hunter' or player:getPawAndFurRank() == 5 and 'are a Trophy Hunter' or player:getPawAndFurRank() == 4 and 'are a Big Game Hunter' or player:getPawAndFurRank() == 3 and 'are a Ranger' or player:getPawAndFurRank() == 2 and 'are a Huntsman' or player:getPawAndFurRank() == 1 and 'are a Member'  or 'haven\'t been ranked yet') .. '.', cid)
        end
        npcHandler.topic[cid] = 0
    elseif isInArray({'special task'}, msg:lower()) then
        if player:getPawAndFurPoints() >= 90 then -- Tiquandas Revenge 90 points
            if player:getStorageValue(Storage.KillingInTheNameOf.MissionTiquandasRevenge) == 1 then  -- Check if he has already started the task.
                npcHandler:say('You have already started the task. Go find Tiquandas Revenge and take revenge yourself!', cid)
            else
                npcHandler:say({
                    'Have you heard about Tiquandas Revenge? It is said that the jungle itself is alive and takes revenge for all the bad things people have done to it. ...',
                    'I myself believe that there is some truth in this clap trap. Something \'real\' which therefore must have a hideout somewhere. Go find it and take revenge yourself!'
                }, cid)
                player:setStorageValue(Storage.KillingInTheNameOf.TiquandasRevengeTeleport, 1) -- Task needed to enter Tiquandas Revenge TP
                player:setStorageValue(Storage.KillingInTheNameOf.MissionTiquandasRevenge, 1) -- Won't give this task again.
            end
        end
        if player:getPawAndFurPoints() >= 100 then -- Demodras 100 points
            if player:getStorageValue(Storage.KillingInTheNameOf.MissionDemodras) == 1 then  -- Check if he has already started the task.
                npcHandler:say('You have already started the special task. Find Demodras and kill it.', cid)
            else
                npcHandler:say('This task is a very dangerous one. I want you to look for Demodras\' hideout. It might be somewhere under the Plains of Havoc. Good luck, old chap.', cid)
                player:setStorageValue(Storage.KillingInTheNameOf.DemodrasTeleport, 1) -- Task needed to enter Demodras TP
                player:setStorageValue(Storage.KillingInTheNameOf.MissionDemodras, 1) -- Won't give this task again.
            end
        end
        npcHandler.topic[cid] = 0
    end
end

local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
    local player = Player(cid)
    if not ignoreCap and player:getFreeCapacity() < ItemType(items[item].id):getWeight(amount) then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
    end
    if items[item].buy then
        player:removeMoney(amount * items[item].buy)
        player:addItem(items[item].id, amount)
        return player:sendTextMessage(MESSAGE_INFO_DESCR, 'Bought '..amount..'x '..items[item].name..' for '..items[item].buy * amount..' gold coins.')
    end
    return true
end

local function onSell(cid, item, subType, amount, ignoreCap, inBackpacks)
    local player = Player(cid)
    if items[item].sell then
        player:addMoney(items[item].sell * amount)
        player:removeItem(items[item].id, amount)
        return player:sendTextMessage(MESSAGE_INFO_DESCR, 'Sold '..amount..'x '..items[item].name..' for '..items[item].sell * amount..' gold coins.')
    end
    return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'Happy hunting, old chap!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
actions/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 = 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] = {'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,
        [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

actions/demonoakchest.lua
Code:
local chests = {
    [9008] = {itemid = 2495, count = 1},
    [9009] = {itemid = 8905, count = 1},
    [9010] = {itemid = 16111, count = 1},
    [9011] = {itemid = 16112, 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
 
actions/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

globalevents/demonoak.lua
Code:
local questArea = {
    Position(32706, 32345, 7),
    Position(32725, 32357, 7)
}

local sounds = {
    '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!'
}

function onThink(interval, lastExecution)
    local spectators, spectator = Game.getSpectators(DEMON_OAK_POSITION, false, true, 0, 15, 0, 15)
    for i = 1, #spectators do
        spectator = spectators[i]
        if isInRange(spectator:getPosition(), questArea[1], questArea[2]) then
            return true
        end

        spectator:say(sounds[math.random(#sounds)], TALKTYPE_MONSTER_YELL, false, 0, DEMON_OAK_POSITION)
    end
    return true
end

movements/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

movements/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

movements/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
 
oldrak.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)         npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                         npcHandler:onThink() end

keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = "I guard this humble temple as a monument for the order of the nightmare knights."})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = "My name is Oldrak."})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, text = "These plains are not safe for ordinary travellers. It will take heroes to survive here."})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, text = "I can't help you, sorry!"})
keywordHandler:addKeyword({'goshnar'}, StdModule.say, {npcHandler = npcHandler, text = "The greatest necromant who ever cursed our land with the steps of his feet. He was defeated by the nightmare knights."})
keywordHandler:addKeyword({'nightmare'}, StdModule.say, {npcHandler = npcHandler, text = "This ancient order was created by a circle of wise humans who were called 'the dreamers'. The order became extinct a long time ago."})
keywordHandler:addKeyword({'extinct'}, StdModule.say, {npcHandler = npcHandler, text = "Many perished in their battles against evil, some went mad, not able to stand their nightmares any longer. Others were seduced by the darkness."})
keywordHandler:addKeyword({'dreamers'}, StdModule.say, {npcHandler = npcHandler, text = "They learned the ancient art of dreamwalking from some elves they befriended."})
keywordHandler:addKeyword({'dreamwalking'}, StdModule.say, {npcHandler = npcHandler, text = "While the dreamwalkers of the elves experienenced the brightest dreams of pleasure, the humans strangely had dreams of dark omen."})
keywordHandler:addKeyword({'omen'}, StdModule.say, {npcHandler = npcHandler, text = "They dreamed of doom, destruction, talked to dead, tormented souls, and gained unwanted insight into the schemes of darkness."})
keywordHandler:addKeyword({'schemes'}, StdModule.say, {npcHandler = npcHandler, text = "They figured out how to interpret their dark dreams and so could foresee the plans of the dark gods and their minions."})
keywordHandler:addKeyword({'plan'}, StdModule.say, {npcHandler = npcHandler, text = "Using this knowledge they formed an order to thwart these plans, and because they battled their nightmares as brave as knights, they named their order accordingly."})
keywordHandler:addKeyword({'necromant'}, StdModule.say, {npcHandler = npcHandler, text = "It is rumoured to open the entrance to the pits of inferno, also called the nightmare pits. Even if I knew about this secret I wouldn't tell you."})
keywordHandler:addKeyword({'havok'}, StdModule.say, {npcHandler = npcHandler, text = "Before the battles raged across them, they were called the fair plains."})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, text = "That's where we are. The world of Tibia."})
keywordHandler:addKeyword({'god'}, StdModule.say, {npcHandler = npcHandler, text = "They created Tibia and all life on it ... and unlife, too."})
keywordHandler:addKeyword({'unlife'}, StdModule.say, {npcHandler = npcHandler, text = "Beware the foul undead!"})
keywordHandler:addKeyword({'undead'}, StdModule.say, {npcHandler = npcHandler, text = "Beware the foul undead!"})
keywordHandler:addKeyword({'excalibug'}, StdModule.say, {npcHandler = npcHandler, text = "A weapon of myth and legend. It was lost in ancient times ... perhaps lost forever."})
keywordHandler:addKeyword({'hugo'}, StdModule.say, {npcHandler = npcHandler, text = "Ah, the bane of the Plains of Havoc, the hidden beast, the unbeatable foe. I live here for years and I am sure it's only a myth."})
keywordHandler:addKeyword({'yenny'}, StdModule.say, {npcHandler = npcHandler, text = "Yenny, known as the Gentle, was one of most powerfull magicwielders in ancient times and known throughout the world for her mercy and kindness."})
keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, text = "I can offer you the holy tible for a small fee."})
keywordHandler:addKeyword({'trade'}, StdModule.say, {npcHandler = npcHandler, text = "I can offer you the holy tible for a small fee."})
keywordHandler:addKeyword({'sell'}, StdModule.say, {npcHandler = npcHandler, text = "I can offer you the holy tible for a small fee."})
keywordHandler:addKeyword({'buy'}, StdModule.say, {npcHandler = npcHandler, text = "I can offer you the holy tible for a small fee."})
keywordHandler:addKeyword({'have'}, StdModule.say, {npcHandler = npcHandler, text = "I can offer you the holy tible for a small fee."})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, text = "Now, it is |TIME|."})

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    if msgcontains(msg, 'mission') or msgcontains(msg, 'demon oak') then
        if player:getStorageValue(Storage.DemonOak.Done) < 1 and player:getStorageValue(Storage.DemonOak.Progress) < 2 then
            npcHandler:say("How do you know? Did you go into the infested area?", cid)
            npcHandler.topic[cid] = 1
        elseif player:getStorageValue(Storage.DemonOak.Progress) == 2 and player:getStorageValue(Storage.DemonOak.Done) < 1 then
            npcHandler:say("You better don't return here until you've defeated the Demon Oak.", cid)
        elseif player:getStorageValue(Storage.DemonOak.Done) == 1 then
            npcHandler:say({
                "You chopped down the demon oak?!? Unbelievable!! Let's hope it doesn't come back. As long as evil is still existent in the soil of the plains, it won't be over. Still, the demons suffered a setback, that's for sure. ...",
                "For your brave action, I tell you a secret which has been kept for many many years. There is an old house south of the location where you found the demon oak. There should be a grave with the name 'Yesim Adeit' somewhere close by. ...",
                "It belongs to a Daramian nobleman named 'Teme Saiyid'. I knew him well and he told me -almost augured- that someone will come who is worthy to obtain his treasure. I'm sure this 'someone' is you. Good luck in finding it!"
            }, cid)
            player:setStorageValue(Storage.DemonOak.Done, 2)
        end
    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
        if player:getStorageValue(Storage.DemonOak.Progress) == 1 then
            npcHandler:say("A demon oak?!? <mumbles some blessings> May the gods be on our side. You'll need a {hallowed axe} to harm that tree. Bring me a simple {axe} and I'll prepare it for you.",cid)
            player:setStorageValue(Storage.DemonOak.Progress, 2)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("I don't believe a word of it! How rude to lie to a monk!",cid)
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, 'axe') then
        if player:getStorageValue(Storage.DemonOak.Progress) == 2 then
            npcHandler:say("Ahh, you've got an axe. Very good. I can make a hallowed axe out of it. It will cost you... er... a donation of 1,000 gold. Alright?",cid)
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("You have to first talk about {demon oak} or the {mission} before we continue.",cid)
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 2 then
        if player:getStorageValue(Storage.DemonOak.Progress) == 2 then
            if player:getMoney() >= 1000 then
                if player:removeItem(2386, 1) and player:removeMoney(1000) then
                    npcHandler:say("Let's see....<mumbles a prayer>....here we go. The blessing on this axe will be absorbed by all the demonic energy around here. I presume it will not last very long, so better hurry. Actually, I can refresh the blessing as often as you like.",cid)
                    player:addItem(8293, 1)
                    Npc():getPosition():sendMagicEffect(CONST_ME_YELLOWENERGY)
                    npcHandler.topic[cid] = 0
                else
                    npcHandler:say("There is no axe with you.",cid)
                    npcHandler.topic[cid] = 0
                end
            else
                npcHandler:say("There is not enough of money with you.",cid)
                npcHandler.topic[cid] = 0
            end
        end
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say("What a pity! Let me know when you managed to get in there. Maybe I can help you when we know what we are dealing with.",cid)
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 2 then
        npcHandler:say("No then.",cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top Bottom