Hi there,
I've been working on a custom dungeon (Mostly for my own amusement) and have just started tackling scripting, so far everything has been working fine, save when i tried to get this to work:
--Opening and closing doors
function open()
for a in alcove:containedItems() do
if a.name == "golden_chalice" and
door1:isClosed() then
door1:open()
end
end
end
Now this is slightly misleading, the code as it is works fine, when the player places the golden_chalice in the alcove, the door opens. The issue comes when I want the door to close if the chalice is removed, I.E to stop the character taking it with them. I've gotten very close, able to set the alcove with a connector that shuts the door if it is deactivated. Unfortunately this carried the issue of allowing the player to simply place any other item on the alcove and remove the golden_chalice, leaving the gate open and allowing them to walk through.
I tried your suggestion and found that, instead of the door closing when the chalice is removed, rather it closes only when the chalice is placed on the alcove when the door is open.
In reality what will be needed I feel is a way of checking the contained items for the chalice and have it return a "false" prompt of some description, so that it checks BOTH for a positive and negative result opening and closing the door respectively. I just don't have the talent with LUA to achieve this.
function openGoldenChaliceDoor()
if my_door:isClosed() then
for a in my_alcove:containedItems() do
if a.name == "long_sword" and my_alcove:getItemCount() == 1 then
my_door:open()
end
end
else
my_door:close()
end
end
Edit: use "any" on your alcove for calling script.
We're nearly there, that works perfectly so long as we don't introduce another item, for instance if I place a torch on the alcove after the chalice, then take the chalice off, the door remains open.
EDIT
Curiously after thinking about it, I discovered an odd but effective workaround. Simply by setting the alcove to always active, then adding another connector to the scripting entity. Finally I set one connector to 'activate' and one to 'deactivate', this coupled with the alcove ticking as if it were activated every time something is added and deactivated every time something is removed, it correctly located the foreign body of the torch and closes the gate.
LGreymark wrote:We're nearly there, that works perfectly so long as we don't introduce another item, for instance if I place a torch on the alcove after the chalice, then take the chalice off, the door remains open.
To restrict the alcove to only accept the Chalice is easy, (if that is what you want), by adding to the object definition:
onInsertItem = function(alcove,item)
return item.name == "golden_chalice"
end
______________
*Clone the alcove, and use the clone; or that will affect all alcoves.
If you want other items allowed; (but only one at a time), then add this instead:
onInsertItem = function(alcove,item)
return alcove:getItemCount() == 0
end
______________
For anything else, you just add to or replace the onInsertItem hook's function with your custom code, and it will run when the
player tries to add items to the alcove.
Preventing drop into is not the best way, if there is an "general alcove" imho.
You no need to add activate /deactivate, just use one "any". Alcove must be set to always active. Check this Example. If you add right item, door --> open, if there is more items in alcove, or wrong item, door --> close.
Thanks for the help, but, as this is working fine and I actually understand why and how it works the way it does I'll keep using it, no sense in delving into things over my head.