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

Lua Quest Chests help

darkangel1

New Member
Joined
Oct 31, 2023
Messages
53
Reaction score
4
Hello community. Please tell me. I have 5 chests, you can take one weapon of your choice, then you can’t take another. And there are 2 chests behind the doors 10 and 30 lvl. I put crystals there. If I take a weapon, I can’t take the crystal anymore, because it writes empty, and if I first take the crystal, then I can’t take the weapon. Both scripts are attached. What am I doing wrong, please tell me

Lua:
--[[

    Anni-style chests.
 
    This script goes into data/scripts as a .lua file

    1) Place 2+ chests into map editor
    2) Place Same ActionId onto all chests. (example: 45000)
    3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
    4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
    5) Update table with itemId's, count's and an unused storage number
    6) Restart Server, and test

]]--

local rewardChests = {
----[actionId] = {
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    [uniqueId] = {itemId = ####, count = #},
----    storage = #####
----},
    [45000] = { -- 45000 as Action id on ALL 3 chests
        [45001] = {itemId = 1294, count = 100},
        [45002] = {itemId = 2394, count = 1},
        [45003] = {itemId = 2374, count = 1},
    [45004] = {itemId = 2383, count = 1},
        [45005] = {itemId = 2190, count = 1},
        [45006] = {itemId = 2182, count = 1},
        storage = 45000
    }
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChests[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
 
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local reward = ItemType(index.itemId)
    local rewardWeight = reward:getWeight() * index.count
    if rewardWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
        return true
    end
 
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
 
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
    return true
end

Code:
local rewardChestscrystal = {
    [45007] = { -- 45000 as Action id on ALL 3 chests
        [45008] = {itemId = 2160, count = 5}, --45001 as UNIQUE id on chest for item 2190
        storage = 45007
    },
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local index = rewardChestscrystal[item:getActionId()][item:getUniqueId()]
    if not index then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
        print("Error: UniqueId does not exist in table.")
        return true
    end
 
    if player:getStorageValue(index.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
        return true
    end

    local crystal = ItemType(index.itemId)
    local crystalWeight = crystal:getWeight() * index.count
    if crystalWeight > player:getFreeCapacity() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. crystal:getName() .. " weighing " .. crystalWeight .. " oz. It's too heavy.")
        return true
    end
 
    player:addItem(index.itemId, index.count, true)
    player:setStorageValue(index.storage, 1)
 
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. crystal:getName() .. ".")
    return true
end
Post automatically merged:

and can I put multiple items in one chest?
 

Attachments

Lua:
local rewardChests = {
    [45000] = { -- 45000 as Action id on ALL 3 chests
        [45001] = {itemId = 1294, count = 100},
        [45002] = {itemId = 2394, count = 1},
        [45003] = {itemId = 2374, count = 1},
        storage = 45000
    },
    [45001] = { -- Action id
        [45004] = {itemId = 2383, count = 1}, -- Unique ID
        [45005] = {itemId = 2190, count = 1}, -- Unique ID
        [45006] = {itemId = 2182, count = 1}, -- Unique ID
        storage = 45001
    },
    [45002] = { -- Action id
        [45008] = {itemId = 2160, count = 5}, -- Unique ID
        storage = 45002
    }
}
 
Lua:
local rewardChests = {
    [45000] = { -- 45000 as Action id on ALL 3 chests
        [45001] = {itemId = 1294, count = 100},
        [45002] = {itemId = 2394, count = 1},
        [45003] = {itemId = 2374, count = 1},
        storage = 45000
    },
    [45001] = { -- Action id
        [45004] = {itemId = 2383, count = 1}, -- Unique ID
        [45005] = {itemId = 2190, count = 1}, -- Unique ID
        [45006] = {itemId = 2182, count = 1}, -- Unique ID
        storage = 45001
    },
    [45002] = { -- Action id
        [45008] = {itemId = 2160, count = 5}, -- Unique ID
        storage = 45002
    }
}
No working =(
 
Back
Top