• 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.3] Advanced quest chests

beenii

Active Member
Joined
Jul 26, 2010
Messages
485
Solutions
1
Reaction score
27
System by strutZ with a small modification to do anahi type quest
4 chest 1 reward.

Features
  • Easy config
  • Can add level requirements for chests
  • Supports Item Rewards
  • Supports Experience Rewards
  • Supports Outfit Rewards
  • Supports Addon Rewards
  • Supports Mount Rewards
  • Supports Anihi Quest (4 Chest only select 1 Chest)

This system currently supports up to 100 chests. o add more simply up the change 2000, 2100 in data/scripts/actions/quest_chests.lua

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


data/lib/quest_chests.lua
Lua:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [2000] = {
       minLevel = 50,
       storageUnique = 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 = "Orc", mountId = 20},
       },
   },
 
     ---------------------------------------------------------
   -- Example Quest Box 2 like anihi 2 reward only select 1
   ---------------------------------------------------------
   [2001] = {
       minLevel = 50,
       storageUnique = 2001, -- put same storage for only select 1 reward
       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},
       },
   },
    [2002] = {
       minLevel = 50,
       storageUnique = 2001, -- put same storage for only select 1 reward
       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/scripts/actions/quest_chests.lua
Lua:
function capAll(str)
    return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end))
end

local advanceChest = Action()

function advanceChest.onUse(player, item, fromPosition, itemEx, toPosition)
   -----------------------------------------------------------------------------------
   -- 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.")
       toPosition:sendMagicEffect(10)
       return true
   end
 
   local storageOne = questChests[questChest].storageUnique
   -----------------------------------------------------------------------------------
   -- Check if player has already opened box multiple chest only 1 reward --
   -----------------------------------------------------------------------------------
   if player:getStorageValue(storageOne) == 1 then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
       toPosition:sendMagicEffect(10)
       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

            
 
 
   -----------------------------------------------------------------------------------
   -- Add in any cooldowns/storages --
   -----------------------------------------------------------------------------------
   player:setStorageValue(questChest, 1)
   player:setStorageValue(storageOne, 1)
   return true
end
end

for i = 2000, 2100 do
    advanceChest:uid(i)
end

advanceChest:register()


It is a very useful system, since it has a simple organization, I hope my contribution will serve you.
 
Last edited:

ImaG

Member
Joined
Aug 16, 2017
Messages
30
Reaction score
5
Location
Poland
GitHub
ImaGus01v
Lua Script Error: [Test Interface]
data/actions/scripts/questchests.lua
data/actions/scripts/questchests.lua:5: attempt to call global 'Action' (a nil value)
stack traceback:
[C]: in function 'Action'
data/actions/scripts/questchests.lua:5: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/questchests.lua
 

Znote

<?php echo $title; ?>
Staff member
Global Moderator
Premium User
Joined
Feb 14, 2008
Messages
6,947
Solutions
252
Reaction score
1,890
Location
Norway
GitHub
Znote
Modification in data/lib/lib.lua is not neccesary, you can just change the path of data/lib/quest_chests.lua file to data/scripts/lib/quest_chests.lua, Revscriptsys will load files in data/scripts/lib/ as lib files automatically.
 
OP
OP
beenii

beenii

Active Member
Joined
Jul 26, 2010
Messages
485
Solutions
1
Reaction score
27
Modification in data/lib/lib.lua is not neccesary, you can just change the path of data/lib/quest_chests.lua file to data/scripts/lib/quest_chests.lua, Revscriptsys will load files in data/scripts/lib/ as lib files automatically.
thanks for letting me know, i will modify
 
Top