Page 1 of 1

[Script]Path puzzle

Posted: Fri Nov 07, 2014 5:20 pm
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

Re: [Script]Path puzzle

Posted: Fri Nov 07, 2014 5:42 pm
by MrChoke
Very cool. I may try this out. Thanks!

Re: [Script]Path puzzle

Posted: Fri Nov 07, 2014 6:17 pm
by Drakkan
seems cool, will try it !
thanks for sharing

Re: [Script]Path puzzle

Posted: Fri Nov 07, 2014 6:48 pm
by Lark
This will be great! Thank you, GoldenShadowGS! I'll try it tonight... -Lark

Re: [Script]Path puzzle

Posted: Sat Nov 08, 2014 5:16 pm
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.

Re: [Script]Path puzzle

Posted: Sat Nov 08, 2014 6:34 pm
by Doridion
Sticked in the superthread with description below : "The Word of God. Only in the footsteps of God will he proceed." :lol:

Re: [Script]Path puzzle

Posted: Sat Nov 08, 2014 8:45 pm
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.

Re: [Script]Path puzzle

Posted: Sat Nov 08, 2014 8:50 pm
by NutJob
try "local currentactivated = {}"

Re: [Script]Path puzzle

Posted: Sat Nov 08, 2014 8:55 pm
by GoldenShadowGS
NutJob wrote:try "local currentactivated = {}"
Updated the OP with this. Thanks!

Re: [Script]Path puzzle

Posted: Sat Nov 08, 2014 10:51 pm
by Mysterious
Thxs it's working awesome, this will be very handy indeed :)