Counting items in an alcove
Counting items in an alcove
If I wanted to check for a specific number of specific items in an alcove, how would I do that? I know how to check for specific items in an alcove, but what if there are two or more of the same item type?
To be more specific: I have three different items (item types) that can be placed in the alcove and each of them exists numerous times throughout the dungeon. I want the player to put exactly four of those items into the alcove (and no other items), in any combination. He can put in four times item 1, or three times item 2 and item 1 once or twice item 1 and twice item 3 or...you hopefully understand what I'm trying to do.
Any ideas how to script this?
To be more specific: I have three different items (item types) that can be placed in the alcove and each of them exists numerous times throughout the dungeon. I want the player to put exactly four of those items into the alcove (and no other items), in any combination. He can put in four times item 1, or three times item 2 and item 1 once or twice item 1 and twice item 3 or...you hopefully understand what I'm trying to do.
Any ideas how to script this?
Re: Counting items in an alcove
Code: Select all
function check()
local valid = {"blue_gem", "green_gem", "red_gem"}
local counter = 0
for i in alcove:containedItems() do
local ok = false
for j = 1,#valid do
if i.name == valid[j] then
counter = counter + 1
ok = true
break
end
end
if not ok then
counter = -1
break
end
end
--print(counter)
if counter == 4 then
teleporter_1:activate()
else
teleporter_1:deactivate()
end
endRe: Counting items in an alcove
Is that spam I see? o-o;
It was! It was spam I saw!
It was! It was spam I saw!
Last edited by Neikun on Sat Oct 20, 2012 1:19 pm, edited 1 time in total.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
- Message me to join in!
Re: Counting items in an alcove
....
Last edited by Batty on Mon Jan 23, 2017 10:22 pm, edited 1 time in total.
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Counting items in an alcove
xDDDDDDBatty wrote:well, we have a good name for a custom monster — the haohao
Final boss with unlimited life...
p.d: I hate spammers!
Re: Counting items in an alcove
Haha, now that the spam was deleted it sounds as if Neikun is a troll. 
Thank you Decayer, it works like a charm!
Thank you Decayer, it works like a charm!
Re: Counting items in an alcove
yeah, I wiped him and all posts out, probably messed up a few threads 
Finished Dungeons - complete mods to play
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Counting items in an alcove
First of all sorry for posting that here, maybe this isn't the most suitable place...
I didn't find a better leak... as I used the forum search tool, the word "alcove" returned at least 744 results. xDDDDDDD
I'm trying to create a room with 4 alcoves, with 4 items inside that alcoves (one item per alcove).
There's only one door, and that door only remains open IF in each alcove there's AT LEAST ONE item, doesn't matter if there's 8 items per alcove, doesn't matter what kind of item there are...
BUT if any alcove is empty, then the door remains closed.
That's the code I'm using, and I know that something is wrong... MAYBE with the code item_name?
Any help will be rewarded with the publication of a 5 levels dungeon (tested & detailed!!!) -coming soon-

Thanks everybody!!!
I didn't find a better leak... as I used the forum search tool, the word "alcove" returned at least 744 results. xDDDDDDD
I'm trying to create a room with 4 alcoves, with 4 items inside that alcoves (one item per alcove).
There's only one door, and that door only remains open IF in each alcove there's AT LEAST ONE item, doesn't matter if there's 8 items per alcove, doesn't matter what kind of item there are...
BUT if any alcove is empty, then the door remains closed.
That's the code I'm using, and I know that something is wrong... MAYBE with the code item_name?
Code: Select all
alcove_1_had_item = false
alcove_2_had_item = false
alcove_3_had_item = false
alcove_4_had_item = false
function altarHasItem(altar,item_name,had_item)
for i in altar:containedItems() do
if i.name == item_name then
if(had_item) then
playSound("lever")
end
return true
end
end
return false
end
function areItemsThere()
local alcove_1_ok = altarHasItem(alcove_1, "item", alcove_1_had_i)
local alcove_2_ok = altarHasItem(alcove_2, "item", alcove_2_had_i)
local alcove_3_ok = altarHasItem(alcove_3, "item", alcove_3_had_i)
local alcove_4_ok = altarHasItem(alcove_4, "item", alcove_4_had_i)
if(alcove_1_ok) then
alcove_1_had_item = true
end
if(alcove_2_ok) then
alcove_2_had_item = true
end
if(alcove_3_ok) then
alcove_3_had_item = true
end
if(alcove_4_ok) then
alcove_4_had_item = true
end
if alcove_1_ok and alcove_2_ok and alcove_3_ok and alcove_4_ok then
temple_alcove_door:open()
else
temple_alcove_door:close()
end
endThanks everybody!!!
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Counting items in an alcove
Please, some caritative soul that helps me!!!! 
I'm really having trouble with the code asking for placed items (look at my previous post).
I've tried everything I know about scripting but with no success...
What's the appropiate script to ask for "any" objetc in an alcove.
It's important to make mention that a counter will not work properly, as if I put two objects in an alcove BUT another alcove remains empty, the counter will work as if each alcove has two objects in them.
Thanks everybody (and again and again)!!!! Hehehe.
I'm really having trouble with the code asking for placed items (look at my previous post).
I've tried everything I know about scripting but with no success...
What's the appropiate script to ask for "any" objetc in an alcove.
It's important to make mention that a counter will not work properly, as if I put two objects in an alcove BUT another alcove remains empty, the counter will work as if each alcove has two objects in them.
Thanks everybody (and again and again)!!!! Hehehe.
Re: Counting items in an alcove
There is a way to do it with just counters, but you'd need to have 5 of them... 1 counter for each alcove initial value 1 which decrement when the alcove has an item inserted, and increment when the item is removed. Each of the 4 counters is linked to the 5th counter with decrement and increment events. the 5th counter has initial value 4 and when it reaches 0 the door opens.. if it deactivates then close the door.
To do the same puzzle with scripts all you need is to check alcove:getItemCount() ~= 0 for each one. e.g.
To do the same puzzle with scripts all you need is to check alcove:getItemCount() ~= 0 for each one. e.g.
Code: Select all
function checkAlcoves()
if alcove_1:getItemCount() ~= 0 and alcove_2:getItemCount() ~= 0 and alcove_3:getItemCount() ~= 0 and alcove_4:getItemCount() ~ 0 then
temple_alcove_door:open()
else
temple_alcove_door:close()
end
end
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
