[Request] A new hook for alcove "onRemoveItem"

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Darklynx
Posts: 9
Joined: Thu Apr 12, 2012 4:06 pm
Location: Italy, Rome

[Request] A new hook for alcove "onRemoveItem"

Post by Darklynx »

I'm doing a complex puzzle in my dungeon with custom alcoves, but i can't find a hook to launch a function when an item is removed from the alcove.
I need this because the player need to put a certain item in order in a series of alcoves, and this is doable with "onInsertItem", but i need the exactly opposite and i can't find the way :?
With a hook like "onRemoveItem" i could do it, but there is no "onRemoveItem" :(

I can launch a function when the alcove is deactivated, but it isn't what i need. I need to deny the remove of the item if certain conditions are not met.

I think a hook of this kind can be useful also for other uses.

TY :oops:
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Lmaoboat »

Can't you just make a script that activates upon putting that specific item in that alcove, and then keeps checking to see if it's been removed?
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Batty »

A complex answer would be to replace the alcove with another alcove that has no clickbox so they can't remove the item (knowing that they've put it in there). You should explain the details of the puzzle.

There's also the party onPickUpItem hook maybe that'd be useful.
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: [Request] A new hook for alcove "onRemoveItem"

Post by crisman »

This looks pretty difficult, if you explain the puzzle maybe we can come up with something!
Or an alternative :D
Lilltiger
Posts: 95
Joined: Sun Sep 16, 2012 1:12 am

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Lilltiger »

You can easily solve this with "onPickUpItem"

items.lua:

Code: Select all

cloneObject{
    name = "party",
    baseObject = "party",
    onPickUpItem = function(party, self)
        -- Let the script decide if the item should be picked up or not.
        return puzzle_script.checkConditions(party,self)
    end
}
In the editor make a script, name it to:
puzzle_script

Code: Select all

function checkConditions(party, item)
    -- Check the conditions here, and then return true if you can pick up the item, else return false
    -- In this case I prevent the player from picking up and blue_gem's at all
    if( item.name == "blue_gem" ) then
        return false
    end
   return true
end
Cant give more help without know more about what you are trying to do.
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: [Request] A new hook for alcove "onRemoveItem"

Post by crisman »

Never tried that hook, I should give it a look!
User avatar
Lupe Fenrir
Posts: 25
Joined: Sun Oct 07, 2012 7:42 am
Location: Sweden

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Lupe Fenrir »

you could solve the problem by having a timer constantly updating the alcove by adding another item and then instantly removing it. this has the problem that it removes any item of the same type as the "update item" that the player may put there though.
Edit: Actualy if you just break the loop after it have removed the item it added, you won't have this problem. I uppdated the script example accordingly.

Code: Select all

function update()
	dungeon_alcove_1:addItem(spawn("dagger"))
	for i in dungeon_alcove_1:containedItems() do
		if i.name == "dagger" then
			i:destroy()
         break
		end
	end
end
My name is Torsek in some places
User avatar
Lupe Fenrir
Posts: 25
Joined: Sun Oct 07, 2012 7:42 am
Location: Sweden

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Lupe Fenrir »

Lupe Fenrir wrote:you could solve the problem by having a timer constantly updating the alcove by adding another item and then instantly removing it. this has the problem that it removes any item of the same type as the "update item" that the player may put there though.
Edit: Actualy if you just break the loop after it have removed the item it added, you won't have this problem. I uppdated the script example accordingly.

Code: Select all

function update()
	dungeon_alcove_1:addItem(spawn("dagger"))
	for i in dungeon_alcove_1:containedItems() do
		if i.name == "dagger" then
			i:destroy()
         break
		end
	end
end
Or you could just have the timer update the script that checks if the item is there.
I'm over-thinking things again. :P
My name is Torsek in some places
Darklynx
Posts: 9
Joined: Thu Apr 12, 2012 4:06 pm
Location: Italy, Rome

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Darklynx »

Thank you guys, it was really simple :D
I solved it with this function:

Code: Select all

function alcove_onDeactivate()
	setMouseItem()
        -- Destroy the gem collected
	alcove:addItem(spawn("green_gem"))
        -- Respawn instantly the gem
end
I can put the gem in the alcove, but i can't remove it :)
Darklynx
Posts: 9
Joined: Thu Apr 12, 2012 4:06 pm
Location: Italy, Rome

Re: [Request] A new hook for alcove "onRemoveItem"

Post by Darklynx »

I have found a more clean (and silent) solution:

Code: Select all

cloneObject{
	name = "party",
	baseObject = "party",
	onPickUpItem = function(party, item)
		if item.name == "green_gem_PH" then return false end
	end,
}
cloneObject{
	name = "green_gem_PH",
	baseObject = "green_gem",
}

Code: Select all

function alcove_onActivate()
	local alcove = findEntity("alcove_name")
	for i in alcove:containedItems() do
		if i.name == "green_gem" then
			i:destroy()
			alcove:addItem(spawn("green_gem_PH"))
		end
	end
end
In this way you can move the Green Gem normally, but when you put it in the alcove is destroyed and replaced with a Green Gem not movable. :mrgreen:

Thank you again guys for the help :)
Post Reply