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

Distinctive reward chests TFS1.4

DarkLua

New Member
Joined
Apr 29, 2019
Messages
24
Reaction score
3
Hello,

Wondering how to create multiple unique reward chests on TFS1.4

When inserting a chest(uid=1740) in RME with propeties: aid - 0 , uid - reward item.

The first chest will give the item with the expected results.

But if another identical chest with the same settings is inserted - it will prompt the chest is empty.

How do I distinct one chest from another?

Many thanks.
 
If i understand it correctly; you are giving them the same IDs and u've already opened the first chest, with the same character you go and open the other chest with the same IDs and it prompts empty?

To answer this shortly: Each quest (reward chests), should have their OWN unique ID. Unless it's a quest similiar to Annihilator where you want to limit the player so that one can only open one of the three chests. If you are making seperate quests, they need to have different Unique IDs.
 
with a little bit of changes you can use the "old" system:

by old I mean, aid 2000 + uid + reward inside chest

just remove unwanted stuff
Thank you for the prompt answer.
And how to you register old action 2000 on the new actions.xml flow?

Tried adding"<action actionid="2000" script="quests/system.lua" />" in actions.xml like in previous versions, but it didn't work/
It seems like actions are attached to an "itemid" instead of a call function.

*EDIT

I've removed previous "Quests" lines from actions.xml and added this:
<action actionid="2000" script="quests/system.lua" />

Edited system.lua like this:
Lua:
local specialQuests = {
    [2215] = PlayerStorageKeys.AnnihilatorDone,

}

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


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 tutorialIds[storage] then
        player:sendTutorial(tutorialIds[storage])
        if item.uid == 50080 then
            player:setStorageValue(PlayerStorageKeys.RookgaardTutorialIsland.SantiagoNpcGreetStorage, 3)
        end
    end

    if table.contains(hotaQuest, item.uid) then
        if player:getStorageValue(PlayerStorageKeys.TheAncientTombs.DefaultStart) ~= 1 then
            player:setStorageValue(PlayerStorageKeys.TheAncientTombs.DefaultStart, 1)
        end
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. result .. '.')
    player:setStorageValue(storage, 1)
    return true
end

It seems like chests with previously rewarded items from new chests still seem to be empty.
Furthermore, Tried to open a chest with these settings:
aid: 2000 , unique id: 2570
Which should reward with a "rolling pin", instead i was rewarded with a chest.
I'm missing something.. don't I?
 
Last edited:
Thank you for the prompt answer.
And how to you register old action 2000 on the new actions.xml flow?

Tried adding"<action actionid="2000" script="quests/system.lua" />" in actions.xml like in previous versions, but it didn't work/
It seems like actions are attached to an "itemid" instead of a call function.

*EDIT

I've removed previous "Quests" lines from actions.xml and added this:
<action actionid="2000" script="quests/system.lua" />

Edited system.lua like this:
Lua:
local specialQuests = {
    [2215] = PlayerStorageKeys.AnnihilatorDone,

}

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


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 tutorialIds[storage] then
        player:sendTutorial(tutorialIds[storage])
        if item.uid == 50080 then
            player:setStorageValue(PlayerStorageKeys.RookgaardTutorialIsland.SantiagoNpcGreetStorage, 3)
        end
    end

    if table.contains(hotaQuest, item.uid) then
        if player:getStorageValue(PlayerStorageKeys.TheAncientTombs.DefaultStart) ~= 1 then
            player:setStorageValue(PlayerStorageKeys.TheAncientTombs.DefaultStart, 1)
        end
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. result .. '.')
    player:setStorageValue(storage, 1)
    return true
end

It seems like chests with previously rewarded items from new chests still seem to be empty.
Furthermore, Tried to open a chest with these settings:
aid: 2000 , unique id: 2570
Which should reward with a "rolling pin", instead i was rewarded with a chest.
I'm missing something.. don't I?

aid: 2000
uid: any number (it will be used as storage)
and inside the chest you put the reward items you want quest to give
 
aid: 2000
uid: any number (it will be used as storage)
and inside the chest you put the reward items you want quest to give
Yeah, I've tried it.
It seems like it still won't give you same item twice even from deferent reward chest + it has a bug that it will reward you a chest sometimes instead of the reward's UID.

I think the default script is more stable, but yet if you found a solution for multiple unique rewards from different chests, Id like to hear about it!
Thanks.
 
try this one:

Lua:
local specialQuests = {
    [2215] = PlayerStorageKeys.AnnihilatorDone
}

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

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