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

Bag with items quest

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
136
Location
Sweden
Hello guys!

I'm using TFS 1.2 and i need some help with "bag with items quest"
For example, open chest, get a bag with 2 rings in it.
Is it possible to make that using RME or does it have to be scripted?

Thanks in advance.
 
Solution
Sorry for double post, but i get this error when i replace that quests.lua script.
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/quests/quests.lua
data/actions/scripts/quests/quests.lua:2: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/quests/quests.lua:2: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/quests/quests.lua
Try this:
That file has storages from real map, etc...
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = item.uid
  
    if storage > 65535 then
        return false
    end

    if player:getStorageValue(storage) > 0 then...
When you add a bag in a chest container in RME, can you double click on the bag and add items to the bag?
 
Code:
function onUse(player, item, fromPosition, ItemEx, toPosition, isHotkey)
    local user = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if user == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        player:addItem(2160, 1, true) -- 2160 = id, 1 = amount
        elseif user == 1 then
            player:sendCancelMessage("You've already done this quest.")
        end
    return true
end

try this :)

anyone more advanced in scripting than me, feel free to tell me what could be improved in this (tabbing is awful, i know :()
 
Last edited:
Code:
function onUse(player, item, fromPosition, ItemEx, toPosition, isHotkey)
    local user = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if user == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        player:addItem(2160, 1, true) -- 2160 = id, 1 = amount
        elseif user == 1 then
            player:sendCancelMessage("You've already done this quest.")
        end
    return true
end

try this :)

anyone more advanced in scripting than me, feel free to tell me what could be improved in this (tabbing is awful, i know :()
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if storage == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        player:addItem(2160, 1) -- 2160 = id, 1 = amount
    elseif storage == 1 then
        player:sendCancelMessage("You've already done this quest.")
    end
    return true
end
changed itemEx to target in function arguments
the "true" that you put in player:addItem is already true by default
+ fixed tabbing
 
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if storage == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        player:addItem(2160, 1) -- 2160 = id, 1 = amount
    elseif storage == 1 then
        player:sendCancelMessage("You've already done this quest.")
    end
    return true
end
changed itemEx to target in function arguments
the "true" that you put in player:addItem is already true by default
+ fixed tabbing
Code:
function onUse(player, item, fromPosition, ItemEx, toPosition, isHotkey)
    local user = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if user == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        player:addItem(2160, 1, true) -- 2160 = id, 1 = amount
        elseif user == 1 then
            player:sendCancelMessage("You've already done this quest.")
        end
    return true
end

try this :)

anyone more advanced in scripting than me, feel free to tell me what could be improved in this (tabbing is awful, i know :()

Thanks for your help guys, but how do i make it a bag with the items inside?
 
Here, i've had a really nasty lesson from Xeraphus (duhh he even called me a monkey) but i've learned how to use the tables now) so here you go :)

Code:
local items = { {2168, 2} }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if storage == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        local container = player:addItem(xxxx) - change it to whatever ID the container is
        for i = 1, #items do
            local itemid = items[i][1]
            local count = items[i][2]
            if not ItemType(itemid):isStackable() then
                for c = 1, count do
                    container:addItem(itemid, 1)
                end
            else
                container:addItem(itemid, count)
            end
        end
    elseif storage == 1 then
        player:sendCancelMessage("You've already done this quest.")
    end
    return true
end
 
Then it should be possible to give it a default action and/or unique id to the chest and it should work through the default system? Where is the default RME chest reward script, I think I have seen it before but couldn't find it in TFS 1.2.
Something along the lines of this: https://github.com/orts/server/blob/master/data/actions/scripts/quests/system.lua#L43-L98

I just had this one quests.lua
Code:
local annihilatorReward = {1990, 2400, 2431, 2494}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid <= 1250 or item.uid >= 30000 then
        return false
    end

    local itemType = ItemType(item.uid)
    if itemType:getId() == 0 then
        return false
    end

    local itemWeight = itemType:getWeight()
    local playerCap = player:getFreeCapacity()
    if isInArray(annihilatorReward, item.uid) then
        if player:getStorageValue(30015) == -1 then
            if playerCap >= itemWeight then
                if item.uid == 1990 then
                    player:addItem(1990, 1):addItem(2326, 1)
                else
                    player:addItem(item.uid, 1)
                end
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
                player:setStorageValue(30015, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        end
    elseif player:getStorageValue(item.uid) == -1 then
        if playerCap >= itemWeight then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
            player:addItem(item.uid, 1)
            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
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end
    return true
end
 
Here, i've had a really nasty lesson from Xeraphus (duhh he even called me a monkey) but i've learned how to use the tables now) so here you go :)

Code:
local items = { {2168, 2} }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = player:getStorageValue(xxxx) -- Put your own storage value instead of xxxx, could be anything that u dont use in your other scripts
    if storage == -1 then
        player:setStorageValue(xxxx, 1) -- change xxxx again
        local container = player:addItem(xxxx) - change it to whatever ID the container is
        for i = 1, #items do
            local itemid = items[i][1]
            local count = items[i][2]
            if not ItemType(itemid):isStackable() then
                for c = 1, count do
                    container:addItem(itemid, 1)
                end
            else
                container:addItem(itemid, count)
            end
        end
    elseif storage == 1 then
        player:sendCancelMessage("You've already done this quest.")
    end
    return true
end

Code:
[Warning - Weapons::registerEvent] Duplicate registered item with id: 0
[Warning - Event::checkScript] Can not load script: scripts/quests/bograider.lua
data/actions/scripts/quests/bograider.lua:7: '=' expected near 'to'
 
add another - near change so its a comment, i'm sorry for that mistake

change line
Code:
local container = player:addItem(xxxx) - change it to whatever ID the container is
to
Code:
local container = player:addItem(xxxx) -- change it to whatever ID the container is
 
Replace your quests.lua by this https://raw.githubusercontent.com/orts/server/master/data/actions/scripts/quests/system.lua and it will work as other quests with single items, you will need just to add the default actionid, some uniqueid to the chest and add the items inside it.
I guess i have to change in actions.xml cuz right now it looks like this:
Code:
<action itemid="1740" script="quests/quests.lua" />
    <action fromid="1747" toid="1749" script="quests/quests.lua" />
I have to add like actionid 2000 or something right?
 
Replace your quests.lua by this https://raw.githubusercontent.com/orts/server/master/data/actions/scripts/quests/system.lua and it will work as other quests with single items, you will need just to add the default actionid, some uniqueid to the chest and add the items inside it.

Sorry for double post, but i get this error when i replace that quests.lua script.
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/quests/quests.lua
data/actions/scripts/quests/quests.lua:2: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/quests/quests.lua:2: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/quests/quests.lua
 
Sorry for double post, but i get this error when i replace that quests.lua script.
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/quests/quests.lua
data/actions/scripts/quests/quests.lua:2: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/quests/quests.lua:2: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/quests/quests.lua
Try this:
That file has storages from real map, etc...
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = item.uid
  
    if storage > 65535 then
        return false
    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
 
Solution
Try this:
That file has storages from real map, etc...
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = item.uid
 
    if storage > 65535 then
        return false
    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

Thank you very much mate. Now it works by adding a bag including items in RME :)
 

Similar threads

Back
Top