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

Action Advanced quest chests 1.x

It seem to create an issue when I add "dofile('data/lib/quest_chests.lua')" into the global.lua. It says it wount load a ton of different scripts, and it wount log me into the server. Anyone else has an issue with this? I would really love for this to work as it seems awesome :D

Thanks guys
 
can you derect me into your optimized code please?

Did you figure it out? I have the exact same issue as you. I cant add it to global or to lib. I get the message "The chest is empty", but never get any of the rewards.
Help is much needed
 
Old post but dont understand the error. @strutZ


Code:
Lua Script Error: [Action Interface]
data/actions/scripts/monzera/multichests.lua:onUse
data/actions/scripts/monzera/multichests.lua:17: attempt to index global 'questChests' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/monzera/multichests.lua:17: in function <data/actions/scripts/monzera/multichests.lua:1>


Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   -----------------------------------------------------------------------------------
   -- Local Variables --
   -----------------------------------------------------------------------------------
   local questChest = item:getUniqueId()
   -----------------------------------------------------------------------------------
   -- Check if player has already opened box --
   -----------------------------------------------------------------------------------
   if player:getStorageValue(questChest) == 1 then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
       return true
   end
   -----------------------------------------------------------------------------------
   -- Check if player meets level requirment
   -----------------------------------------------------------------------------------
   local playerLevel = player:getLevel()
   local minLevel = questChests[questChest].minLevel
   if questChests[questChest].minLevel >= playerLevel then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level "..minLevel.." to open this chest.")
       return true
   end
   -----------------------------------------------------------------------------------
 
   -- Give rewward if player has not yet opened box --
 
   -----------------------------------------------------------------------------------
   for i = 1, #questChests[questChest].items do
       local rewardType = questChests[questChest].items[i].type
       -----------------------------------------------------------------------------------
       -- Item Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "item" then
           local item = questChests[questChest].items[i].item
           local count = questChests[questChest].items[i].count
           player:addItem(item, count)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You earned ["..count.."x] "..capAll(getItemName(item)))
       end
       -----------------------------------------------------------------------------------
       -- Experience Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "experience" then
           local amount = questChests[questChest].items[i].amount
           player:addExperience(amount)
           player:say(amount.." EXP gained!", TALKTYPE_MONSTER_SAY)
           player:getPosition():sendMagicEffect(CONST_ME_STUN)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained "..amount.." experience points.")
       end
       -----------------------------------------------------------------------------------
       -- Outfit Type Reward --
       -----------------------------------------------------------------------------------   
       if rewardType == "outfit" then
           local outfitName = questChests[questChest].items[i].name
           local maleOutfit = questChests[questChest].items[i].maleId
           local femaleOutfit = questChests[questChest].items[i].femaleId
           if player:getSex() == 0 then
               player:addOutfit(femaleOutfit)
           else
               player:addOutfit(maleOutfit)
           end
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the "..outfitName.." outfit.")
       end
       -----------------------------------------------------------------------------------
       -- Addon Type Reward --
       -----------------------------------------------------------------------------------   
       if rewardType == "addon" then
           local outfitName = questChests[questChest].items[i].outfit
           local addon = questChests[questChest].items[i].addonNumber
           local maleAddon = questChests[questChest].items[i].maleId
           local femaleAddon = questChests[questChest].items[i].femaleId
           if player:getSex() == 0 then
               player:addOutfitAddon(femaleAddon, addon)
           else
               player:addOutfitAddon(maleAddon, addon)
           end
           if addon == 1 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the first "..outfitName.." outfit addon.")
           elseif addon == 2 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the second "..outfitName.." outfit addon.")
           elseif addon == 3 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the third "..outfitName.." outfit addon.")
           end
       end
       -----------------------------------------------------------------------------------
       -- Mount Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "mount" then
           local mountName = questChests[questChest].items[i].mountName
           local mountId = questChests[questChest].items[i].mountId
           player:addMount(mountId)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have unlocked the "..mountName.." mount.")
       end
   end
   -----------------------------------------------------------------------------------
   -- Add in any cooldowns/storages --
   -----------------------------------------------------------------------------------
   player:setStorageValue(questChest, 1)
   return true
end
 
Old post but dont understand the error. @strutZ


Code:
Lua Script Error: [Action Interface]
data/actions/scripts/monzera/multichests.lua:onUse
data/actions/scripts/monzera/multichests.lua:17: attempt to index global 'questChests' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/monzera/multichests.lua:17: in function <data/actions/scripts/monzera/multichests.lua:1>

Your error is due to the fact you haven't loaded the other lib file.

