• 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

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,391
Solutions
7
Reaction score
550
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

 
Last edited:
Thanks for that nice script! What exactly I have to fill out, to get it work? For example I want to loot unique id 2010 to get 200.000 xp? :)
Thanks for your help anyway! :)
 
Thanks for that nice script! What exactly I have to fill out, to get it work? For example I want to loot unique id 2010 to get 200.000 xp? :)
Thanks for your help anyway! :)

Fill this bit out =)

Lua:
questChests = {
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2000] = { -- Enter Unique ID here
        items = {
            [1] = {type = "item", item = 2160, count = 1}, --Item reward example
            [2] = {type = "experience", amount = 20000}, -- Experience reward Example
            [3] = {type = "outfit", name = "assassin", femaleId = 156, maleId = 152}, -- Outfit reward exampe
            [4] = {type = "addon", outfit = "nobleman", addonNumber = 1, femaleId = 140, maleId = 132}, -- Addon reward example
        },
    },
}

So if you wanted to make a chest with UID 2010 to get 200k exp you would write it like this

Lua:
[code=Lua]questChests = {
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2010] = { -- Enter Unique ID here
        items = {
            [1] = {type = "experience", amount = 200000}, -- Experience reward Example
        },
    },
 
So if you wanted to make a chest with UID 2010 to get 200k exp you would write it like this

Lua:
[code=Lua]questChests = {
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2010] = { -- Enter Unique ID here
        items = {
            [1] = {type = "experience", amount = 200000}, -- Experience reward Example
        },
    },

Thanks man :)
 
Another question, because I like your script.
Is it possible to add a choice? For example there are 3 chests, 2 with items or 1 with xp, and u can choose just one of them?
Possible to add? :)
 
Another question, because I like your script.
Is it possible to add a choice? For example there are 3 chests, 2 with items or 1 with xp, and u can choose just one of them?
Possible to add? :)
Its possible but too much effort to add it into this script.
 
I get this error when open the unique ID. - Does your system just work with chests?
I want to use it on "Blood Herb Quest" - there u have to loot a "tree" - I added the UID to the tree, but it give me that error. I get the Blood Herb, but I can loot it endless times.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/quest_chests.lua:onUse
data/actions/scripts/quests/quest_chests.lua:27: attempt to call global 'capAll' (a nil value)
stack traceback:
        [C]: in function 'capAll'
        data/actions/scripts/quests/quest_chests.lua:27: in function <data/actions/scripts/quests/quest_chests.lua:1>

Edit: okay,.. same problem on "box" too.
 
Last edited:
possible to do this with mounts aswell? :)

still awesome code dude, will use it :)
 
I get this error when open the unique ID. - Does your system just work with chests?
I want to use it on "Blood Herb Quest" - there u have to loot a "tree" - I added the UID to the tree, but it give me that error. I get the Blood Herb, but I can loot it endless times.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/quest_chests.lua:onUse
data/actions/scripts/quests/quest_chests.lua:27: attempt to call global 'capAll' (a nil value)
stack traceback:
        [C]: in function 'capAll'
        data/actions/scripts/quests/quest_chests.lua:27: in function <data/actions/scripts/quests/quest_chests.lua:1>

Edit: okay,.. same problem on "box" too.
Ahh shit i did it again! add this to the top of the action script.

Lua:
-- This function will capitalize the first letter of every word.
function capAll(str)
    local newStr = ""; wordSeparate = string.gmatch(str, "([^%s]+)")
    for v in wordSeparate do
        v = v:gsub("^%l", string.upper)
        if newStr ~= "" then
            newStr = newStr.." "..v
        else
            newStr = v
        end
    end
    return newStr
end


possible to do this with mounts aswell? :)

still awesome code dude, will use it :)

I'll add support for it tomorrow
 
possible to do this with mounts aswell? :)

still awesome code dude, will use it :)

Quest Example Updated
Lua:
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2000] = {
        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 = "dromedary", mountId = 20},
        },
    },

