Script: Make Multiple Buttons/Levers

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!
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Script: Make Multiple Buttons/Levers

Post by Duncan1246 »

Isaac wrote:
Duncan1246 wrote:I needs to use runes-buttons (same as "wall_button" but with a rune instead of the LOG1 logo, named "wall_button_fire", ..., etc.
The best way to have the runes, is to change the texture on the material... but that's not the easiest way. The second best , is to edit the model in blender an add the rune as a plane, one unit in front of the button face. It will cover the logo, rather than replace it.

To alter the textures, you could use Blender to bake the changes to the material(s); or you could use Photoshop/Gimp along with the normal map plug-in; to fake the baked results.

Thanks Isaac. It's your slider puzzle in ORR2 which give me the idea to use runes in a slightly different way, I make an attempt with Blender, but I failed: this tool needs some time to handle... So I have made the runes buttons with your first proposal: changing textures and materials of the center of the button, leaving the metal around unchanged. It works, even if it's certainly possible to make it better.
But now the problem is: how use these buttons with Lark's multilever script, because the script call ONE button model for all buttons spawned. I haven't tried to change the script for now, but my feeling is that it's not so easy...
Duncan
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Script: Make Multiple Buttons/Levers

Post by Isaac »

Duncan1246 wrote:But now the problem is: how use these buttons with Lark's multilever script, because the script call ONE button model for all buttons spawned. I haven't tried to change the script for now, but my feeling is that it's not so easy...
Duncan
I could not find a way to override the material called by a model ~per node. However, I did manage to override the button face, once I'd reassigned it to a new material in the GMT. This seems to work pretty well; (specifically for a 3x3 grid of the runes) .
Image
https://www.dropbox.com/s/k3ez33cqrc5pt ... d.zip?dl=0

To use this method, you must add the included button model, the three clay tile textures, and the runes.lua script to your mod; runes.lua needs to be imported to init.lua
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Script: Make Multiple Buttons/Levers

Post by Eleven Warrior »

Ok Issac I downloaded the test dungeon but imam not sure how to use it yeah. Is it possible for you to make a better example on how to use your test dungeon with a puzzle, small, medium, high for testing yeah? Your demo just has the code and nothing connected to script you made.

Thxs for any help mate :)
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Script: Make Multiple Buttons/Levers

Post by Isaac »

Eleven Warrior wrote:Ok Issac I downloaded the test dungeon but imam not sure how to use it yeah. Is it possible for you to make a better example on how to use your test dungeon with a puzzle, small, medium, high for testing yeah? Your demo just has the code and nothing connected to script you made.

Thxs for any help mate :)
It's Larks button script... I just added a tweak that changes the buttons to have rune faces. Lark explains the usage in the OP.

Basically the script makes buttons that call the buttonPress() function. To have the buttons trigger anything, requires that you change the logic in the buttonPress() function.

I do have a post on page 2, that shows an easy change that allows for a list of actions: viewtopic.php?f=22&t=8129&start=10#p89943

The example I give, shows the calling of three separate scripts, but of course it could also call one script, with many functions in it; or simply add the instructions into the list.
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Script: Make Multiple Buttons/Levers

Post by Duncan1246 »

Isaac wrote:
Duncan1246 wrote:But now the problem is: how use these buttons with Lark's multilever script, because the script call ONE button model for all buttons spawned. I haven't tried to change the script for now, but my feeling is that it's not so easy...
Duncan
I could not find a way to override the material called by a model ~per node. However, I did manage to override the button face, once I'd reassigned it to a new material in the GMT. This seems to work pretty well; (specifically for a 3x3 grid of the runes) .
To use this method, you must add the included button model, the three clay tile textures, and the runes.lua script to your mod; runes.lua needs to be imported to init.lua
Thanks a lot, Isaac, the script works perfectly! :D
I have had some trouble with the order, because I don't use the order of the runes cast and the order of definerunes() is inverse of reading order, so first attempt it was a real mess... but all is right now
Duncan
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Script: Make Multiple Buttons/Levers

Post by THOM »

Have a problem in using this script.

Everything is fine - my buttons are created, they work and send their impulses after beeing pressed. At the end they trigger a function which starts like

Code: Select all

function mineSequence(sender)
       if sender.id == "mine_buttongrid_button_41" then
         
("mine_buttongrid_button_41" is the button created with Larks script - ID is veryfied)

But I always get the error attempt to index local 'sender' (a number value)

I know that this function works if I trigger it with a normal button - so it seems "sender" in this case is lost somehow.

Does anyone have an idea what I have to do?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Script: Make Multiple Buttons/Levers

Post by Isaac »

THOM wrote:...But I always get the error attempt to index local 'sender' (a number value)
if sender is a number, then it won't have a sender.id field.

This is the buttonPress() function...

Code: Select all

function buttonPress(my)
  local pushed = tonumber(string.sub(my.go.id, string.len(my.go.id) - 1))
  hudPrint("button pressed:  "..pushed)
  --Replace the above with your own logic
  end
How is your copy changed from the original?
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Script: Make Multiple Buttons/Levers

Post by THOM »

The thing is, I am trying to mix this Multiple Buttons/Levers Script with that Button Sequence script: viewtopic.php?f=14&t=3026&hilit=buttons&start=10#p37586

So I have

Code: Select all

    function buttonPress(my)
      local pushed = tonumber(string.sub(my.go.id, string.len(my.go.id) - 1))
    ---------------------------------------------------------------------------------   
        local buttonAction = {  
					[14] = function() script_MineGridSequence.script.mineSequence(pushed) end,
                      			[35] = function() script_MineGridSequence.script.mineSequence(pushed) end,
                      			[41] = function() script_MineGridSequence.script.mineSequence(pushed) end,
                      			[42] = function() script_MineGridSequence.script.mineSequence(pushed) end,
and the mentioned script_MineGridSequence.script.mineSequence starts with

Code: Select all

function mineSequence(my)
       if sender.id == "mine_buttongrid_button_41" and counter_mineGrid.counter:getValue() == 5 then
          counter_mineGrid.counter:setValue(4)
       elseif sender.id == "mine_buttongrid_button_41" and counter_mineGrid.counter:getValue() == 4 then
          counter_mineGrid.counter:setValue(5)
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Script: Make Multiple Buttons/Levers

Post by Isaac »

That seems kind of complicated. So you just want a keypad for a combination lock?

Perhaps try this instead:

Code: Select all

--script id is "combination_lock"
combination = {11,11,23,32,12,22}  
next = 0

function buttonPress(button)
next = next + 1
	if combination[next] ~= button then
	  next = 0
	end
	if next == #combination then
		--do something
		playSound("master_gate_open")
		--do something
		next = 0 
	end
	--print(next, button)  --uncomment to see the button ids
end

To set the combination, uncomment the print statement and press the buttons you want. Use those numbers in the combination table ~first to last.

Call the function from the button script.

Code: Select all

    function buttonPress(my)
      local pushed = tonumber(string.sub(my.go.id, string.len(my.go.id) - 1))
      	combination_lock.script.buttonPress(pushed)
      end
Project: https://www.dropbox.com/s/2f6xn0gnao2cu ... k.zip?dl=0
Video: https://www.dropbox.com/s/l2w7fx9uwzo7o ... s.avi?dl=0
SpoilerShow
The demo uses a more complicated version that supports multiple combination locks from a central script.
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Script: Make Multiple Buttons/Levers

Post by THOM »

And once again: A big thank you, Isaac. Works perfect!
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Post Reply