• 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.3] 8.6 Actions -> quest reward from chests and other containers

ivvanek

New Member
Joined
Mar 24, 2009
Messages
113
Reaction score
3
I have inspired with the following thread:
TFS 1.X+ - QUEST SCRIPT REQUEST (https://otland.net/threads/quest-script-request.270272/#post-2605953)
and

I have on my map editor many chests and other containers with actionid=2000 and itemid reward uniqueid=1789 (for example) and when i open chests with actionid=2000 for reward i get chest (it depends which cointainter is reward box)

I have trying with this scripts, i make a file actions/scripts/quests.lua

quests2.lua:
Code:
local specialQuests = {
    [2001] = 30015 --Annihilator
}

local questsExperience = {
    [30015] = 10000
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = specialQuests[item:getActionId()]
    if not storage then
        storage = item:getUniqueId()
        if storage > 65535 then
            return false
        end
    end

    if player:getStorageValue(storage) > 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end


    local itemType = ItemType(item:getId())
    local container = Container(item.uid)
    local playerCap = player:getFreeCapacity() / 100
    local items = {}
    local rewardWeight = 0

    if itemType:isContainer() == true then
        items = container:getItems()
        rewardWeight = items[2]

        if playerCap < rewardWeight then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. items[1][1]:getArticle() .. ' ' .. items[1][1]:getName() .. ' weighing ' .. rewardWeight .. ' oz it\'s too heavy.')
            return true
        end

        items = items[1]
        size = table.maxn(items)

        if size == 1 then
            local item = items[1]
            local count = item:getCount()
            local rewardContainer = Container(item.uid)
      

            if rewardContainer ~= nil then
                bag = player:addItem(item:getId(), 1)
                local rewardItems = rewardContainer:getItems()[1]

                for i = 1, #rewardItems do
                    bag:addItem(rewardItems[i]:getId(), rewardItems[i]:getCount())
                end
            else
                player:addItem(item:getId(), count)
            end
  
            player:setStorageValue(storage, 1)
      
            if count > 1 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. count .. ' ' .. item:getPluralName() .. '.')
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. item:getName() .. '.')
            end

        end
    end

    return true
end

added to actions.xml
Code:
    <action itemid="2000" script="quests/quests2.lua" />
        <action itemid="2001" script="quests/quests2.lua" />

And when i click on the chest it will give me a chest to my backpack, when clicking on skeleton body to get reward i get skeleton body in my backpack too...

What's wrong?
 
Last edited:
You need to add the rewards into the chest in map editor.
The unique id is not the item reward, its the storage it uses to store it, and has nothing to do with the reward for the regular aid 2000.
 
Last edited:
I will try it what you say and give you a feedback.

but i have found in my action.xml and dont know if i have to disable it or keep enabled.
Code:
    <action actionid="2000" script="quests/system.lua" />
    <action actionid="2016" script="quests/system.lua" />
    <action actionid="2215" script="quests/system.lua" />

and system.lua
Code:
local specialQuests = {
    [2215] = Storage.AnnihilatorDone,
    [2016] = Storage.DreamersChallenge.Reward,
    [10544] = Storage.PitsOfInferno.WeaponReward,
    [12513] = Storage.thievesGuild.Reward,
    [12374] = Storage.WrathoftheEmperor.mainReward,
    [26300] = Storage.SvargrondArena.RewardGreenhorn,
    [27300] = Storage.SvargrondArena.RewardScrapper,
    [28300] = Storage.SvargrondArena.RewardWarlord
}

local questsExperience = {
    [2217] = 1 -- dummy values
}

local questLog = {
    [9130] = Storage.hiddenCityOfBeregar.DefaultStart
}

local tutorialIds = {
    [50080] = 5,
    [50082] = 6,
    [50084] = 10,
    [50086] = 11
}

local hotaQuest = {12102, 12103, 12104, 12105, 12106, 12107}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = specialQuests[item.actionid]
    if not storage then
        storage = item.uid
        if storage > 65535 then
            return false
        end
    end

    if player:getStorageValue(storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'The ' .. ItemType(item.itemid):getName() .. ' is empty.')
        return true
    end

    local items, reward = {}
    local size = item:isContainer() and item:getSize() or 0
    if size == 0 then
        reward = item:clone()
    else
        local container = Container(item.uid)
        for i = 0, container:getSize() - 1 do
            items[#items + 1] = container:getItem(i):clone()
        end
    end

    size = #items
    if size == 1 then
        reward = items[1]:clone()
    end

    local result = ''
    if reward then
        local ret = ItemType(reward.itemid)
        if ret:isRune() then
            result = ret:getArticle() .. ' ' ..  ret:getName() .. ' (' .. reward.type .. ' charges)'
        elseif ret:isStackable() and reward:getCount() > 1 then
            result = reward:getCount() .. ' ' .. ret:getPluralName()
        elseif ret:getArticle() ~= '' then
            result = ret:getArticle() .. ' ' .. ret:getName()
        else
            result = ret:getName()
        end
    else
        if size > 20 then
            reward = Game.createItem(item.itemid, 1)
        elseif size > 8 then
            reward = Game.createItem(1988, 1)
        else
            reward = Game.createItem(1987, 1)
        end

        for i = 1, size do
            local tmp = items[i]
            if reward:addItemEx(tmp) ~= RETURNVALUE_NOERROR then
                print('[Warning] QuestSystem:', 'Could not add quest reward to container')
            end
        end
        local ret = ItemType(reward.itemid)
        result = ret:getArticle() .. ' ' .. ret:getName()
    end

    if player:addItemEx(reward) ~= RETURNVALUE_NOERROR then
        local weight = reward:getWeight()
        if player:getFreeCapacity() < weight then
            player:sendCancelMessage(string.format('You have found %s weighing %.2f oz. You have no capacity.', result, (weight / 100)))
        else
            player:sendCancelMessage('You have found ' .. result .. ', but you have no room to take it.')
        end
        return true
    end

    if questsExperience[storage] then
        player:addExperience(questsExperience[storage], true)
    end

    if questLog[storage] then
        player:setStorageValue(questLog[storage], 1)
    end

    if tutorialIds[storage] then
        player:sendTutorial(tutorialIds[storage])
        if item.uid == 50080 then
            player:setStorageValue(Storage.RookgaardTutorialIsland.SantiagoNpcGreetStorage, 3)
        end
    end

    if isInArray(hotaQuest, item.uid) then
        if player:getStorageValue(Storage.TheAncientTombs.DefaultStart) ~= 1 then
            player:setStorageValue(Storage.TheAncientTombs.DefaultStart, 1)
        end
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. result .. '.')
    player:setStorageValue(storage, 1)
    return true
end
[/ICODE]
 
Back
Top