To make it work add this to your action script under the addon reward.
Lua:
        -----------------------------------------------------------------------------------
        -- Mount Type Reward --
        -----------------------------------------------------------------------------------
        if rewardType == "mount" then
            local mountName = questChests[questChest].items[i].mountName
            local mountId = questChests[questChest].items[i].mountId
            player:addMount(mount)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have unlocked the "..mountName.." mount.")
        end

Main post updated.
 
Perfect! Now:) it works :) Thanks man![

Ahh shit i did it again! add this to the top of the action script.

Lua:
-- This function will capitalize the first letter of every word.
function capAll(str)
    local newStr = ""; wordSeparate = string.gmatch(str, "([^%s]+)")
    for v in wordSeparate do
        v = v:gsub("^%l", string.upper)
        if newStr ~= "" then
            newStr = newStr.." "..v
        else
            newStr = v
        end
    end
    return newStr
end

Next Question, how to add multiple items to 1 chest? :) And is it possible to add a lvl requirement?
 
Last edited:
Perfect! Now:) it works :) Thanks man![



Next Question, how to add multiple items to 1 chest? :) And is it possible to add a lvl requirement?
Farkkk gimme your server i'll do that too ahaha

Do add multiple items to a chest you just follow the config i set up

So
Code:
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2000] = {
        items = {
            [1] = {type = "item", item = 2160, count = 1},
            [2] = {type = "item", item = 2187, count = 1},
        },
    },

This will give the player 1 crystal coin and one wand of inferno.

I also updated main post with the level requirement thing you asked for.
 
Thanks man, your are fucking awesome! :)

Will you hate me if I ask one thing more? :D

When I loot one of these quest chests, the item is looted and cannot looted again, everything is finde, can I add a "Questname bla bla (completed)" to Quest Log? :)
 
Last edited:
Thanks man, your are fucking awesome! :)

Will you hate me if I ask one thing more? :D

When I loot one of these quest chests, the item is looted and cannot looted again, everything is finde, can I add a "Questname bla bla (completed)" to Quest Log? :)
I try lol

Nah no hate but you are going to have to do this next bit yourself ;) If you go into data/XML/quests.xml this is where all the questlog data is stored.

A good tutorial can be found here
[Configuration] How to make a working Quest Log

Good luck!
 
Okay, I copied the new action file with lvl requirement.

Now, when I want to loot one of these chests, I get this error:

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/quest_chests.lua:onUse
data/actions/scripts/quests/quest_chests.lua:32: attempt to compare number with nil
stack traceback:
        [C]: in function '__le'
        data/actions/scripts/quests/quest_chests.lua:32: in function <data/actions/scripts/quests/quest_chests.lua:15>

This ist the actual "quest_chests.lua" from actions.
-- This function will capitalize the first letter of every word.
function capAll(str)
local newStr = ""; wordSeparate = string.gmatch(str, "([^%s]+)")
for v in wordSeparate do
v = v:gsub("^%l", string.upper)
if newStr ~= "" then
newStr = newStr.." "..v
else
newStr = v
end
end
return newStr
end

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.type
-----------------------------------------------------------------------------------
-- Item Type Reward --
-----------------------------------------------------------------------------------
if rewardType == "item" then
local item = questChests[questChest].items.item
local count = questChests[questChest].items.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.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.name
local maleOutfit = questChests[questChest].items.maleId
local femaleOutfit = questChests[questChest].items.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.outfit
local addon = questChests[questChest].items.addonNumber
local maleAddon = questChests[questChest].items.maleId
local femaleAddon = questChests[questChest].items.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.mountName
local mountId = questChests[questChest].items.mountId
player:addMount(mount)
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
 
Tested on 1.3 not working. I'm getting console errors. how tf do you add an image in this forum? lmfao
Error

Whatever, there's a link.
 
@Schwarzbeere @Taurus

My bad updated main post try now

Still wasn't doing the trick. I was able to get it working by fixing the syntax. This is a SWEET script buddy.

You totally ROCK for sharing this.

Here's what I fixed:

Lua:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [1234] = {
       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},
       },
   },
} -- This closing bracket was missing.
 
Back
Top