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

Chest that requires items to open

froie

Expert Mapper
Joined
May 27, 2013
Messages
196
Reaction score
4
Location
Canada
Hello everyone on OTland, I have been searching around and I can't seem to find the script for what i'm looking for, I was hoping someone could give me a hand, I would like to make a chest that you can only open ONCE and requires you to have.. 1 Red Dragon Claw (ID:5915), 50 green dragon leathers (ID:5877), 50 red dragon leathers (ID:5948), and 1 dragon lord trophy (ID:7399) so when you have these items it will take the items from you and give you your reward, but if you don't have these items it will not allow you to open the chest. I've tried to figure it out but i'm not the best scripter. Thank you for your time!
 
tfs 1.0, sorry for late reply
Code:
local config = {
    checkItems = {
        [1] = {item = 2674, count = 1},
        [2] = {item = 2050, count = 1},
    },
    rewards = {
        [1] = {item = 2140, count = 10},
    },
}

function onUse(player, item, fromPosition, itemEx, toPosition)
    for i = 1, #config.checkItems do
        if player:getItemCount(config.checkItems[i].item) < config.checkItems[i].count then
            player:say("You do not have the required items to open this chest", TALKTYPE_MONSTER_SAY)
            return false
        end
    end
    for i = 1, #config.rewards do
        player:addItem(config.rewards[i].item, config.rewards[i].count)
    end
    player:say("Congratulations you win stuff!", TALKTYPE_MONSTER_SAY)
    return true
end
 
Last edited:
Code:
local config = {
    checkItems = {
        [1] = {item = 2674, count = 1},
        [2] = {item = 2050, count = 1},
    },
    rewards = {
        [1] = {item = 2140, count = 10},
    },
}

function onUse(player, item, fromPosition, itemEx, toPosition)
    for i = 1, #config.checkItems do
        if player:getItemCount(config.checkItems[i].item) < config.checkItems[i].count then
            player:say("You do not have the required items to open this chest", TALKTYPE_MONSTER_SAY)
            return false
        end
    end
    for i = 1, #config.rewards do
        player:addItem(config.rewards[i].item, config.rewards[i].count)
    end
    player:say("Congratulations you win stuff!", TALKTYPE_MONSTER_SAY)
end
dont forget return true
:|
 
Change:
Code:
function onUse(player, item, fromPosition, itemEx, toPosition)
To:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local player = Player(cid)
...
That usually does the trick.
 
Okay! I tried that but it still said player, I added "cid" to the beginning of the original script that strutz posted and now im getting this error.
https://imgur.com/vdN2f8Q

this is the script now.

Code:
local config = {

    checkItems = {
        [1] = {item = 5919, count = 1},
        [2] = {item = 5877, count = 50},
        [3] = {item = 5948, count = 50},
        [4] = {item = 7399, count = 1},
    },
    rewards = {
        [1] = {item = 9932, count = 1},
    },
}

function onUse(cid, player, item, fromPosition, itemEx, toPosition)
    for i = 1, #config.checkItems do
        if player:getItemCount(config.checkItems[i].item) < config.checkItems[i].count then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have the required items to open the chest.")
            return false
        end
    end
    for i = 1, #config.rewards do
        player:addItem(config.rewards[i].item, config.rewards[i].count)
    end
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found the special boots!")
    return true
end
 
Edit: Removes items now.
Code:
local config = {
    storageValue = 1234,
    checkItems = {
        [1] = {item = 5919, count = 1},
        [2] = {item = 5877, count = 50},
        [3] = {item = 5948, count = 50},
        [4] = {item = 7399, count = 1}
    },
    rewards = {
        [1] = {item = 9932, count = 1}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStorageValue(cid, config.storageValue) ~= 1 then
        local player = Player(cid)
        for i = 1, #config.checkItems do
            if player:getItemCount(config.checkItems[i].item) < config.checkItems[i].count then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have the required items to open the chest.")
                return false
            end
        end
        for i = 1, #config.checkItems do
            player:removeItem(config.checkItems[i].item, config.checkItems[i].count)
        end
        for i = 1, #config.rewards do
            player:addItem(config.rewards[i].item, config.rewards[i].count)
        end
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found the special boots!")
        setPlayerStorageValue(cid, config.storageValue, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already obtained the reward.")
        return false
    end
    return true
end
 
Last edited:
Should work like this, I also added the storage value.
Code:
local config = {
    storageValue = 1234,
    checkItems = {
        [1] = {item = 5919, count = 1},
        [2] = {item = 5877, count = 50},
        [3] = {item = 5948, count = 50},
        [4] = {item = 7399, count = 1},
    },
    rewards = {
        [1] = {item = 9932, count = 1},
    },
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStorageValue(cid, config.storageValue) ~= 1 then
        local player = Player(cid)
        for i = 1, #config.checkItems do
            if player:getItemCount(config.checkItems[i].item) < config.checkItems[i].count then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have the required items to open the chest.")
                return false
            end
        end
        for i = 1, #config.rewards do
            player:addItem(config.rewards[i].item, config.rewards[i].count)
        end
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found the special boots!")
        setPlayerStorageValue(cid, config.storageValue, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already obtained the reward.")
        return false
    end
    return true
end
still using player:getItemCount so he will get the same error, apparently 1.0 doesn't have that method for some reason
 
still using player:getItemCount so he will get the same error, apparently 1.0 doesn't have that method for some reason

Edit: He was getting that error because he placed player as the 2nd argument of the interface which is supposed to be item. So he was basically trying to do item:getItemCount() which doesn't exist.

Just tested it on 1.0 and it worked, I forgot to remove the items though.
 
Code:
function doHaveItemsFromList(cid,items)
    local count = 0
    if table.maxn(items) > 0 then
        for i = 1, table.maxn(items) do
            if getPlayerItemCount(cid,items[1]) >= items[2] then
            count = count + 1 end
        end
    end
    return count == table.maxn(items) and true or false
end
function onUse(cid, player, item, fromPosition, itemEx, toPosition)
local ret,reward = {{5919,1},{5877,50},{5948,50},{7399,1}},9932
local storage = 58754
if not doHaveItemsFromList(cid, ret) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have the required items to open the chest.") return true
elseif getPlayerStorageValue(cid, storage) > 0
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Its Empty.") return true
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found the special boots!")
setPlayerStorageValue(cid, storage, 1)
doPlayerAddItem(cid, reward, 1)
return true
end
 
Code:
function doHaveItemsFromList(cid,items)
    local count = 0
    if table.maxn(items) > 0 then
        for i = 1, table.maxn(items) do
            if getPlayerItemCount(cid,items[1]) >= items[2] then
            count = count + 1 end
        end
    end
    return count == table.maxn(items) and true or false
end
function onUse(cid, player, item, fromPosition, itemEx, toPosition)
local ret,reward = {{5919,1},{5877,50},{5948,50},{7399,1}},9932
local storage = 58754
if not doHaveItemsFromList(cid, ret) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have the required items to open the chest.") return true
elseif getPlayerStorageValue(cid, storage) > 0
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Its Empty.") return true
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found the special boots!")
setPlayerStorageValue(cid, storage, 1)
doPlayerAddItem(cid, reward, 1)
return true
end
why do you kinda tab the itemsfromlist function but not onuse at all
 
Back
Top