Page 1 of 2
Scripting Help: Item Placement on Two Alcoves
Posted: Tue Oct 16, 2012 1:50 am
by Adamconcept
Hello potential helpers
I've been working on this problem all day, and the resources and Youtube tutorials Komag put together have been an incredible help, but it's time to admit my shortcomings at programming and organizing my thoughts appropriately for it.
I have a door with an alcove on each side of it, and the goal is to get the player to place a skull in each alcove and activate the door. This is the
basic code I've managed to put together:
Code: Select all
function puzzleR101()
local itemName = "skull"
local alcoveID = R1Alcove1
for i in alcoveID:containedItems() do
if i.name == itemName then
playSound("lever")
else
end
end
end
The code is repeated on the other alcove, using different names for the function and alcoveID. I tried tying it together with a counter (placed just beneath the "playSound" command), but the problem comes when you use an object that isn't a skull, or remove a skull; it screws up the counter. I've tried this, along with a combination of other scripts which lie far beyond my comprehension, and mucking around with other tools built into Grimrock with no success. If someone can tell me what to look for, or even help me put the code together, that would be amazing. I basically just want a door to open when there's only a skull in each alcove, and to stay shut otherwise. That includes closing itself if a skull is removed.
Thank you again. If this is too complicated to pull off with the resources available, so be it.
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Tue Oct 16, 2012 2:15 am
by Belblindd
As far as I'm concerned make 1 script for every alcove connect them and connect both alcoves to the counter.
Code: Select all
function skullPuzzle()
for i in dungeon_alcove_4:containedItems() do -- Name of the alcove
if i.name == "skull" then -- Item category
counter_2:decrement() -- Counter name
playSound("lever")
break
end
end
end
Then connect the counter to the door, you need to try if you like to close the door when a skull is removed or not, as well as connect the alcove to the counter with "Event: deactivate" and "Action: increment".
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Tue Oct 16, 2012 3:17 am
by Adamconcept
Almost there; I don't know if I'm missing something. The door won't open unless a skull is in each alcove; that works perfectly fine. As well, if a skull is removed, it closes. That's fine as well. Here's the problem now:
If a skull is in the alcove and another item is placed (say, a torch), then the counter goes up again because it sees a skull during that event. The player can then remove the skull and the door will stay open. :S
I might leave it for now and move on to making the next floor, and hope a solution pops up in the knowledgebases sometime. Again, thank you for the help; it works much better than it did before. It's probably not something most players would pick up on, but two skulls can add a lot on one floor if the player's minotaur has that ability.
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Tue Oct 16, 2012 8:03 am
by Filipsan
Try this witout counter - just link both altars to the areItemsThere() function.. (not tested)
Code: Select all
altar_1_had_skull = false
altar_2_had_skull = false
function altarHasItem(altar,item_name, had_skull)
for i in altar:containedItems() do
if i.name == item_name then
if(!had_skull) then
playSound("lever")
end
return true
end
end
return false
end
function areItemsThere()
local altar_1_ok = altarHasItem(altar_1, "skull", altar_1_had_skull)
local altar_2_ok = altarHasItem(altar_2, "skull", altar_2_had_skull)
if(altar_1_ok) then
altar_1_had_skull = true
end
if(altar_2_ok) then
altar_2_had_skull = true
end
if altar_1_ok and altar_2_ok then
altardoor:open()
else
altardoor:close()
end
end
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Thu Oct 18, 2012 11:07 pm
by SpiderFighter
Belblindd wrote:As far as I'm concerned make 1 script for every alcove connect them and connect both alcoves to the counter.
Code: Select all
function skullPuzzle()
for i in dungeon_alcove_4:containedItems() do -- Name of the alcove
if i.name == "skull" then -- Item category
counter_2:decrement() -- Counter name
playSound("lever")
break
end
end
end
Then connect the counter to the door, you need to try if you like to close the door when a skull is removed or not, as well as connect the alcove to the counter with "Event: deactivate" and "Action: increment".
Found this while stuck on the exact same thing (great minds). My problem is that I'm just learning how to call functions, but don't know how to increment the counter while the item is removed from the alcove (for example, like you can if you remove a torch from the holder). In other words, a player only needs one item instead of two; they can just place it on the alcove, remove it, and replace it and the counter will decrease and open the door. Can someone please help?
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Fri Oct 19, 2012 2:12 am
by Komag
IIRC, you can set the alcove to "activate always", then make your "activate" connection to decrement, but also a "deactivate" connection to increment, so if they put an item in and out it will have no net effect
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Fri Oct 19, 2012 12:13 pm
by SpiderFighter
Komag wrote:IIRC, you can set the alcove to "activate always", then make your "activate" connection to decrement, but also a "deactivate" connection to increment, so if they put an item in and out it will have no net effect
That's more what I mean...I don't know how to script "if [item name] is not equal to [item ID].
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Sat Oct 20, 2012 10:53 am
by SpiderFighter
Got all excited that help was here...and then...spam.
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Sat Oct 20, 2012 11:23 am
by Komag
spam cleaned up
Re: Scripting Help: Item Placement on Two Alcoves
Posted: Sat Oct 20, 2012 11:48 am
by Decayer
Code: Select all
function checkItems(caller)
for i in caller:containedItems() do
if i.name == "skull" then
counter_1:decrement()
return
end
end
counter_1:increment()
end
Add a counter and change its ID to counter_1 (or change counter_1 in the code to its ID). Set it to have an initial value of 2 and to toggle your door when it receives "any" event. Link your alcoves to the script entity with an "any" event and make sure that 'Activate Always' is unchecked.