• 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

Now this:

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

TFS 1.2 if it matter.

what does your config table look like
 
@strutZ

No errors, first it says i recieve reward but i get nothing, then chest is empty
Tfs 1.2
scripts
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player = Player(player)
    chest = questChests[item:getAttribute('uid')]
    if not chest then return true end
  
    --------------Check if player has already opened the chest-----
    if player:getStorageValue(item:getAttribute('uid')) == 1 then
        return player:sendCancelMessage("The chest is empty.")
    end
  
    --------------Check if player has quest status-----------------
    if chest.storage and chest.status then
        if player:getStorageValue(chest.storage) ~= chest.status then
            return player:sendCancelMessage(chest.questMsg_fail)
        end
    end
  
    ---------------Check if player has level requirement------------
    if chest.levelReq then
        if player:getLevel() < chest.levelReq then
            return player:sendCancelMessage("You must be level "..chest.levelReq.. " to open this chest.")
        end
    end
  
    --------------Check if player has key required-------------------
    if chest.keyReq then
        if player:getItemCount(chest.keyReq) < 1 then
            return player:sendCancelMessage("This chest requires a key to open.")
        end
    end
  
    ------------Give player EXP reward-------------------------------
    if chest.expReward then
        player:addExperience(chest.expReward, true)
    end
  
    ------------Give player reward items---------------------
    if chest.item_reward then
        for i = 1, #chest.item_reward do
            player:addItem(chest.item_reward[i].itemid, chest.item_reward[i].count, 1)
        end
    end
  
    ------------Give player outfit reward--------------------
    if chest.outfit_reward then
        for i = 1, #chest.outfit_reward do
            if player:getSex() == 0 then
                player:addOutfit(chest.outfit_reward[i].female, chest.outfit_reward[i].addons)
            else
                player:addOutfit(chest.outfit_reward[i].male, chest.outfit_reward[i].addons)
            end
        end
    end
  
    -----------Give player addon reward-----------------------
    if chest.addon_reward then
        for i = 1, #chest.addon_reward do
            if player:getSex() == 0 then
                if chest.addon_reward.addons == 1 then
                    player:addOutfitAddon(chest.addon_reward[i].female, 1)
                else
                    player:addOutfitAddon(chest.addon_reward[i].female, 1)
                    player:addOutfitAddon(chest.addon_reward[i].female, 2)
                end
            else
                if chest.addon_reward.addons == 1 then
                    player:addOutfitAddon(chest.addon_reward[i].male, 1)
                else
                    player:addOutfitAddon(chest.addon_reward[i].male, 1)
                    player:addOutfitAddon(chest.addon_reward[i].male, 2)
                end
            end
        end
    end
  
    ----------Give player mount reward--------------------------
    if chest.mount_reward then
        for i = 1, #chest.mount_reward do
            player:addMount(chest.mount_reward.mountId)
        end
    end
  
    if chest.questStatus then
        player:setStorageValue(chest.questStorage, chest.questStatus + 1)
    end
  
    player:sendCancelMessage("You have recieved your reward.")
    player:setStorageValue(item:getAttribute('uid'), 1)
    return false
end

Lua:
questChests = {
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2001] = {
        items = {
            [1] = {type = "item", item = 2160, count = 1},
            [2] = {type = "item", item = 2187, count = 1},
        },
    },
     }
 
@strutZ

