how to destroy item on an altar?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: how to destroy item on an altar?

Post 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.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: how to destroy item on an altar?

Post 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.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: how to destroy item on an altar?

Post 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?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: how to destroy item on an altar?

Post 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 :)
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: how to destroy item on an altar?

Post 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.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: how to destroy item on an altar?

Post 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?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: how to destroy item on an altar?

Post 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
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply

Return to “Mod Creation”