Document snippets buttons and allow disabling

This commit is contained in:
luk3yx 2021-03-17 12:49:56 +13:00
parent 43d9308c6b
commit 7ce4be4383
4 changed files with 22 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

2
settingtypes.txt Normal file
View File

@ -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