No errors, first it says i recieve reward but i get nothing, then chest is empty
Tfs 1.2
scripts
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player = Player(player)
    chest = questChests[item:getAttribute('uid')]
    if not chest then return true end
 
    --------------Check if player has already opened the chest-----
    if player:getStorageValue(item:getAttribute('uid')) == 1 then
        return player:sendCancelMessage("The chest is empty.")
    end
 
    --------------Check if player has quest status-----------------
    if chest.storage and chest.status then
        if player:getStorageValue(chest.storage) ~= chest.status then
            return player:sendCancelMessage(chest.questMsg_fail)
        end
    end
 
    ---------------Check if player has level requirement------------
    if chest.levelReq then
        if player:getLevel() < chest.levelReq then
            return player:sendCancelMessage("You must be level "..chest.levelReq.. " to open this chest.")
        end
    end
 
    --------------Check if player has key required-------------------
    if chest.keyReq then
        if player:getItemCount(chest.keyReq) < 1 then
            return player:sendCancelMessage("This chest requires a key to open.")
        end
    end
 
    ------------Give player EXP reward-------------------------------
    if chest.expReward then
        player:addExperience(chest.expReward, true)
    end
 
    ------------Give player reward items---------------------
    if chest.item_reward then
        for i = 1, #chest.item_reward do
            player:addItem(chest.item_reward[i].itemid, chest.item_reward[i].count, 1)
        end
    end
 
    ------------Give player outfit reward--------------------
    if chest.outfit_reward then
        for i = 1, #chest.outfit_reward do
            if player:getSex() == 0 then
                player:addOutfit(chest.outfit_reward[i].female, chest.outfit_reward[i].addons)
            else
                player:addOutfit(chest.outfit_reward[i].male, chest.outfit_reward[i].addons)
            end
        end
    end
 
    -----------Give player addon reward-----------------------
    if chest.addon_reward then
        for i = 1, #chest.addon_reward do
            if player:getSex() == 0 then
                if chest.addon_reward.addons == 1 then
                    player:addOutfitAddon(chest.addon_reward[i].female, 1)
                else
                    player:addOutfitAddon(chest.addon_reward[i].female, 1)
                    player:addOutfitAddon(chest.addon_reward[i].female, 2)
                end
            else
                if chest.addon_reward.addons == 1 then
                    player:addOutfitAddon(chest.addon_reward[i].male, 1)
                else
                    player:addOutfitAddon(chest.addon_reward[i].male, 1)
                    player:addOutfitAddon(chest.addon_reward[i].male, 2)
                end
            end
        end
    end
 
    ----------Give player mount reward--------------------------
    if chest.mount_reward then
        for i = 1, #chest.mount_reward do
            player:addMount(chest.mount_reward.mountId)
        end
    end
 
    if chest.questStatus then
        player:setStorageValue(chest.questStorage, chest.questStatus + 1)
    end
 
    player:sendCancelMessage("You have recieved your reward.")
    player:setStorageValue(item:getAttribute('uid'), 1)
    return false
end

Lua:
questChests = {
    ---------------------------------------------------------
    -- Example Quest Box 1
    ---------------------------------------------------------
    [2001] = {
        items = {
            [1] = {type = "item", item = 2160, count = 1},
            [2] = {type = "item", item = 2187, count = 1},
        },
    },
     }
Thats not my code.
 
how only select one reward?
example to anihi
 
This script is not meant for quests like that unfortunately. Though I may add it.
maybe add storage = xxx,
Code:
   [1000] = {
       minLevel = 20,
       storage = 1000,
       items = {
           [1] = {type = "item", item = 25376, count = 20},
       },
   },

Code:
   local storage = questChests[questChest].storage
   -----------------------------------------------------------------------------------
   -- Check if player has already opened box --
   -----------------------------------------------------------------------------------
   if player:getStorageValue(storage) == 1 then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
       toPosition:sendMagicEffect(10)
       return true
   end
 
Hello! I've been doing some modifications to this script.

The last change im missing is that i want from a list of items lets say 10 items for uid 2000, give to the player a random number of the items, can be 1 to 10.

Thought something like this would work.

Code:
if rewardType == "item" then
           local item = questChests[questChest].items[i].item
           local count = questChests[questChest].items[i].count
           player:addItem(math.random(item), count)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You earned ["..count.."x] "..capAll(getItemName(item)))
       end

Thanks for your time and effort. Great script!
 
Hello, I was making one diferent quest for each reward, that I want add, but now with this system, I just need to add a few lines, /reload and works, thanks :D
 
Use /reload global
 
Going to repost this.... I updated the code and tested it to support:

1. Quest Status chests (can only be opened at a certain point in a quest)
2. Key required chests
3. Multiple item rewards, mounts, and addons.

