Page 2 of 2

Re: how to destroy item on an altar?

Posted: Wed Jan 07, 2015 11:31 am
by bongobeat
Hoo St Scripter, ho St Scripter,
this makes another going into the unknow depth of the blackhole Script!

The platform (on the post above) has to be part of some scale with another platform which measure the weight, a bit higher, where the player has to put items to reach a certain weight:

The problem is: how to store the list of all items placed on the altar, destroy all of them when the correct weight is obtained, and respawn all items on a new altar according to the list?

this is the script of the weight test:
SpoilerShow

Code: Select all

    isFinished = false

    function weightcheck()
        if isFinished == true then
            return
        end

        if getWeight(platform_up_22_1) == 93.9 then
            mine_door_heavy_6.door:open()
            playSound("secret")
timer_158.timer:start()
            isFinished = true
        else
            mine_door_heavy_6.door:close()
        end
    end

    function getWeight(alcove)
        local a
        local b = 0

        for _, a in alcove.surface:contents() do
            b = b + (a:getWeight() * a:getStackSize())
        end

        return b
    end
When the correct weight is obtained, the items on the 2 platforms are destroyed, the platforms are destroyed, then another platforms (at same height) are spawned (this is done to make some kind of realistic scale movement of 2 platforms, moving up and down, when equaling their weight get the same size).
Finally, all items that were on the both platforms are respawned.

Re: how to destroy item on an altar?

Posted: Wed Jan 07, 2015 11:38 am
by Prozail
Why not change things around a bit. Spawn the new platforms first, then move the items from the old platforms to the new ones, and then destroy the old platforms. It's all happening in a single frame anyway so you won't notice the order.
This way you don't have to keep an intermediate list of the items, and you dont even have to respawn them, just move them.

Re: how to destroy item on an altar?

Posted: Wed Jan 07, 2015 7:52 pm
by bongobeat
Prozail wrote:Why not change things around a bit. Spawn the new platforms first, then move the items from the old platforms to the new ones, and then destroy the old platforms. It's all happening in a single frame anyway so you won't notice the order.
This way you don't have to keep an intermediate list of the items, and you dont even have to respawn them, just move them.
you mean, the first item you put on a platform, spawn the new platform?

how do you move items?

Re: how to destroy item on an altar?

Posted: Wed Jan 07, 2015 11:45 pm
by Prozail
ok.. this might not be what you want at all, but... if you have your two mine-platforms, one called platformA and another called platformB. Hook up both platforms insertItem and removeItem to the following script and try it out:

Code: Select all


function itemOnPlatform(sender)
	local wb = 0
	local wa = 0

	for _, a in platformA.surface:contents() do
		wa = wa + (a:getWeight() * a:getStackSize())
	end
	for _, a in platformB.surface:contents() do
		wb = wb + (a:getWeight() * a:getStackSize())
	end

	local height = math.max(1.0-(wa-wb)/10.0, 0) /2
	
	platformA:setWorldPositionY(height)
	platformB:setWorldPositionY(1.0-height)
	for _, a in platformA.surface:contents() do
		a.go:setWorldPositionY(height+0.4)
	end
	for _, a in platformB.surface:contents() do
		a.go:setWorldPositionY((1.0-height)+0.4)
	end
end

itemOnPlatform()

Not really sure if this is what your looking for, but it's a scale atleast :)

Re: how to destroy item on an altar?

Posted: Thu Jan 08, 2015 1:28 am
by JohnWordsworth
I definitely advise moving the items around - even if it means putting them on a hidden (never seen by the player) alcove somewhere. Then you don't have to worry about storing data about how many charges it has left etc.

Re: how to destroy item on an altar?

Posted: Thu Jan 08, 2015 6:32 pm
by bongobeat
waoww this looks amazing! it is visually, that I want. thanks :D

But the items that you put on any altars are invisible, is there any way to avoid that?

Re: how to destroy item on an altar?

Posted: Fri Jan 09, 2015 2:14 pm
by bongobeat
ok I did not saw the items, because I have tested the script on basic altar :lol: :
the items are put under the surface of the altar, at the defined height.

this is what it shows now with the height set to 0,87
SpoilerShow
Image
SpoilerShow

Code: Select all

    function itemOnPlatform(sender)
       local wb = 0
       local wa = 0

       for _, a in platform_scale.surface:contents() do
          wa = wa + (a:getWeight() * a:getStackSize())
       end
       for _, a in platform_scale2.surface:contents() do
          wb = wb + (a:getWeight() * a:getStackSize())
       end

       local height = math.max(1.0-(wa-wb)/10.0, 0) /2
       
       platform_scale:setWorldPositionY(height)
       platform_scale2:setWorldPositionY(1.0-height)
       for _, a in platform_scale.surface:contents() do
          a.go:setWorldPositionY(height+0.87)
       end
       for _, a in platform_scale2.surface:contents() do
          a.go:setWorldPositionY((1.0-height)+0.87)
       end
    end

    itemOnPlatform()

if someone wants to make such scale in his dungeon, here is the object definition:
SpoilerShow

Code: Select all

defineObject{
	name = "mine_counterweight_platform_altar",
	baseObject = "base_altar",
	components = {
		{
			class = "Model",
			model = "assets/models/env/mine_counterweight_platform_01.fbx",
			staticShadow = true,
			offset = vec(0, 0.0, 0),
		},
		{
			class = "Surface",
			offset = vec(0, 0.85, 0),
			size = vec(1, 1, 1),
			--debugDraw = true,
		},
	},
	minimalSaveState = true,
	automapIcon = 152,
}
I check the weight only on the left altar for the puzzle, but the 2 altars have to be connected to Prozail's script (thanks to him!) with insertItem and removeItem

then let the magic happens :D