scripting alcove riddle

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

scripting alcove riddle

Post by bongobeat »

Hello,

how can i open a door with placing 3 items in 3 alcove?
I want to re create the scroll riddle with alcove, like in the level 4 or 5 (dont remenber) in LOG but I dont know how to do!

ex: in alcove (gha1) contain item "sr1" and gha2 contain "sr2" and gha3 contain "sr3"
tdmine:open
else
nothing

I have tried to modify the code but I dont know how to do!

I got this code:
only for 1 alcove and 1 item:
I have try with this one:

"sr1" is a item (scroll) renamed in the editor, placed somewhere and which contain a part of the riddle, but the door wont open, with "sr1", it seems that the script didnt consider the scroll id, and opens only if I let "scroll" instead of "sr1"
You can put any scroll to open the door, which is not what I want.

gha1 is the alcove name
tdmine is the door to open

can someone help me please?

Code: Select all

function check()
   local valid = {"sr1"}
	local counter = 0   

   for i in gha1: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 == 1 then
	tdmine:open()
   end
end
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: scripting alcove riddle

Post by Ryeath_Greystalk »

edit: oops, sppoke too soon.

Instead of using i.name try i.id
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: scripting alcove riddle

Post by bongobeat »

yeah, thanks a lot!
works with id! :D

do you have any idea how to add 2 more alcove and items in this script?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: scripting alcove riddle

Post by Ryeath_Greystalk »

I would need to take some time to work out a good way to do it using a table like you have in your code since I am still unclear on table usage. If someone has not offered up a soulution before I get home later today then I will work something up.

I have a smilar puzzle in my mod that uses colored gems. But it is just uses a bunch of if then statements, not a table.

Code: Select all

-- gem check

function gemCheck()

	if counter_24:getValue() == 0 then  -- built in flag to make a one time only solution
		
		local count =  false    -- determine if only one item in alcove
	
		local redcount = false
		if red_alcove:getItemCount() == 1 then
			redcount = true
		else
			redcount = false	
		end
		
		local greencount = false
		if green_alcove:getItemCount() == 1 then
			greencount = true
		else
			greencount = false
		end
		
		local bluecount = false
		if blue_alcove:getItemCount() == 1 then
			bluecount = true
		else
			bluecount = false
		end
		
		if redcount and greencount and bluecount then 
			count = true   --  if all three alcoves only contain one item
		else
			count = false
		end
		
		local color = false  -- determine if each alcove has the correct color gem
		
		local red = false	
		for i in red_alcove:containedItems() do
			if i.name == "red_gem" then
				red = true
			else
				red = false
			end
		end
		
		local green = false		
		for i in green_alcove:containedItems() do
			if i.name == "green_gem" then
				green = true
			else
				green = false
			end
		end
		
		local blue = false	
		for i in blue_alcove:containedItems() do
			if i.name == "blue_gem" then
				blue = true
			else
				blue = false
			end
		end
		
		if red and green and blue then
			color = true
		else
			color = false
		end

-- start evaulation stage
		
		if count and color then  -- each alcove contains the correct color gem and nothing else
			playSound("secret")
			party:getChampion(1):gainExp(500)
			party:getChampion(2):gainExp(500)
			party:getChampion(3):gainExp(500)
			party:getChampion(4):gainExp(500)
			local name1 = party:getChampion(1):getName()
			local name2 = party:getChampion(2):getName()
			local name3 = party:getChampion(3):getName()
			local name4 = party:getChampion(4):getName()
			hudPrint(name1.." gained 500 experience!")
			hudPrint(name2.." gained 500 experience!")
			hudPrint(name3.." gained 500 experience!")
			hudPrint(name4.." gained 500 experience!")
			prison_door_portcullis_14:open()
			counter_24:increment() -- set flag so players can not repeat for more experience
		end
	end
end

bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: scripting alcove riddle

Post by bongobeat »

thanks for the answer.
I found it in Masterquest from Komag!

Code: Select all

function hintSniff(entity, item)
  for i in entity:containedItems() do
    if i.id == item then
      return true
    end
  end
  return false -- if we get here the item was not found
end

function hintCheck()
  if hintSniff(gha1, "sr1") and
     hintSniff(gha2, "sr2") and
     hintSniff(gha3, "sr3") and
     hintSniff(gha4, "sr4")
  then
    hintsIn()
  else
    tdmine:close()
  end
end

function hintsIn()
  tdmine:open()
	playSound("discover_spell")
	hudPrint("Sequence complete! your party gain 800 experience points.")
	party:getChampion(1):gainExp(800)
	party:getChampion(2):gainExp(800)
	party:getChampion(3):gainExp(800)
	party:getChampion(4):gainExp(800)
	hudPrint("The mine! Here we are.")
	hudPrint("After so many stories we heard about it,")
	hudPrint("now we can check ourselves what is true.")
	
	end
works fine.
Komag I hope you wont be angry if I didnt change the name of the function! ;)
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: scripting alcove riddle

Post by Komag »

no problem :)
Finished Dungeons - complete mods to play
Post Reply