Lib code
Code:
questChests = {
--Main example--
   [500] = {
        questStorage = 10000,
        questStatus = 5,
        questMsg_success = "You have found the item now go do blah blah blah",
        questMsg_fail = "You are not ready to open this chest. Go do blah blah blah",
        levelReq = 40,
        keyReq = 2143,
        expReward = 10000,
        item_reward = {
        [1] = {itemid = 1111, count = 1},
        [2] = {itemid = 1111, count = 1}
        },
        outfit_reward = {
        [1] = {male = 111, female = 111, addons = 0}
        },
        addon_reward = {
        [1] = {male = 111, female = 111, addons = 1}
        },
        mount_reward = {
        [1] = {mountId = 1}
        }
      
   },
  --Example 2--
   [2000] = {
        item_reward = {
        [1] = {itemid = 1988, count = 1},
        [2] = {itemid = 2461, count = 1},
        [3] = {itemid = 2467, count = 1},
        [4] = {itemid = 2649, count = 1},
        [5] = {itemid = 2643, count = 1},
        [6] = {itemid = 2173, count = 1},
        [7] = {itemid = 2120, count = 1},
        [8] = {itemid = 2512, count = 1},
        [9] = {itemid = 2382, count = 1},
        [10] = {itemid = 2554, count = 1}
        }
   }
  
  
}

Action Code
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player = Player(player)
    chest = questChests[item:getAttribute('uid')]
    if not chest then return true end
  
    --------------Check if player has already opened the chest-----
    if player:getStorageValue(item:getAttribute('uid')) == 1 then
        return player:sendCancelMessage("The chest is empty.")
    end
  
    --------------Check if player has quest status-----------------
    if chest.storage and chest.status then
        if player:getStorageValue(chest.storage) ~= chest.status then
            return player:sendCancelMessage(chest.questMsg_fail)
        end
    end
  
    ---------------Check if player has level requirement------------
    if chest.levelReq then
        if player:getLevel() < chest.levelReq then
            return player:sendCancelMessage("You must be level "..chest.levelReq.. " to open this chest.")
        end
    end
  
    --------------Check if player has key required-------------------
    if chest.keyReq then
        if player:getItemCount(chest.keyReq) < 1 then
            return player:sendCancelMessage("This chest requires a key to open.")
        end
    end
  
    ------------Give player EXP reward-------------------------------
    if chest.expReward then
        player:addExperience(chest.expReward, true)
    end
  
    ------------Give player reward items---------------------
    if chest.item_reward then
        for i = 1, #chest.item_reward do
            player:addItem(chest.item_reward[i].itemid, chest.item_reward[i].count, 1)
        end
    end
  
    ------------Give player outfit reward--------------------
    if chest.outfit_reward then
        for i = 1, #chest.outfit_reward do
            if player:getSex() == 0 then
                player:addOutfit(chest.outfit_reward[i].female, chest.outfit_reward[i].addons)
            else
                player:addOutfit(chest.outfit_reward[i].male, chest.outfit_reward[i].addons)
            end
        end
    end
  
    -----------Give player addon reward-----------------------
    if chest.addon_reward then
        for i = 1, #chest.addon_reward do
            if player:getSex() == 0 then
                if chest.addon_reward.addons == 1 then
                    player:addOutfitAddon(chest.addon_reward[i].female, 1)
                else
                    player:addOutfitAddon(chest.addon_reward[i].female, 1)
                    player:addOutfitAddon(chest.addon_reward[i].female, 2)
                end
            else
                if chest.addon_reward.addons == 1 then
                    player:addOutfitAddon(chest.addon_reward[i].male, 1)
                else
                    player:addOutfitAddon(chest.addon_reward[i].male, 1)
                    player:addOutfitAddon(chest.addon_reward[i].male, 2)
                end
            end
        end
    end
  
    ----------Give player mount reward--------------------------
    if chest.mount_reward then
        for i = 1, #chest.mount_reward do
            player:addMount(chest.mount_reward.mountId)
        end
    end
  
    if chest.questStatus then
        player:setStorageValue(chest.questStorage, chest.questStatus + 1)
    end
  
    player:sendCancelMessage("You have recieved your reward.")
    player:setStorageValue(item:getAttribute('uid'), 1)
    return false
end
Thankkkk youu!
 
i can't really figure it out.

how do i add quests?

like this?

