[Script]Lever toggle puzzle using Onclick

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!
Post Reply
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

[Script]Lever toggle puzzle using Onclick

Post by GoldenShadowGS »

If you connect a lever to another lever, you can not control which one the player actually clicked on without some extra work to enable and disable the other connections with floor triggers or getfacing.
Here is an easy way to create such a puzzle:

I put a floor trigger in front of each lever to guarantee the setup function gets run before any levers can be thrown, but you have to limit this to a run once or it will add lots of extra connections.

The actual levers are not connected to anything in the editor. They get the Onclick hook from the setup function.

Code: Select all

for i = 1,4 do
local ruinlever = findEntity("tomb_wall_lever_"..i)
ruinlever.clickable:addConnector("onClick", "script_entity_20", "ruinlever"..i)
end

function ruinlever1()
	tomb_wall_lever_2.lever:toggle()
	tomb_pit_trapdoor_1.pit:toggle()
	tomb_pit_trapdoor_2.pit:toggle()
end

function ruinlever2()
	tomb_wall_lever_1.lever:toggle()
	tomb_wall_lever_3.lever:toggle()
	tomb_pit_trapdoor_1.pit:toggle()
	tomb_pit_trapdoor_2.pit:toggle()
	tomb_pit_trapdoor_3.pit:toggle()
end

function ruinlever3()
	tomb_wall_lever_2.lever:toggle()
	tomb_wall_lever_4.lever:toggle()
	tomb_pit_trapdoor_2.pit:toggle()
	tomb_pit_trapdoor_3.pit:toggle()
	tomb_pit_trapdoor_4.pit:toggle()
end

function ruinlever4()
	tomb_wall_lever_3.lever:toggle()
	tomb_pit_trapdoor_3.pit:toggle()
	tomb_pit_trapdoor_4.pit:toggle()
end

EDIT: I just discovered that you can put commands outside of functions and they will automatically run.
Post Reply