Hi everyone - you'll be pleased to know I'm a total newbie to modding and Lua, so expect a few daft questions....although I have done my best to scour the forums for the answers beforehand. Have to say, I've really enjoyed reading the forum posts and have found this resource really useful. I'm still lifting chunks of code, but the undrlying logic is starting to become clear...
Anyway, I have a puzzle problem I can't work out:
1) I'm setting up a puzzle whereby stepping on a series of pressure plates closes pits in an area behind a grating, (although stepping on the wrong ones opens them all again).
2) When the final 'correct' pressure plate is used, a gate opens allowing access to that area; however the pits do not all have to be closed in order for the player to get to the centre - they're really just a visual cue to show them from behind the grating how far they are through the puzzle.
The problem I have is that I was trying to set up connectors from pits to a script entity; I started by imagining I could steal the 'combination puzzle' script and have a script entity looking at the state of 8 pits, only activting the door when they were all closed. But then I realised that pits don't have connectors in the inspector, and I came unstuck when trying to code this.
I also thought about using a counter linked to the plates to decrement the counter - but then the player could just step on the plate 8 times. I see the inspector features an option to 'activate once', but ideally I want the pressure plates to reset as well, (and start decrementing again) if the player steps on the WRONG pressure plate, (with the result of opening all pits and sending them back to square 1).
I'm sure there's a very simple explaination but I can't see the wood for the trees at present!
More pit woes
Re: More pit woes
You can do it in many ways. One of them is to connect each plate to script entity with following script.
I wrote it without testing, so there may be a typo etc, but the idea is that on each step on the plate it will check all pits defined in list in script and if all of them are closed, it will open door. Script does not care about pit reset etc.
I'm not sure about that if pitList:isClosed() then
maybe you have to go through all pits in level and if pit.name is in list you can c=c+1 etc...
[/color]
I wrote it without testing, so there may be a typo etc, but the idea is that on each step on the plate it will check all pits defined in list in script and if all of them are closed, it will open door. Script does not care about pit reset etc.
Code: Select all
function OpenPitDoor
pitList = {"pit_1, "pit_2"} -- list of pits in puzzle, write their names
local c = 0 -- variable counting closed pits
for i = 0, #pitList do
if pitList[i]:isClosed() then -- it returns true if yes, check lua how to do if it's true
c = c + 1 --if its closed then increase counter
else
break
end
end
if c == #pitList then -- if all are closed, c must be equal to number of pits in list of pits
pitDoor:open()
end
endmaybe you have to go through all pits in level and if pit.name is in list you can c=c+1 etc...
[/color]
I'm the Gate I'm the Key.
Dawn of Lore
Dawn of Lore
Re: More pit woes
Thanks! I'll give that a go!
Re: More pit woes
To slightly fix that code:
- global variables like the pitList table should be declared outside of functions, always only local variables inside functions!
- missing () after the function name.
- Lua tables start from 1, so it's for i = 1, not for i = 0.
- The table stores the pit's id, but you need to retrieve the actual entity befor checking if it's closed, so findEntity(pitList) instead of pitList.
Enjoy!
Code: Select all
pitList = {"pit_1, "pit_2"} -- list of pits in puzzle, write their names
function OpenPitDoor()
local c = 0 -- variable counting closed pits
for i = 1, #pitList do
if findEntity(pitList[i]):isClosed() then -- it returns true if yes, check lua how to do if it's true
c = c + 1 --if its closed then increase counter
else
break
end
end
if c == #pitList then -- if all are closed, c must be equal to number of pits in list of pits
pitDoor:open()
end
end- missing () after the function name.
- Lua tables start from 1, so it's for i = 1, not for i = 0.
- The table stores the pit's id, but you need to retrieve the actual entity befor checking if it's closed, so findEntity(pitList) instead of pitList.
Enjoy!
Re: More pit woes
Thanks for fixing code m8, I wrote it from my tablet and it was terrible exeriance haha - on the other hand, it was some kind of hint, to motivate him to investigate etc
I'm the Gate I'm the Key.
Dawn of Lore
Dawn of Lore
Re: More pit woes
Great guys - I really appreciate the help! 