[Script]Path puzzle

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]Path puzzle

Post by GoldenShadowGS »

This script is a puzzle where the player needs to walk a certain path. There are invisible floor triggers at key points that update the script and turn on nearby lights to give feedback to the player that they are going the right way. At the end, I activate a door, a secret entity and give some XP. Then it is important to disable the script with pathsolved == 1 so all the lights stay lit when solved.

If you go the wrong way, the puzzle resets and you have to start over from the start.

All of the floor triggers should be numbered sequentially in the order they should be stepped on. The light near it should have the same number. All floor triggers just connect to the one function pathpuzzle()

Code: Select all

pathlighttable = {}
pathcount = 0
pathsolved = 0
function pathpuzzle()
	if pathsolved == 0 then
		local currentactivated = {}
		for i = 1,8 do
			currentactivated[i] = findEntity("pathtrigger"..i)
			if currentactivated[i].floortrigger:isActivated() then
				if i == pathcount + 1 then
					pathlighttable[i] = 1
					pathcount = pathcount + 1
					pathlights()
					if pathcount == 8 then
						pathsecret.secret:activate()
						dungeon_door_portcullis_23.door:open()
						for p = 1, 4, 1 do
							party.party:getChampion(p):gainExp(500)
						end
						hudPrint("500 XP")
						pathsolved = 1
					end
				elseif i == pathcount then
					--do nothing
				elseif i == 1 then 
					--start reset
					pathcount = 1
					for i = 1,8 do
						pathlighttable[i] = 0
					end
					pathlighttable[1] = 1
					pathlights()
				else
					-- total reset
					pathcount = 0
					for i = 1,8 do
						pathlighttable[i] = 0
					end
					pathlights()
				end
			end
		end
	end
end

function pathlights()
	for i = 1,8 do
		local pathlight = findEntity("pathlight"..i)
		if pathlighttable[i] == 1 then
			pathlight.light:enable()
			pathlight.particle:enable()
		else
			pathlight.light:disable()
			pathlight.particle:disable()
		end
	end
end
Last edited by GoldenShadowGS on Sat Nov 08, 2014 8:54 pm, edited 1 time in total.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [Script]Path puzzle

Post by MrChoke »

Very cool. I may try this out. Thanks!
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [Script]Path puzzle

Post by Drakkan »

seems cool, will try it !
thanks for sharing
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [Script]Path puzzle

Post by Lark »

This will be great! Thank you, GoldenShadowGS! I'll try it tonight... -Lark
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: [Script]Path puzzle

Post by Mysterious »

The script is awesome. It works in the editor but crashes when you are in the actual exported version, when you try to save a game bang!! sorry I just report for you.
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: [Script]Path puzzle

Post by Doridion »

Sticked in the superthread with description below : "The Word of God. Only in the footsteps of God will he proceed." :lol:
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script]Path puzzle

Post by GoldenShadowGS »

Mysterious wrote:The script is awesome. It works in the editor but crashes when you are in the actual exported version, when you try to save a game bang!! sorry I just report for you.
I will investigate if I can recreate this problem. I have only play tested it in editor.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: [Script]Path puzzle

Post by NutJob »

try "local currentactivated = {}"
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script]Path puzzle

Post by GoldenShadowGS »

NutJob wrote:try "local currentactivated = {}"
Updated the OP with this. Thanks!
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: [Script]Path puzzle

Post by Mysterious »

Thxs it's working awesome, this will be very handy indeed :)
Post Reply