Page 1 of 1

custom torches and torchholders

Posted: Tue Sep 18, 2012 2:54 pm
by velojun
so far ive created a new torch holder:
cloneObject{
name = "sacrificial_torch_holder",
baseObject = "torch_holder",
}

and a new torch:
cloneObject{
name = "sacrificial_torch",
baseObject = "torch_everburning",
uiName = "sacrificial_torch",
attackPower = 8,
damageType = "fire",
description = "This Torch is rapped in bandages, its fire seems brighter.",
}

now i would like this torch holder to trigger a event only when this special torch is put in
I've no idea how script this

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 9:54 pm
by Neikun
Well since the torch holder is cloned from the original, you should be able to add a connector from it like any other torch holder, no?

I'm going to clone your code and see what I can come up with. If my theory proves right, the new torch holder should have all the capabilities of the original torch holder, only it is unique.

Note: I'm fairly certain the torch holder will belong in the object.lua and not the item.lua file.

Edit: Thinking further on this, what would be the way to keep it from being activated by any other torch?

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 9:59 pm
by Komag
that's precisely the question! 8-)

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 10:09 pm
by Komag
Maybe you could make a custom alcove using the torchholder model, but not sure how it would handle items being placed into it

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 10:11 pm
by Neikun
Komag wrote:that's precisely the question! 8-)
Well there is still a work around by removing the torch, but that's lame and doesn't highlight that the torch is special.
But if you use the torch itself on lets say, an alcove, that much should still be easy enough.

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 10:14 pm
by Komag
do you mean script it to remove any regular torches? how would it detect that?

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 10:19 pm
by Neikun
Oh no! I've been totally misunderstood.
Remove the sacrificial torch from the sacrificial holder.

Re: custom torches and torchholders

Posted: Tue Sep 18, 2012 11:45 pm
by Lilltiger
So i figured out a way to do this, but it's a hack that requires that there are no torches on the ground in the holders square that was placed there in the editor(facing the same way as the holder) or thrown there facing the holder, if there are the script will tell the player to remove them.

You need a torch holder that triggers this script with id "special_torch_holder", and right now it checks the id for a torch with the id "special_torch" but for your new torch types change the check to look at the name instead of the id.

Code: Select all

function addTorch()
	x = special_torch_holder.x
	y = special_torch_holder.y
	l = special_torch_holder.level
	
	-- Gather all torches avaible in the square
	torch_table = {}
	for i in entitiesAt(l, x, y) do
		-- Does the item have torch in the name
		if( string.find(i.name, "torch") ~= nil ) then
			-- Make sure it dosent have holder in it's name
			if( string.find(i.name, "holder") == nil ) then
				table.insert(torch_table,i)
			end
		end 
	end
	print(#torch_table)
	
	for id, torch in ipairs(torch_table) do
		-- Exlude all that is on heroes
		for hero = 1, 4 do
			champ = party:getChampion(hero)
			for i = 1, 31 do
				if( champ:getItem(i) == torch ) then
					table.remove(torch_table,id)
				end
			end
		end
		-- Remove all torches not facing the same way as the torch holder
		if( torch.facing ~= special_torch_holder.facing ) then
			table.remove(torch_table,id)
		end
	end
	
	-- Now torch_table only includes items on the ground or in the holder
	-- and facing the same way as the holder
	
	-- Only activate if there is only one torch
	if( #torch_table == 1 ) then
		-- Get the last item in the table, and the only item
		torch = table.remove(torch_table)
                -- Here you can change it to check (torch.name == "sacrificial_torch") instead
		if( torch.id == "special_torch" ) then
                        -- Do the stuff it should when the special torch is inserted
			hudPrint("Special torch inserted")
		end
	else
		hudPrint("Remove all other torches from the floor")
	end
end

Re: custom torches and torchholders

Posted: Wed Sep 19, 2012 2:38 pm
by velojun
i was kind of hoping for a hook in the objects file simular to the daemon eye socket one ,,,, :shock:

Re: custom torches and torchholders

Posted: Fri Sep 21, 2012 12:59 am
by Neikun
I'VE GOT IT!
Make your torch holder a lock and your torch a key!