How to check which item is in alcove?
Re: How to check which item is in alcove?
Generally speaking
this compares a with string "xxx":
If a == "xxx" then ...
while this compares a with the contents of variable xxx:
if a == xxx then ...
this compares a with string "xxx":
If a == "xxx" then ...
while this compares a with the contents of variable xxx:
if a == xxx then ...
Re: How to check which item is in alcove?
YES, it's working!
now to fill up that big weapon list (or at least the possible weapons the party could have by that point)
Code: Select all
function weaponCheck()
local weaponlist = { "dagger", "legionary_spear", "arrow" }
if weaponalcove:getItemCount() == 0
then
weapondoor:close()
else
for j=1,3 do
for i in weaponalcove:containedItems() do
if i.name == weaponlist[j]
then
weapondoor:open()
return
end
end
end
weapondoor:close()
end
end
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
Could somebody help:
How to make a trap action when alcove is completely empty?
How to make a trap action when alcove is completely empty?
Re: How to check which item is in alcove?
It's already there in the first part of my script:
You can make anything you want happen at that point
Code: Select all
if weaponalcove:getItemCount() == 0
then
weapondoor:close()
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
I am trying to set up a puzzle that seems to have been mentioned several times now. I have been typing script and reading this thread for 2 days and still can not get it to work right. There are 4 altars. There are 4 peices of chitin armor. Boots should be on altar 1, mask on 2, greaves and mail on 3 and 4. Everything I have tried opend the door with the placement of the first item without checking the final 3. Here's an example of the most recent one I tried.
Code: Select all
function armordoor()
-- iterate through all contained items on alcoves, checking for a matching name
local itemFound = false
for i in altar_1:containedItems() do
if i.name == "chitin_boots" then
for j in altar_2:containedItems() do
if j.name == "chitin_greaves" then
for k in altar_3:containedItems() do
if k.name == "chitin_mail" then
for l in altar_4:containedItems() do
if l.name == "chitin_mask" then
itemFound = true
end
end
end
end
end
end
end
end
if itemFound then
armordoor:open()
else
armordoor:close()
end
end
Re: How to check which item is in alcove?
You may need to check also whether the altars are empty. You might also consider doing each altar separately, and just connecting them all to a counter set to 4 which opens the door on 0
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
@betalove... this post earlier may help you.
viewtopic.php?f=14&t=3083&start=30#p35816
Basically... Create function to check if altar contains item:
in the same script create a function to check all altars
Then in theory you would link every altar to the function aretheitemsthere in the script for ANY event.. and set each altar to ACTIVATE ALWAYS... then every time an item is added to or removed from any of the altars the check is done to see if all altars contain their item.. if so, open the door. otherwise. close the door.
viewtopic.php?f=14&t=3083&start=30#p35816
Basically... Create function to check if altar contains item:
Code: Select all
-- This function returns true if the entity contains a given item.
-- It works for any entity that implements the containedItems() method.
function containsItem(entity, item)
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
Code: Select all
function aretheitemsthere()
if containsItem(altar_1, "chitin_boots") and containsItem(altar_2, "chitin_greaves") and containsItem(altar_3, "chitin_mail") and containsItem(altar_4, "chitin_mask")
then
armordoor:open()
else
armordoor: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
Re: How to check which item is in alcove?
This, this pure product of genius is what I've been trying the whole day! The other ways worked somewhat, but it was with this that I found the answer at last! Thank you, thank you! I kind of wish I'd found the solution myself, but this saved me a ton of work.Grimwold wrote:@betalove... this post earlier may help you.
viewtopic.php?f=14&t=3083&start=30#p35816
Basically... Create function to check if altar contains item:in the same script create a function to check all altarsCode: Select all
-- This function returns true if the entity contains a given item. -- It works for any entity that implements the containedItems() method. function containsItem(entity, item) 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
Then in theory you would link every altar to the function aretheitemsthere in the script for ANY event.. and set each altar to ACTIVATE ALWAYS... then every time an item is added to or removed from any of the altars the check is done to see if all altars contain their item.. if so, open the door. otherwise. close the door.Code: Select all
function aretheitemsthere() if containsItem(altar_1, "chitin_boots") and containsItem(altar_2, "chitin_greaves") and containsItem(altar_3, "chitin_mail") and containsItem(altar_4, "chitin_mask") then armordoor:open() else armordoor:close() end end
BASILEUS
Re: How to check which item is in alcove?
OK, this is what I have so far and no errors. Door does not open after all items are placed. The Altars are pointed to the function areitemsthere. Do I need to addConnector from script to door?
function armordoor()
-- iterate through all contained items on alcoves, checking for a matching name
for i in altar_1:containedItems() do
if i.name == "chitin_boots" then
return true
end
for j in altar_2:containedItems() do
if j.name == "chitin_greaves" then
return true
end
for k in altar_3:containedItems() do
if k.name == "chitin_mail" then
return true
end
for l in altar_4:containedItems() do
if l.name == "chitin_mask" then
return true
end
return false
end
end
end
function areitemsthere()
if containedItems(altar_1, "chitin_boots") and containedItems(altar_2, "chitin_greaves") and containedItems (altar_3, "chitin_mail") and containedItems(altar_4, "chitin_mask")
then
armordoor:open()
else
armordoor:close()
end
end
end
end
function armordoor()
-- iterate through all contained items on alcoves, checking for a matching name
for i in altar_1:containedItems() do
if i.name == "chitin_boots" then
return true
end
for j in altar_2:containedItems() do
if j.name == "chitin_greaves" then
return true
end
for k in altar_3:containedItems() do
if k.name == "chitin_mail" then
return true
end
for l in altar_4:containedItems() do
if l.name == "chitin_mask" then
return true
end
return false
end
end
end
function areitemsthere()
if containedItems(altar_1, "chitin_boots") and containedItems(altar_2, "chitin_greaves") and containedItems (altar_3, "chitin_mail") and containedItems(altar_4, "chitin_mask")
then
armordoor:open()
else
armordoor:close()
end
end
end
end
Re: How to check which item is in alcove?
Try this:
You have to kook every altar with lua entity
Code: Select all
function altarHasItem(altar,item_name)
for i in altar:containedItems() do
if i.name == item_name then
return true
end
end
return false
end
function areitemsthere()
if altarHasItem(altar_1, "chitin_boots") and altarHasItem(altar_2, "chitin_greaves") and altarHasItem (altar_3, "chitin_mail") and altarHasItem(altar_4, "chitin_mask") then
armordoor:open()
else
armordoor:close()
end
end