You need to add this to global.lua
dofile('data/lib/quest_chests.lua')

You need to create:
data/lib/quest_chests.lua

and use the following:
Lua:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [2000] = {
       minLevel = 50,
       items = {
           [1] = {type = "item", item = 2160, count = 1},
           [2] = {type = "experience", amount = 20000},
           [3] = {type = "outfit", name = "assassin", femaleId = 156, maleId = 152},
           [4] = {type = "addon", outfit = "nobleman", addonNumber = 1, femaleId = 140, maleId = 132},
           [5] = {type = "mount", mountName = "Orc", mountId = 20},
       },
   },
},
 
Been awhile since I have posted something here so I'm going to release my advanced quest chest ;)

What does it do?
A quest chest that can hold rewards in the shape of an Item, Experience, Outfit or a addon!

Features
  • Easy config
  • Can add level requirements for chests
  • Supports Item Rewards
  • Supports Experience Rewards
  • Supports Outfit Rewards
  • Supports Addon Rewards
  • Supports Mount Rewards

This system currently supports up to 100 chests. o add more simply up the "touid" in the actions.xml line.

Installation

data/global.lua
Lua:
dofile('data/lib/quest_chests.lua')

data/lib/quest_chests.lua
Lua:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [2000] = {
       minLevel = 50,
       items = {
           [1] = {type = "item", item = 2160, count = 1},
           [2] = {type = "experience", amount = 20000},
           [3] = {type = "outfit", name = "assassin", femaleId = 156, maleId = 152},
           [4] = {type = "addon", outfit = "nobleman", addonNumber = 1, femaleId = 140, maleId = 132},
           [5] = {type = "mount", mountName = "Orc", mountId = 20},
       },
   },
},

data/actions/actions.xml
Lua:
<action fromuid="2000" touid="2100" script="quest_chests.lua" />

data/actions/scripts/quest_chests.lua
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   -----------------------------------------------------------------------------------
   -- Local Variables --
   -----------------------------------------------------------------------------------
   local questChest = item:getUniqueId()
   -----------------------------------------------------------------------------------
   -- Check if player has already opened box --
   -----------------------------------------------------------------------------------
   if player:getStorageValue(questChest) == 1 then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
       return true
   end
   -----------------------------------------------------------------------------------
   -- Check if player meets level requirment
   -----------------------------------------------------------------------------------
   local playerLevel = player:getLevel()
   local minLevel = questChests[questChest].minLevel
   if questChests[questChest].minLevel => playerLevel then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level "..minLevel.." to open this chest.")
       return true
   end
   -----------------------------------------------------------------------------------

   -- Give rewward if player has not yet opened box --

   -----------------------------------------------------------------------------------
   for i = 1, #questChests[questChest].items do
       local rewardType = questChests[questChest].items[i].type
       -----------------------------------------------------------------------------------
       -- Item Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "item" then
           local item = questChests[questChest].items[i].item
           local count = questChests[questChest].items[i].count
           player:addItem(item, count)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You earned ["..count.."x] "..capAll(getItemName(item)))
       end
       -----------------------------------------------------------------------------------
       -- Experience Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "experience" then
           local amount = questChests[questChest].items[i].amount
           player:addExperience(amount)
           player:say(amount.." EXP gained!", TALKTYPE_MONSTER_SAY)
           player:getPosition():sendMagicEffect(CONST_ME_STUN)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained "..amount.." experience points.")
       end
       -----------------------------------------------------------------------------------
       -- Outfit Type Reward --
       -----------------------------------------------------------------------------------   
       if rewardType == "outfit" then
           local outfitName = questChests[questChest].items[i].name
           local maleOutfit = questChests[questChest].items[i].maleId
           local femaleOutfit = questChests[questChest].items[i].femaleId
           if player:getSex() == 0 then
               player:addOutfit(femaleOutfit)
           else
               player:addOutfit(maleOutfit)
           end
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the "..outfitName.." outfit.")
       end
       -----------------------------------------------------------------------------------
       -- Addon Type Reward --
       -----------------------------------------------------------------------------------   
       if rewardType == "addon" then
           local outfitName = questChests[questChest].items[i].outfit
           local addon = questChests[questChest].items[i].addonNumber
           local maleAddon = questChests[questChest].items[i].maleId
           local femaleAddon = questChests[questChest].items[i].femaleId
           if player:getSex() == 0 then
               player:addOutfitAddon(femaleAddon, addon)
           else
               player:addOutfitAddon(maleAddon, addon)
           end
           if addon == 1 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the first "..outfitName.." outfit addon.")
           elseif addon == 2 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the second "..outfitName.." outfit addon.")
           elseif addon == 3 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the third "..outfitName.." outfit addon.")
           end
       end
       -----------------------------------------------------------------------------------
       -- Mount Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "mount" then
           local mountName = questChests[questChest].items[i].mountName
           local mountId = questChests[questChest].items[i].mountId
           player:addMount(mountId)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have unlocked the "..mountName.." mount.")
       end
   end
   -----------------------------------------------------------------------------------
   -- Add in any cooldowns/storages --
   -----------------------------------------------------------------------------------
   player:setStorageValue(questChest, 1)
   return true
