Getting the ID of toches and other spawned items?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Getting the ID of toches and other spawned items?

Post 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.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Getting the ID of toches and other spawned items?

Post 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
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Getting the ID of toches and other spawned items?

Post 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)
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Re: Getting the ID of toches and other spawned items?

Post by Lmaoboat »

Thanks, that seems to do it.
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Re: Getting the ID of toches and other spawned items?

Post 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.
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Re: Getting the ID of toches and other spawned items?

Post by Lmaoboat »

I'm trying to make a similar script for an enchanted item that damages nearby skeletons, what is it exactly that

Code: Select all

 i.name:sub(1,5)
does?
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Getting the ID of toches and other spawned items?

Post 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

Code: Select all

 i.name:sub(1,5)
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"
Post Reply