Page 7 of 8

Re: How to check which item is in alcove?

Posted: Sun Oct 14, 2012 11:19 am
by Komag
no problem!

Re: How to check which item is in alcove?

Posted: Wed May 15, 2013 2:27 pm
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

Re: How to check which item is in alcove?

Posted: Wed May 15, 2013 7:47 pm
by Komag
looks like you just need "" around "elementalAltar"

Re: How to check which item is in alcove?

Posted: Wed May 15, 2013 10:12 pm
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?

Re: How to check which item is in alcove?

Posted: Fri May 17, 2013 12:47 pm
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.

Re: How to check which item is in alcove?

Posted: Sun Jan 26, 2014 6:03 pm
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.

Re: How to check which item is in a CELL

Posted: Sun Feb 16, 2014 5:05 pm
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):..

Re: How to check which item is in alcove?

Posted: Sun Feb 16, 2014 9:03 pm
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

Re: How to check which item is in alcove?

Posted: Mon Feb 17, 2014 7:04 pm
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?

Re: How to check which item is in alcove?

Posted: Mon Feb 17, 2014 7:14 pm
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^^