end
Hello my friend, is there a possibility to modify this script so that I can choose the prizes that each vocation will receive and the items have the name of the player who made the quest recorded in their description?
 
Hello my friend, is there a possibility to modify this script so that I can choose the prizes that each vocation will receive and the items have the name of the player who made the quest recorded in their description?
It is definitely possible.
 
Thanks for this script tho!
A question is how do i need to arrange so a player can only take 1 out of 2 chests?

I have a set up so that eg sorc can pick boh + a spellbook, and a knight voc would insted choose boh + shield but atm with set up below a player can choose both chests.

Lua:
  [5010] = {
        questStorage = 10000,
        questStatus = 5,
        questMsg_success = "Woho!",
        questMsg_fail = "Nope, still weak!",
        levelReq = 150,
        expReward = 10000,
        item_reward = {
        [1] = {itemid = 8900, count = 1},
        [2] = {itemid = 2195, count = 1}
        }
     
   },
  --Example 2--
   [5011] = {
        questStorage = 10000,
        questStatus = 5,
        questMsg_success = "Woho!",
        questMsg_fail = "Nope, still weak!",
        levelReq = 150,
        expReward = 10000,
        item_reward = {
        [1] = {itemid = 2517, count = 1},
        [2] = {itemid = 2195, count = 1}
        }
   }
 
 
}



EDIT: Got help from supp forum, added code in lib file
vocation = { id = {1, 2, 5, 6 } },

and in action files before
Code:
    if chest.expReward then
        player:addExperience(chest.expReward, true)
    end
add below
Lua:
    if chest.vocation then
    if not table.contains(chest.vocation.id, player:getVocation():getId()) then
        return player:sendCancelMessage("Your vocation cannot open this chest.")
    end
end


Added both files in case someone wants to use :] tried and works on TFS 1.3
 

Attachments

Last edited:
Add the chest.vocation BEFORE chest.expReward, because if you want to make chest for X vocation that gives exp, it will add exp before checking vocation, so everyone will be able to use it to get experience.
 
When I try to use chest with UID I got:
Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onGainExperience
data/events/scripts/player.lua:206: attempt to index local 'source' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:206: in function <data/events/scripts/player.lua:205>
        [C]: in function 'addExperience'
        data/actions/scripts/quest_chests.lua:57: in function <data/actions/scripts/quest_chests.lua:15>



player.lua:
Lua:
function Player:onGainExperience(source, exp, rawExp)  -- 205 line
if source:isMonster() then
        local bonusExperience = source:getMonsterLevel() * 5
        if source:getMonsterLevel() > 0 and bonusExperience > 1 then
            exp = exp * bonusExperience
        end
    end

quest.chests.lua 57 line
Lua:
       if rewardType == "experience" then
           local amount = questChests[questChest].items[i].amount
           player:addExperience(amount)                                                -- 57 LINE
           player:say(amount.." EXP gained!", TALKTYPE_MONSTER_SAY)
           player:getPosition():sendMagicEffect(nil)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained "..amount.." experience points.")
       end

quest_chests.lua:15
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)


TFS 1.3, 8.6
 
When I implement everything, and set up uid of chest lets say 2001, in game I don't get what's in quest_chests.lua , except i recive Purple Backpack that has ID 2001. In console i have no errors whatsoever.
I'm using TFS 1.3/1.4 from Nekiro for 8.6, idk what to do...
 
Tfs 1.3 tibia 12.64 don't work. In console i don't have errors whatsever.
After climbing the chest, the character reacts to the quest by moving back.
When I click on a quest. No reaction.
Can help me?
 
Lua:
Lua Script Error: [Main Interface]
data/global.lua
data/lib/questchests.lua:7: '}' expected (to close '{' at line 2) near 'levelReq'
stack traceback:
        [C]: at 0x7ff65a5f3700
        [C]: in function 'dofile'
        data/global.lua:4: in main chunk
[Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua
 
Back
Top