Lua:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [2100] = {
       minLevel = 7,
       items = {
           [1] = {type = "item", item = 2160, count = 1},
           [2] = {type = "experience", amount = 20000},
           [3] = {type = "outfit", name = "nobleman", femaleId = 140, maleId = 132},
           [4] = {type = "addon", outfit = "nobleman", addonNumber = 1, femaleId = 140, maleId = 132},
           [5] = {type = "mount", mountName = "Dromedary", mountId = 20},
       },
   },
   ---------------------------------------------------------
   [2101] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2486, count = 1}, -- Noble Armor
       },
   },
   ---------------------------------------------------------
   [2102] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2391, count = 1}, -- War Hammer
       },
   },
}

etc..?
 
i can't really figure it out.

how do i add quests?

like this?

Lua:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [2100] = {
       minLevel = 7,
       items = {
           [1] = {type = "item", item = 2160, count = 1},
           [2] = {type = "experience", amount = 20000},
           [3] = {type = "outfit", name = "nobleman", femaleId = 140, maleId = 132},
           [4] = {type = "addon", outfit = "nobleman", addonNumber = 1, femaleId = 140, maleId = 132},
           [5] = {type = "mount", mountName = "Dromedary", mountId = 20},
       },
   },
   ---------------------------------------------------------
   [2101] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2486, count = 1}, -- Noble Armor
       },
   },
   ---------------------------------------------------------
   [2102] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2391, count = 1}, -- War Hammer
       },
   },
}

etc..?

Look at the example quest:
Code:
questChests = {
    ---------------------------------------------------------
   -- Example Quest Box 1
   ---------------------------------------------------------
   [2100] = {
       minLevel = 7,
       items = {
           [1] = {type = "item", item = 2160, count = 1},
           [2] = {type = "experience", amount = 20000},
           [3] = {type = "outfit", name = "nobleman", femaleId = 140, maleId = 132},
           [4] = {type = "addon", outfit = "nobleman", addonNumber = 1, femaleId = 140, maleId = 132},
           [5] = {type = "mount", mountName = "Dromedary", mountId = 20},
       },
   },
   [example quest] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2486, count = 1}, -- Noble Armor
       },
   },
   ---------------------------------------------------------
   [2101] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2486, count = 1}, -- Noble Armor
       },
   },
   ---------------------------------------------------------
   [2102] = {
       minLevel = 8,
       items = {
           [1] = {type = "item", item = 2391, count = 1}, -- War Hammer
       },
   },
}
 
ive updated to theforgottenserver-v1.2-win64
(tfs 1.2)
seems like i just didn't do it right.


the original script got me into loop of errors.
so i use this
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(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

Lua:
questChests = {
--Main example--
   [3000] = {
        questStorage = 10000,
        questStatus = 5,
        questMsg_success = "You have found the item now go do blah blah blah",
        questMsg_fail = "You are not ready to open this chest. Go do blah blah blah",
        levelReq = 40,
        keyReq = 2143,
        expReward = 10000,
        item_reward = {
        [1] = {itemid = 1111, count = 1},
        [2] = {itemid = 1111, count = 1}
        },
        outfit_reward = {
        [1] = {male = 111, female = 111, addons = 0}
        },
        addon_reward = {
        [1] = {male = 111, female = 111, addons = 1}
        },
        mount_reward = {
        [1] = {mountId = 1}
        }
      
   },
--Test--
   [3001] = {
        questStorage = 10000,
        questStatus = 5,
        questMsg_success = "You have found the item now go do blah blah blah",
        questMsg_fail = "You are not ready to open this chest. Go do blah blah blah",
        levelReq = 7,
        expReward = 10000,
        item_reward = {

        mount_reward = {
        [1] = {mountId = 4}
            }
      
        }
    }
}

i tested the dofile('data/lib/quest_chests.lua') line in both Lib and global and both have the same results
i don't get the reward and it says "The chest is empty."

note: remere map editor chest.
action ID: 2215
unique ID: 3001


problem is i don't get error so i can't locate the issue.. please help!..
 
when i don't use action id i get djinn corpse as reward, probably because its ID is 3001

IE: remere map editor chest.
action ID: 0
unique ID: 3001

and when i flip them nothing happned (chest just open and no reward)

IE: remere map editor chest.
action ID: 3001
unique ID: 0
 
Back
Top