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

🍬 Simple Quest Chest System 🍬

Sarah Wesker

ƐƖєgαηт Sуηтαx ❤
Staff member
TFS Developer
Support Team
Joined
Mar 16, 2017
Messages
1,422
Solutions
155
Reaction score
1,985
Location
London
GitHub
MillhioreBT
Twitch
millhiorebt
Available for Engine: TFS-master

data/scripts/little_quest_chest.lua
Lua:
--[[
    Little Quest Chests
    Create By: 𝓜𝓲𝓵𝓵𝓱𝓲𝓸𝓻𝓮 𝓑𝓣
    TFS Version: 1.5
]]--

local storageBase = 9000000
local actionId = 65535

local action = Action()

function action.onUse(player, chest, fromPos, target, toPos, isHotkey)
    local questId = chest:getUniqueId()
    if not chest:getType():isContainer() then
        error(string.format("[Error - LittleQuestChests::%d] Item %d is not a container.", questId, chest:getId()))
    end

    if player:getStorageValue(storageBase + questId) ~= -1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local items = chest:getItems()
    if #items == 0 then
        error(string.format("[Error - LittleQuestChests::%d] No items found for quest %d", questId, questId))
    end

    local totalWeight = 0
    for _, item in pairs(items) do
        totalWeight = totalWeight + item:getWeight()
    end

    if player:getFreeCapacity() < totalWeight then
        player:sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY)
        return true
    end

    player:setStorageValue(storageBase + questId, 1)
    player:sendTextMessage(MESSAGE_LOOT, string.format("You have found %s.", chest:getContentDescription()))
    for _, item in pairs(items) do
        player:addItemEx(item:clone(), true)
    end
    return true
end

action:aid(actionId)
action:register()
sddsg.gifdfvdfhg.gif
 
Last edited:
You are probably not using TFS master or that's a custom function Sarah has.
Change player.storage[storageBase + questId] ~= -1 to player:getStorageValue(storageBase + questId) ~= -1
and also change player.storage[storageBase + questId] = 1 to player:setStorageValue(storageBase + questId, 1)
 
ahh ok, thank you very much now yes.

@Sarah Wesker
I had another question, I wanted to know if it was possible to do it without a bag, that when you open the chest it would give you the items directly, and not with the bag. Greetings.
 
ahh ok, thank you very much now yes.

@Sarah Wesker
I had another question, I wanted to know if it was possible to do it without a bag, that when you open the chest it would give you the items directly, and not with the bag. Greetings.
You probably don't need it anymore, but I already made the modifications, and it works without a backpack.

For those who want to use a backpack, simply add it to the container, and add the items inside that container.
 
Could you make a slight change/new variation to the script? So that it work in a way that if if the chest has a stackable, like gold coin, it will give a random amount of that stackable between 1 and the "max" set by the count in the map editor, so if the count is 50, it doesn't always give 50 gp, it will give between 1 and 50. And then if the chest has more than 1 item, it has a chance of giving one of the items set via the map editor. So if the chest has gp, potions, and a sword, you randomly get one of the 3, and it still recognizes the "count" variable in the map editor as the max amount of an item if it is stackable.

This would only work on the root layer of items. For example, if there is a backpack set as a reward in the map editor then that backpack with every item in it would be looted as they are placed in the backpack in the map editor (for example, stackables in the backpack wouldn't have a random amount).
 
Available for Engine: TFS-master

data/scripts/little_quest_chest.lua
Lua:
--[[
    Little Quest Chests
    Create By: 𝓜𝓲𝓵𝓵𝓱𝓲𝓸𝓻𝓮 𝓑𝓣
    TFS Version: 1.5
]]--

local storageBase = 9000000
local actionId = 65535

local action = Action()

function action.onUse(player, chest, fromPos, target, toPos, isHotkey)
    local questId = chest:getUniqueId()
    if not chest:getType():isContainer() then
        error(string.format("[Error - LittleQuestChests::%d] Item %d is not a container.", questId, chest:getId()))
    end

    if player:getStorageValue(storageBase + questId) ~= -1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local items = chest:getItems()
    if #items == 0 then
        error(string.format("[Error - LittleQuestChests::%d] No items found for quest %d", questId, questId))
    end

    local totalWeight = 0
    for _, item in pairs(items) do
        totalWeight = totalWeight + item:getWeight()
    end

    if player:getFreeCapacity() < totalWeight then
        player:sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY)
        return true
    end

    player:setStorageValue(storageBase + questId, 1)
    player:sendTextMessage(MESSAGE_LOOT, string.format("You have found %s.", chest:getContentDescription()))
    for _, item in pairs(items) do
        player:addItemEx(item:clone(), true)
    end
    return true
end

action:aid(actionId)
action: register()
View attachment 74798View attachment 74799

Is it used to place backpacks with items inside?
 
Thanks to another community member's help, I was able to get a new variation adjusted. Read my post above to understand what this variation does.


Lua:
local storageBase = 9000000
local actionId = 4330

local action = Action()

function action.onUse(player, chest, fromPos, target, toPos, isHotkey)
    local questId = chest:getUniqueId()
    if not chest:getType():isContainer() then
        error(string.format("[Error - LittleQuestChests::%d] Item %d is not a container.", questId, chest:getId()))
    end

    if player:getStorageValue(storageBase + questId) ~= -1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local items = chest:getItems()
    if #items == 0 then
        error(string.format("[Error - LittleQuestChests::%d] No items found for quest %d", questId, questId))
    end

    local totalWeight = 0
    local itemNum = math.random(1,#items)
   if items[itemNum] then
    totalWeight = totalWeight + items[itemNum]:getWeight()
  end

    if player:getFreeCapacity() < totalWeight then
        player:sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY)
        return true
    end

    player:setStorageValue(storageBase + questId, 1)
 
    if items[itemNum] then
        local itemID = items[itemNum]:getId()
        if ItemType(itemID):isStackable() then
            local count = math.random(1,items[itemNum]:getCount())           

            local reward = player:addItem(itemID,count)
            player:sendTextMessage(MESSAGE_LOOT, string.format("You have found %s.", reward:getDescription(1)))
        end
    else
        player:addItemEx(items[itemNum]:clone(), true)
        if itemType:isContainer() then
            player:sendTextMessage(MESSAGE_LOOT, string.format("You have found %s.", items[itemNum]:getContentDescription()))
        else
            player:sendTextMessage(MESSAGE_LOOT, string.format("You have found %s.", items[itemNum]:getDescription(1)))
        end
    end
    return true
end


action:aid(actionId)
action:register()
 
Back
Top