From 7ce4be4383892e18ae8f8b59f6ef04e008715da9 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 17 Mar 2021 12:49:56 +1300 Subject: [PATCH] Document snippets buttons and allow disabling --- README.md | 16 +++++++++++++++- init.lua | 5 ++++- nodes.lua | 2 +- settingtypes.txt | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 settingtypes.txt diff --git a/README.md b/README.md index 1ade679..10bbb30 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,21 @@ A way for admins to run and save lua snippets. ## Chatcommands - - `/snippets`: Open the snippets console. + - `/snippets`: Open the snippets console. This allows you to edit and run Lua + snippets. + +## Nodes + +This mod registers a snippets button node that runs a snippet when pressed. The +snippet will be called with the player name as its first argument. For example, +you can do `local name = ...` inside a snippet to get the name of the player +that pressed the button. + +Buttons don't appear in the creative inventory, if you want them to you will +need to run `/giveme snippets:button`. + +If you don't want the buttons at all, you can add +`snippets.enable_buttons = false` to your minetest.conf. ## API diff --git a/init.lua b/init.lua index 582038c..3db78d8 100644 --- a/init.lua +++ b/init.lua @@ -20,4 +20,7 @@ dofile(modpath .. '/forms.lua') dofile(modpath .. '/console.lua') -- Load "snippet buttons" -dofile(modpath .. '/nodes.lua') +local enable_buttons = minetest.settings:get_bool('snippets.enable_buttons') +if enable_buttons or enable_buttons == nil then + dofile(modpath .. '/nodes.lua') +end diff --git a/nodes.lua b/nodes.lua index 01f3856..65750bb 100644 --- a/nodes.lua +++ b/nodes.lua @@ -6,7 +6,7 @@ minetest.register_node('snippets:button', { description = 'Snippets button', tiles = {'default_steel_block.png', 'default_steel_block.png', 'default_steel_block.png^snippets_button.png'}, - groups = {cracky = 2}, + groups = {cracky = 2, not_in_creative_inventory = 1}, on_construct = function(pos) local meta = minetest.get_meta(pos) diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..3eeeda9 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,2 @@ +# Enables snippets buttons which allow all players to run a specified snippet. +snippets.enable_buttons (Register snippets button nodes) bool true