Page 1 of 1
Getting the ID of toches and other spawned items?
Posted: Thu Oct 04, 2012 2:37 pm
by Lmaoboat
If I wanted to, say, destroy a torch holder and the torch inside it, how would I got about referring to the torch. I made an alcove that prints the id of the item placed in it, and torches spawned with the holder have a different one each time the game is loaded.
Re: Getting the ID of toches and other spawned items?
Posted: Thu Oct 04, 2012 3:07 pm
by Grimwold
Not sure if this works, but can you use entitiesAt(lvl,x,y) to get the id of the torch in the holder in square x,y
If you don't know the x,y but you know the name of the torch holder, you can get it's x,y first and then use entitiesAt() to get the name of the torch there.
ok a very basic script which I just tested (set to test level 1 square (15,14)):
Code: Select all
function findEntityNames()
for i in entitiesAt(1,15,14) do
hudPrint(i.name .. " with id = " .. i.id)
end
end
prints to the hud the name and id of all items in that square. in my case it returned torch_holder_1 and torch 2032
you could then process an IF statement based on the name that calls a destroy
Re: Getting the ID of toches and other spawned items?
Posted: Thu Oct 04, 2012 3:34 pm
by Grimwold
OK... this little script tests the names of objects in a square and if they begin with the word torch they are destroyed...
Code: Select all
function destroyTorches()
for i in entitiesAt(1,15,14) do
-- hudPrint(i.name .. " with id = " .. i.id)
if i.name:sub(1,5) == "torch"
then
i:destroy()
end
end
end
you could make the script more generic by passing variables for level, x and y to it.. so you could call destroyTorches(lvl,x,y)
Re: Getting the ID of toches and other spawned items?
Posted: Thu Oct 04, 2012 3:54 pm
by Lmaoboat
Thanks, that seems to do it.
Re: Getting the ID of toches and other spawned items?
Posted: Thu Oct 04, 2012 4:43 pm
by Lmaoboat
Hmm, spawned torches don't seem to have any sound effect, and I wanted to use torches to get the burning sound since couldn't figure out how to make a playSound start and stop.
Re: Getting the ID of toches and other spawned items?
Posted: Fri Oct 05, 2012 2:28 pm
by Lmaoboat
I'm trying to make a similar script for an enchanted item that damages nearby skeletons, what is it exactly that
does?
Re: Getting the ID of toches and other spawned items?
Posted: Sat Oct 06, 2012 1:18 am
by Grimwold
Lmaoboat wrote:I'm trying to make a similar script for an enchanted item that damages nearby skeletons, what is it exactly that
does?
i.name is the name of an item from the the loop.. in that case one of the entities
sub(1,5) means take a substring of the name starting at the character 1 and being 5 characters in length...
so if i.name = "torch_holder"
then i.name:sub(1,5) = "torch"
edit.. in the previous script it was basically a shortcut for selecting any of the following "torch" "torch_holder" and "torch_everburning"