• 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+ Quest Chest 10.98 TFS 1.3 PROBLEM

jo31

New Member
Joined
May 24, 2010
Messages
70
Reaction score
1
Location
Sweden
Hello Otlands people!

i have write a code so all my chest on the server that have actionid "2000" and random unique id will be rewarded when they open the chest.
But the problem is i dont get any error in the console and it will only open the chest. I hope anyone could help me with a clean code

XML:
    <action actionid="2000" script="quests.lua" /> <!-- quests -->

Lua:
local quest = {
    [2000] = Reward
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if quest == 2000 then
        return false
    end

    if quest[item.actionid] then
        if player:getStorageValue(quest) == 1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
            return true
        end

        local chest = quest[item.actionid]
        local itemType = ItemType(chest.itemid)
        if itemType then
            local itemWeight = itemType:getWeight()
            local playerCap = player:getFreeCapacity()
            if playerCap >= itemWeight then
                local textm = itemType:getArticle()
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#textm > 0 and textm .. ' ' or '') .. itemType:getName() .. '.')
                player:addItem(chest.itemid, chest.count)
                player:setStorageValue(item.uid, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
            end
        end
    end

    return true
end
 
Solution
No you don't need to, all you have to do is write the id of item in chest's unique id by using map editor
Example : If this chest gonna give you a Royal helmet then you'll put 2498 as UniqueID which is the id of Royal Helmet in items.xml
That is not how its supposed to work on TFS 1.3, All you should do is putting the item id number as chest unique id then you'll get rewarded with that item.
Or you are trying to make different quest chest system? explain more if so.
 
So i dont need to add The Item into The chest in map editor? Only The unique id??
That is not how its supposed to work on TFS 1.3, All you should do is putting the item id number as chest unique id then you'll get rewarded with that item.
Or you are trying to make different quest chest system? explain more if so.
Post automatically merged:

That is not how its supposed to work on TFS 1.3, All you should do is putting the item id number as chest unique id then you'll get rewarded with that item.
Or you are trying to make different quest chest system? explain more if so.
I have only had 0.4/8.6 ots before😁
 
Last edited:
No you don't need to, all you have to do is write the id of item in chest's unique id by using map editor
Example : If this chest gonna give you a Royal helmet then you'll put 2498 as UniqueID which is the id of Royal Helmet in items.xml
 
Solution
How about when its more than one item in the chest?
Like a bag with 3 items?
No you don't need to, all you have to do is write the id of item in chest's unique id by using map editor
Example : If this chest gonna give you a Royal helmet then you'll put 2498 as UniqueID which is the id of Royal Helmet in items.xml
 
 
I'm working on migrating a 0.4 datapack to 1.3 and I think its pretty useful to have both logic working because my map already had tons of quests working the old way. Here is my quest_system.lua so you can use it on items with action id 2000 and still use the actual 1.3 system on new quests you add.

Lua:
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


    if itemType:isContainer() == true then
        items = container:getItems()
        rewardWeight = items[2]
        local itemType = ItemType(item:getId())
        local container = Container(item.uid)
        local playerCap = player:getFreeCapacity() / 100
        local items = {}
        local rewardWeight = 0
       
        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

Also, I can see yours isn't working firstly because of your first if statement.

Code:
if quest == 2000 then
        return false
end

You are testing quest against a number when in reality it as an array.
 
I'm working on migrating a 0.4 datapack to 1.3 and I think its pretty useful to have both logic working because my map already had tons of quests working the old way. Here is my quest_system.lua so you can use it on items with action id 2000 and still use the actual 1.3 system on new quests you add.

Lua:
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


    if itemType:isContainer() == true then
        items = container:getItems()
        rewardWeight = items[2]
        local itemType = ItemType(item:getId())
        local container = Container(item.uid)
        local playerCap = player:getFreeCapacity() / 100
        local items = {}
        local rewardWeight = 0
      
        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

Also, I can see yours isn't working firstly because of your first if statement.

Code:
if quest == 2000 then
        return false
end

You are testing quest against a number when in reality it as an array.


I really dont understand how this works??

I tried put the UID in map editor both with and without item added into the chest.
While Action ID is 0.

How do i make quests work???
 
I'm working on migrating a 0.4 datapack to 1.3 and I think its pretty useful to have both logic working because my map already had tons of quests working the old way. Here is my quest_system.lua so you can use it on items with action id 2000 and still use the actual 1.3 system on new quests you add.

Lua:
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


    if itemType:isContainer() == true then
        items = container:getItems()
        rewardWeight = items[2]
        local itemType = ItemType(item:getId())
        local container = Container(item.uid)
        local playerCap = player:getFreeCapacity() / 100
        local items = {}
        local rewardWeight = 0
      
        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

Also, I can see yours isn't working firstly because of your first if statement.

Code:
if quest == 2000 then
        return false
end

You are testing quest against a number when in reality it as an array.

What do i write in action.xml with your script?

<action actionid="2000" script="quests.lua" /> <!-- quests -->
??
 
Code:
stack traceback:
        [C]: in function 'index'
        data/actions/scripts/quest.lua:25: in function <data/actions/scripts/quest.lua:9>

Lua Script Error: [Action Interface]
data/actions/scripts/quest.lua:onUse
data/actions/scripts/quest.lua:25: attempt to index global 'itemType' (a nil value)
stack traceback:
        [C]: in function 'index'
        data/actions/scripts/quest.lua:25: in function <data/actions/scripts/quest.lua:9>
Post automatically merged:

I get this error in console
 
Sorry, for some reason some parts of that script were missing. :O

Try this.
Lua:
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
 
Last edited:
Back
Top