Page 1 of 2

[Request] A new hook for alcove "onRemoveItem"

Posted: Sat Oct 06, 2012 8:31 pm
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:

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

Posted: Sat Oct 06, 2012 8:45 pm
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?

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

Posted: Sat Oct 06, 2012 10:19 pm
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.

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

Posted: Sun Oct 07, 2012 12:10 am
by crisman
This looks pretty difficult, if you explain the puzzle maybe we can come up with something!
Or an alternative :D

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

Posted: Sun Oct 07, 2012 12:25 am
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.

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

Posted: Sun Oct 07, 2012 1:45 am
by crisman
Never tried that hook, I should give it a look!

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

Posted: Sun Oct 07, 2012 8:38 am
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

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

Posted: Sun Oct 07, 2012 9:45 am
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

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

Posted: Sun Oct 07, 2012 10:36 am
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 :)

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

Posted: Sun Oct 07, 2012 12:50 pm
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 :)