How to check which item is in alcove?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How to check which item is in alcove?

Post by Komag »

no problem!
Finished Dungeons - complete mods to play
User avatar
The cube
Posts: 94
Joined: Tue Apr 23, 2013 6:09 pm
Location: Barren Desert

Re: How to check which item is in alcove?

Post by The cube »

How do i make this work with 4 specific types of items in a altar? (for example: scroll_fireball, scroll_ice_shards, scroll_poison_bolt, scroll_invisibility)
This code does nothing with all the items on the altar (called elementalAltar). the altar is connected to the script with the any option, and has activate always on.

Code: Select all

function aretheitemsthere()
if containsItem(elementalAltar, "scroll_poison_cloud") and containsItem(elementalAltar, "scroll_ice_shards")  and  containsItem(elementalAltar, "scroll_fireball")  and containsItem(elementalAltar, "scroll_invisibility") 
  then
    ironDoor2:open()
  else      
    ironDoor2:close() 
  end
end


function containsItem(entity, item)
    -- This function returns true if the entity contains a given item.
    -- It works for any entity that implements the containedItems() method.
  for i in entity:containedItems() do
    if i.name == item then
      return true
     end
   end
   -- if we get here the item was not found
   return false
end
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How to check which item is in alcove?

Post by Komag »

looks like you just need "" around "elementalAltar"
Finished Dungeons - complete mods to play
jpaf84
Posts: 10
Joined: Sun Mar 03, 2013 1:13 am

Re: How to check which item is in alcove?

Post by jpaf84 »

Hi. first I would like to say that I'm not very good at scripting.

That said I'm also trying to open a door using multiple alcoves. The thing is I want the door to open when the player inserts 1 treasure on each of the 4 alcoves. ANY treasures, not specific ones.
How can I do this? Is there a way I can make the script check for the "Treasure" flag instead of using names?
User avatar
Kuningas
Posts: 268
Joined: Wed Apr 11, 2012 10:29 pm
Location: Northern Finland

Re: How to check which item is in alcove?

Post by Kuningas »

Start with this if you have not (I presume you have)
http://www.grimrock.net/modding/how-to- ... ve-puzzle/

Make a list of your treasures (or a table, is it called that in here?), and check for that every time the alcove is accessed. (I'm sure someone can give you a more technical explanation of that part, tables are not something I am really familiar with), then make a counter that decrements each time a treasure is entered into an alcove and incremented when one is taken away.

Connect that counter to the door, so it opens when the counter hits zero. (a counter automatically fires when it hits zero, you only need to connect it, I believe)

You still need to make sure the alcove only counts one treasure per alcove. This can be done simply by checking it in the code before decrementing the counter.

This is a very verbal and even vague explanation -- I didn't have time to test it in the editor. I hope this is of help or that someone can give a more technical explanation. If not, I hope I can make a better attempt at this at a later time.
BASILEUS
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: How to check which item is in alcove?

Post by AdrTru »

What about check set of items in alcove?

Code: Select all

function checkItems(alcove)
  local ent
  local list = {"scroll","arrow","scroll","scroll"}   -- set of checked items
  table.sort(list)                                            -- short list for correct compare
  local inv = table.concat(list,",")                   -- make string from list for easy compare
  local alcoved = {}
  for ent in alcove:containedItems() do           -- make table of items in alcove
    table.insert(alcoved,ent.name)
  end
  table.sort(alcoved)                                      -- short items
  local alc = table.concat(alcoved,",")              -- make string
  if inv == alc then                                         -- compare two strings - alcoved items / checked items
--    print("good")
    return true
  end
--  print("bad")
  return false
end
There script may compare any defined items in list with items in alcove.
This way is useful for testing more items of one type.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
LordofKral
Posts: 27
Joined: Mon Feb 10, 2014 5:56 pm

Re: How to check which item is in a CELL

Post by LordofKral »

Hey Guys,
i´ve benn trying alot ,
but i cannot find a script that triggers when a specific item is in a cell.
Has anyone an idea? I´ve tried pressure_plates and stuff, but it doesn´t work /:
My Idea was to make an dungeon where you have to grow up your enemys...first button enables a lightsource,
and when a item called "Seed" is placed in a lighted area, an enemy "grows" (mbe after 3 seconds or so):..
User avatar
germanny
Posts: 530
Joined: Sat Apr 07, 2012 10:52 pm
Location: Kiel, Germany

Re: How to check which item is in alcove?

Post by germanny »

Try this:

Code: Select all

for i in entitiesAt(place.level,place.x,place.y) do
	if i.name == "that_item" then
		hudPrint("Your item is found: "..i.name)
	else return false
Script returns the i.name (item name) if found.
If your item has a specific Id, better ask with i.id
Dungeon Master Resource Pack worker and passionated Beer drinker
LordofKral
Posts: 27
Joined: Mon Feb 10, 2014 5:56 pm

Re: How to check which item is in alcove?

Post by LordofKral »

I think thath this could work well, but i guess i have to stop the for loop,
like with a break script.
and i have another Question:
How can i make my own"Seeds" (imported the model of green gems and renamed it) open the Demons maze?
User avatar
germanny
Posts: 530
Joined: Sat Apr 07, 2012 10:52 pm
Location: Kiel, Germany

Re: How to check which item is in alcove?

Post by germanny »

Code: Select all

for i in entitiesAt(place.level,place.x,place.y) do
        if i.name == "that_item" then
		hudPrint("Your item is found: "..i.name)
	else return false
        end
end
Forgot to paste the 'end' parts^^
Dungeon Master Resource Pack worker and passionated Beer drinker
Post Reply