Thank you in advance
Pressure Plate Script
Pressure Plate Script
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 
Thank you in advance
Thank you in advance
Re: Pressure Plate Script
Hi,
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.
Done. :)
Kind regards,
Joerg
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.
Done. :)
Kind regards,
Joerg
-
GoldenShadowGS
- Posts: 168
- Joined: Thu Oct 30, 2014 1:56 am
Re: Pressure Plate Script
This is how I did it in my level:
Code: Select all
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
endRe: Pressure Plate Script
Awesome thank you both very much 
Re: Pressure Plate Script
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?GoldenShadowGS wrote:This is how I did it in my level:
Code: Select all
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
-
GoldenShadowGS
- Posts: 168
- Joined: Thu Oct 30, 2014 1:56 am
Re: Pressure Plate Script
Code: Select all
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
endEDIT1:
Oh, ignore this. I just reread your post and you want them in a specific order. I have a solution coming up shortly.
EDIT2:
Code: Select all
--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
endRe: Pressure Plate Script
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
Sorry I'm still learning code and I like to understand it as much as possible. Thank you btw, you are very helpful
-
GoldenShadowGS
- Posts: 168
- Joined: Thu Oct 30, 2014 1:56 am
Re: Pressure Plate Script
This uses a table
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.
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.