Grimfan wrote:Also, most of the spawns I'm talking about are initiated by the player when they step on a floortrigger or pull on a lever, so that means I am good to go (unless someone can point out another big pitfall).
You can also use the trigger's level attribute. eg. floor_trigger_1.level
Another option is to use the script object's level attribute.
Also, you can use an object's built in spawn function to place a new item in the same place as the object. eg. treasure_script:spawn("chest")
This has the benefit of being able to move the object around (even between levels), and the instructions will always spawn at the object's current location.
Grimfan wrote:What if I want to have them press the same button twice in a row or go back to a previous button and press it again?
This script supports buttons that require a set number of presses each, in order to trigger. The names of the buttons are set in B_table. Currently it expects three wall_buttons.
Code: Select all
--button lock with combination
B_table = { --=====================[Add all of your button id's here. Put the number of presses in the braces {#} ]
wall_button_1 = {3},
wall_button_2 = {1},
wall_button_3 = {2},
} --======================[]
for _,each in pairs(B_table) do each[2]=0 end --sets the recorded number of presses to zero.
previous_button = "" --stores the last button pressed
function buttonCapture(button)
if button.go.id ~= previous_button then --runs code only if it's a different button.
previous_button = button.go.id --sets the current button as the previous one.
B_table[button.go.id][2] = 1 --resets button values
B_table[button.go.id][3] = false
if B_table[button.go.id][2]>B_table[button.go.id][1] then --catches too many presses; clears all previously correct button values.
for _,each in pairs(B_table) do
each[2]=0 each[3]=false
end
end
end
if B_table[button.go.id][2]>B_table[button.go.id][1] then --catches too many presses; clears all previously correct button values.
for _,each in pairs(B_table) do each[2]=0 each[3]=false end
end
if B_table[button.go.id][1] == B_table[button.go.id][2] then --detects correct number of presses.
B_table[button.go.id][3] = true --sets the button entry to true
else B_table[button.go.id][3] = false --or false if incorrect
end
B_table[button.go.id][2] = B_table[button.go.id][2]+1 --increments the recorded number of button presses
local unlock = true
for _,b in pairs(B_table) do
unlock = unlock and b[3] --compares all buttons for true values; results in either unlock == true or false
end
if unlock then
--=====================================[success, put unlock logic here]
dungeon_door_iron_1.door:open()
--====================================================[]
end
end
*Note: This script only allows consecutive presses; it doesn't support alternating button presses.