[Script] Alcove puzzle in a specific order.

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

[Script] Alcove puzzle in a specific order.

Post by GoldenShadowGS »

I wrote a script which I think is too complicated for what it should be doing, but it works.
I have 5 figures and they have to be placed in the alcove in order. If the wrong item is placed, then you get an incorrect sound from everything you place afterwards until you take everything out and start over.

Connect the alcove to the script as On insert items, not remove item or you get extra error sounds.

Code: Select all

unlock1 = 0
unlock2 = 0
unlock3 = 0
unlock4 = 0

function figurepuzzle()
	local count = mine_alcove_1.surface:count()
	if count == 1 then
		if surfaceContains(mine_alcove_1.surface, "figure_crowern") then
			unlock1 = 1
			unlock2 = 0
			unlock3 = 0
			unlock4 = 0
			playSound("lock_chest")
		else
			resetlocks()
		end
	elseif count == 2 then
		if surfaceContains(mine_alcove_1.surface, "figure_crowern") and
		surfaceContains(mine_alcove_1.surface, "figure_snail") and
		unlock1 == 1 then
			unlock2 = 1
			playSound("lock_chest")
		else
			resetlocks()
		end
	elseif count == 3 then
		if surfaceContains(mine_alcove_1.surface, "figure_crowern") and
		surfaceContains(mine_alcove_1.surface, "figure_snail") and
		surfaceContains(mine_alcove_1.surface, "figure_ice_guardian") and
		unlock2 == 1 then
			unlock3 = 1
			playSound("lock_chest")
		else
			resetlocks()
		end
	elseif count == 4 then
		if surfaceContains(mine_alcove_1.surface, "figure_crowern") and
		surfaceContains(mine_alcove_1.surface, "figure_snail") and
		surfaceContains(mine_alcove_1.surface, "figure_ice_guardian") and
		surfaceContains(mine_alcove_1.surface, "figure_ogre") and
		unlock3 == 1 then
			unlock4 = 1
			playSound("lock_chest")
		else
			resetlocks()
		end
	elseif count == 5 then
		if surfaceContains(mine_alcove_1.surface, "figure_crowern") and
		surfaceContains(mine_alcove_1.surface, "figure_snail") and
		surfaceContains(mine_alcove_1.surface, "figure_ice_guardian") and
		surfaceContains(mine_alcove_1.surface, "figure_ogre") and
		surfaceContains(mine_alcove_1.surface, "figure_skeleton") and
		unlock4 == 1 then
			playSound("lock_chest")
			mine_door_camo_2.door:open()
		else
			resetlocks()
		end
	else
		resetlocks()
	end
end

function resetlocks()
	playSound("lock_incorrect")
	unlock1 = 0
	unlock2 = 0
	unlock3 = 0
	unlock4 = 0
end

function surfaceContains(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then 
			return true
		end
	end
end
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: [Script] Alcove puzzle in a specific order.

Post by Prozail »

just for fun, made a slightly easier version. Just set the itemlist in the top, and connect the alcove insert and remove to the two functions.

Code: Select all


wrongMove=false
function itemAlcoveInsert(sender, item)
	local solveOrder = { "figure_crowern","figure_snail","figure_ice_guardian","figure_ogre","figure_skeleton" }
	local items = sender.go.surface:count()
	
	if items>#solveOrder or wrongMove==true then 
		playSound("lock_incorrect") 
		wrongMove = true
		return
	end
	
	if solveOrder[items]==item.go.name then
		playSound("lock_chest")
	else
		wrongMove = true
		playSound("lock_incorrect")
		return
	end
	
	if items==#solveOrder then
		hudPrint("Solved It!")
	end
end

function itemAlcoveRemove(sender)
	playSound("lock_incorrect")
	if sender.go.surface:count()==0 then
		wrongMove=false
	end
end
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script] Alcove puzzle in a specific order.

Post by GoldenShadowGS »

I know basic logic with if, and, else. I know how to use for loops with tables and variables and that's about it. lol, I think I am making some pretty fancy stuff with that tool kit.
Post Reply