[Script]Path puzzle
Posted: Fri Nov 07, 2014 5:20 pm
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()
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