• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Chest-With Bag + Items in Bag Help

balador

New Member
Joined
Jan 31, 2010
Messages
23
Reaction score
0
I've been doing fine learning how to do some simple scripts with chests and what not. Only thing is I can't figure out how to have a bag in a chest and have items in the bag also. Maybe i'm just overlooking something simple. I don't know. I'm using tfs 3.6p1. Can someone give me an example? I thought I saw one here but I looked and couldn't find it.
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local cfg = {}
	cfg.items = { {2160,10},{2152,10} }
	cfg.container = 1988
	local bp = doCreateItemEx(cfg.container, 1)
	for i = 1, getContainerCapById(cfg.container) do
		doAddContainerItem(bp, cfg.items[1], cfg.items[2])
	end
	if doPlayerAddItemEx(cid, bp, 0) == RETURNVALUE_NOERROR then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have found a container with items inside!")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You do not have enough capacity/space to carry this.")
	end
	return true
end
 
Last edited:
Thanks I appreciate the fast reply. It's a little complicated but I'm gonna examine it and mess with it and try to figure it out to work with some of my other scripts.
 
This is the main part that adds the items in the script.

Code:
local bp = doCreateItemEx(cfg.container, 1)
	for i = 1, getContainerCapById(cfg.container) do
		doAddContainerItem(bp, cfg.items[1], cfg.items[2])
	end
 
I understand most of it. I'm probably overlooking something simple. Say I want to add the script you posted to this. Is there a way to do it, or do I have to rewrite the whole script?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1740 and item.uid == xxxxx then
        if getPlayerStorageValue(cid,xxxxx) == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a !")
            doPlayerAddItem(cid,,1)
            setPlayerStorageValue(cid,xxxxx,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.itemid == 1740 and item.uid == xxxxx then
        if getPlayerStorageValue(cid,xxxxx) == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a !")
            doPlayerAddItem(cid,,1)
            setPlayerStorageValue(cid,xxxxx,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    if item.itemid == 1740 and item.uid == xxxxx then
        if getPlayerStorageValue(cid,xxxxx) == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a !")
            doPlayerAddItem(cid,,1)
            setPlayerStorageValue(cid,xxxxx,1)
        else
            doPlayerSendTextmessage(cid,22,"It Is empty.")
        end
 
i think it is easier doing it with the map editor remeres
aid = 2000
uid = any "better if you put an item id that is inside the chest"

then add any item inside the chest or a bp and then items inside.
 
All it did was repeat. I don't know. I've been working on it for 2 days now. I give up on it. Thanks for all the help though.
 
[10000] is the chest unique id.
I hope this is what you wanted. I made it so you only have to edit the top part.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local chests = {
		[10000] = {
			items = { {2160,10},{2152,10} },
			container = 1988,
			storage = 5511,
			msg = "You have found a bag full of items."
		},
		[10001] = {
			items = { {2160,10},{2152,10} },
			container = 1988,
			storage = 5511,
			msg = "You have found a bag full of items."
		},
		[10002] = {
			items = { {2160,10},{2152,10} },
			container = 1988,
			storage = 5511,
			msg = "You have found a bag full of items."
		}
	}
	local bp = doCreateItemEx(chests[item.uid].container, 1)
	for i = 1, getContainerCapById(chests[item.uid].container) do
		doAddContainerItem(bp, chests[item.uid].items[1], chests[item.uid].items[2])
	end
	if(doPlayerAddItemEx(cid, bp, 0) == RETURNVALUE_NOERROR) then
		if(getPlayerStorageValue(cid, chests[item.uid].storage) == -1) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, chests[item.uid].msg)
			setPlayerStorageValue(cid, chests[item.uid].storage, 1)
		else
			doPlayerSendCancel(cid, "You have already received your reward.")
		end
	else
		doPlayerSendCancel(cid, "You do not have enough capacity/space.")
	end
	return true
end
 
Thanks JDB. I appreciate it. Guess it's just going to take me a little bit longer to learn how to code good/properly. I appreciate all the help I've gotten.
 
No problem, I hope that's just what you wanted...seems that it is.
Good luck with your project. :thumbup:
 
Strange, it loads up with no errors but when I click the chest. It gives me the backpack but no items. This is the error I get.

[26/02/2010 19:23:52] [Error - Action Interface]
[26/02/2010 19:23:52] data/actions/scripts/bagtest.lua:onUse
[26/02/2010 19:23:52] Description:
[26/02/2010 19:23:52] (luaDoAddContainerItem) Item not found
 
Code:
local chests = {
	[10000] = {
		items = { {2160,10},{2152,10} },
		container = 1988,
		storage = 5511,
		msg = "You have found a backpack full of items."
	},
	[10001] = {
		items = { {2160,10},{2152,10} },
		container = 1988,
		storage = 5511,
		msg = "You have found a backpack full of items."
	},
	[10002] = {
		items = { {2160,10},{2152,10} },
		container = 1988,
		storage = 5511,
		msg = "You have found a backpack full of items."
	}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local v = chests[item.uid]
	if v then
		local bp = doCreateItemEx(v.container, 1)
		for i = 1, #v.items do
			doAddContainerItem(bp, v.items[i][1], v.items[i][2])
		end
		if getPlayerStorageValue(cid, v.storage) < 1 then
			if doPlayerAddItemEx(cid, bp, 0) == 1 then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, v.msg)
				setPlayerStorageValue(cid, v.storage, 1)
			else
				doPlayerSendCancel(cid, "You don't have enough capacity or free space.")
			end
		else
			doPlayerSendCancel(cid, "The " .. getItemName(item.uid) .. " is empty.")
		end
		return true
	end
end
 
It works and thanks again. Now that you mentioned something about a built in quest system. I'm gonna start trying to mess with that now.
 
Back
Top