Page 2 of 2

Re: magic bag request

Posted: Thu May 08, 2014 10:44 pm
by JohnWordsworth
@Isaac: The problem is that the game itself adds up the weight of all items within a container and adds them to your inventory weight. So even if the bag weighs 0, the engine will add up the contents and add them on top.

@MsyBlade: That's a nice idea. Like a pocket dimension / portable hole. What's nice about this is that you could also have an easy solution: Use an item, generate a 1-use teleporter in front of you (player only) which takes you to a small room somewhere in the dungeon. A small 1x2 room with bunch of alcoves and a teleporter taking you back to where you started. The more complicated solution - like you suggest, is also nice. You could teleport all of the contents of the 'bag' onto the square in front of you when you use the item. Use it again and everything in that square gets teleported to the pocket dimension.

Re: magic bag request

Posted: Fri May 09, 2014 1:20 am
by minmay
Sometimes I'll see a problem and instantly think of the worst possible solution to it. This was one of those times, but unlike most of those times I decided to implement it:
SpoilerShow
First, I define 10001 sacks, with weights ranging from 0 to -1000.0 kg:

Code: Select all

for i = 0, 10000 do
        defineObject{
                name = "sack_holding"..i,
                class = "Item",
                uiName = "Sack of Holding",
                model = "assets/models/items/sack_empty.fbx",
                gfxIndex = 82,
                weight = i*-0.1,
                container = true,
                containerType = "sack",
                capacity = 6,
        }
end
Then, I give the party this onDrawGui hook:

Code: Select all

function onDrawGui(gui)
	local sack, champ, slot = findSack()
	if sack then
		local weight = sack:getWeight()
		-- without a tolerance it can get stuck at 0.0, and 0.04 should guarantee 0.1kg differences are always caught
		if weight <= -0.04 or weight >= 0.04 then
			local newSack = spawn("sack_holding"..sack.name:sub(13)+weight*10)
			for i = 1, 6 do
				local item = sack:getItem(i)
				if item then newSack:addItem(item) end
			end
			champ:removeItem(slot)
			champ:insertItem(slot,newSack)
			sackWeight = newSack:getWeight()
		end
	end
end
The findSack helper function:

Code: Select all

function findSack()
	for i = 1, 4 do
		local champ = party:getChampion(i)
		for j = 7, 31 do
			local item = champ:getItem(j)
			if item and item.name:find("sack_holding") then
				return item, champ, j
			end
		end
	end
	return nil, nil, nil
end
The result is a sack that weighs 0.0 kg or -0.0 kg no matter what you put in or take out of it! It also closes every time you put something in or take something out of it! And changes its id! (you can fix that one though)! It also results in getting 10 FPS in the dungeon editor because you defined 10001 extra items!

Please don't do this.

Re: magic bag request

Posted: Fri May 09, 2014 3:32 pm
by bongobeat
humm, I'm not a scripter, so … this is quite beyond my understanding :?

anyway to answer to Komag:

yes it is possible to give a negative weight to an item.
SpoilerShow
defineObject{
name = "magic_bag",
class = "Item",
uiName = "Magig Bag",
model = "assets/models/items/sack_empty.fbx",
gfxIndex = 82,
weight = -10,
container = true,
containerType = "sack",
capacity = 6,
}
that result to remove 10 kg of the total weight of one champion
that's not the purpose, as it removes weight even if you did not put items in the sack, but it grant you to port 10 kilos more.
(very barbaric solution)

Re: magic bag request

Posted: Fri May 09, 2014 3:39 pm
by Komag
Master Quest already has code to store all info about all objects in a container, even nested containers, including charges, torch fuel, etc, and re-create them all. I used it for the dream sequences if the player was holding items on the mouse pointer. After the dream it's all recreated properly. So it could just recreate everything with the proper negative weight bag. But without hooks to trigger it, I'm not sure when to trigger it, so it might have to be done with GUI stuff.