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!
HI, I am very very new to scripting and I was wondering if someone could help me out. I need a script for a door that requires two pressure plates to be pressed down to open the door. If any of the two pressure plates become unpressed the door closes. I have a feeling this is an easy script but its a nightmare for me
you don't even need a script for this.
Use a counter and set its value to 2. Add a connector to it and set that to the door with onactivate ->"open" and another connector with ondeactivate -> "close".
On each pressure plate link a connection to the counter with onactivate -> decrement and another with ondeactivate -> increment.
function twoplates()
if beach_pressure_plate_1.floortrigger:isActivated() and
beach_pressure_plate_2.floortrigger:isActivated() then
beach_door_portcullis_2.door:open()
else
beach_door_portcullis_2.door:close()
end
end
function twoplates()
if beach_pressure_plate_1.floortrigger:isActivated() and
beach_pressure_plate_2.floortrigger:isActivated() then
beach_door_portcullis_2.door:open()
else
beach_door_portcullis_2.door:close()
end
end
Would this script also be usable with levers? Example I made a room with 4 levers they must all be switched on in a specific order. Would I just add other if statements?
function levers()
if lever_1.lever:isActivated() and
lever_2.lever:isActivated() and
lever_3.lever:isActivated() and
lever_4.lever:isActivated() then
--do something here
end
end
EDIT1:
Oh, ignore this. I just reread your post and you want them in a specific order. I have a solution coming up shortly.
--first solution 312314
--secondary solution 214231
tombcombination = {}
for i = 1,12 do
tombcombination[i] = 0
end
function tombcombo1()
if table.concat(tombcombination) == "100000000000" then
playSound("lock_chest")
tombcombination[2] = 1
elseif table.concat(tombcombination) == "111100000000" then
playSound("lock_chest")
tombcombination[5] = 1
elseif table.concat(tombcombination) == "111111100000" then
playSound("lock_chest")
tombcombination[8] = 1
elseif table.concat(tombcombination) == "111111111110" then
playSound("lock_chest")
tombcombination[12] = 1
else
tombcomboreset()
end
--2nd reward for unlocking
if table.concat(tombcombination) == "111111111111" then
teleporter_12.controller:activate()
end
end
function tombcombo2()
if table.concat(tombcombination) == "110000000000" then
playSound("lock_chest")
tombcombination[3] = 1
elseif table.concat(tombcombination) == "111111000000" then
playSound("lock_chest")
tombcombination[7] = 1
elseif table.concat(tombcombination) == "111111111000" then
playSound("lock_chest")
tombcombination[10] = 1
else
tombcomboreset()
end
end
function tombcombo3()
if table.concat(tombcombination) == "000000000000" then
playSound("lock_chest")
tombcombination[1] = 1
elseif table.concat(tombcombination) == "111000000000" then
playSound("lock_chest")
tombcombination[4] = 1
elseif table.concat(tombcombination) == "111111111100" then
playSound("lock_chest")
tombcombination[11] = 1
else
tombcomboreset()
end
end
function tombcombo4()
if table.concat(tombcombination) == "111110000000" then
playSound("lock_chest")
tombcombination[6] = 1
elseif table.concat(tombcombination) == "111111110000" then
playSound("lock_chest")
tombcombination[9] = 1
else
tombcomboreset()
end
--First reward for 6 digits.
if table.concat(tombcombination) == "111111000000" then
tomb_door_portcullis_2.door:open()
end
end
function tombcomboreset()
playSound("lock_incorrect")
for i = 1,12 do
tombcombination[i] = 0
end
end
Here is a copy-paste of a combination lock puzzle using wall buttons. You have to press the wall buttons in order or the lock resets. It is 12 digits long, I unlock one door at the sixth digit and the other door at the 12th. Each wall button links to a different function. For example, button 1 links to function tombcombo1().
wow that 1 looks complex haha.. I don't get how it works though. I guess the 12 digit numbers have me confused as well as what happens when you press a button?
Sorry I'm still learning code and I like to understand it as much as possible. Thank you btw, you are very helpful
table[1], table[2], table[3]..etc can all hold different values.
I am using a for loop to set table[1] through table[12] to 0(zero)
for i = 1,12 do
table = 0
end
What happens is the i in the brackets will cycle from 1 to 12 and set that table value to 0.
Then during the button functions, it does a lua concatenate function on the table that converts all of the values in the table to a string. Then I compare that string to the one I typed in the function.
When all of the values of table 1 through 12 are zero, the output of table.table:concat() will be 000000000000 when table[1] = 1 and the rest are zero the output is 100000000000.
From there, you can do the normal logic and comparing operators to set up the lock.
The important part is when you click the correct button, The code looks to see if the concatenate table matches any. If it does, it sets the next digit from 0 to 1. If not, it resets them all to zero.