Page 5 of 8
Re: How to check which item is in alcove?
Posted: Fri Oct 05, 2012 4:37 pm
by petri
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 ...
Re: How to check which item is in alcove?
Posted: Fri Oct 05, 2012 6:02 pm
by Komag
YES, it's working!
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
now to fill up that big weapon list (or at least the possible weapons the party could have by that point)
Re: How to check which item is in alcove?
Posted: Sat Oct 06, 2012 7:32 am
by uggardian
Could somebody help:
How to make a trap action when alcove is completely empty?
Re: How to check which item is in alcove?
Posted: Sat Oct 06, 2012 12:30 pm
by Komag
It's already there in the first part of my script:
Code: Select all
if weaponalcove:getItemCount() == 0
then
weapondoor:close()
You can make anything you want happen at that point
Re: How to check which item is in alcove?
Posted: Wed Oct 10, 2012 5:46 am
by Betalove
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?
Posted: Wed Oct 10, 2012 1:08 pm
by Komag
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
Re: How to check which item is in alcove?
Posted: Wed Oct 10, 2012 4:34 pm
by Grimwold
@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:
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
in the same script create a function to check all altars
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
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.
Re: How to check which item is in alcove?
Posted: Wed Oct 10, 2012 6:19 pm
by Kuningas
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:
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
in the same script create a function to check all altars
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
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.
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.
Re: How to check which item is in alcove?
Posted: Fri Oct 12, 2012 3:31 am
by Betalove
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
Re: How to check which item is in alcove?
Posted: Fri Oct 12, 2012 8:33 am
by Filipsan
Try this:
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
You have to kook every altar with lua entity