mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-08-20 05:24:20 +02:00
Add //multi
command.
TODO: Documentation. Perhaps it should be it's own mod?
This commit is contained in:
parent
bbde06c72e
commit
ac05627d53
@ -12,6 +12,7 @@ If you can dream of it, it probably belongs here!
|
|||||||
- `//hollowellipsoid <rx> <ry> <rz> <node_name>`
|
- `//hollowellipsoid <rx> <ry> <rz> <node_name>`
|
||||||
- `//torus <major_radius> <minor_radius> <node_name>`
|
- `//torus <major_radius> <minor_radius> <node_name>`
|
||||||
- `//hollowtorus <major_radius> <minor_radius> <node_name>`
|
- `//hollowtorus <major_radius> <minor_radius> <node_name>`
|
||||||
|
- `//multi <command_a> <command_b> .....`
|
||||||
|
|
||||||
### `//floodfill [<replace_node> [<radius>]]`
|
### `//floodfill [<replace_node> [<radius>]]`
|
||||||
Floods all connected nodes of the same type starting at _pos1_ with <replace_node> (which defaults to `water_source`), in a sphere with a radius of <radius> (which defaults to 50).
|
Floods all connected nodes of the same type starting at _pos1_ with <replace_node> (which defaults to `water_source`), in a sphere with a radius of <radius> (which defaults to 50).
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
--- Overlap command. Places a specified node on top of
|
--- Overlap command. Places a specified node on top of each column.
|
||||||
-- @module worldeditadditions.overlay
|
-- @module worldeditadditions.overlay
|
||||||
|
|
||||||
function worldedit.overlay(pos1, pos2, target_node)
|
function worldedit.overlay(pos1, pos2, target_node)
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
worldeditadditions
|
worldeditadditions
|
||||||
worldedit_commands
|
worldedit_commands
|
||||||
|
worldedit
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
-- @license Mozilla Public License, 2.0
|
-- @license Mozilla Public License, 2.0
|
||||||
-- @author Starbeamrainbowlabs
|
-- @author Starbeamrainbowlabs
|
||||||
|
|
||||||
|
dofile(minetest.get_modpath("worldeditadditions_commands").."/multi.lua")
|
||||||
|
|
||||||
local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
|
local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
|
||||||
|
|
||||||
|
|
||||||
|
62
worldeditadditions_commands/multi.lua
Normal file
62
worldeditadditions_commands/multi.lua
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
--- Executes multiple worldedit commands in sequence.
|
||||||
|
-- @module worldeditadditions.multi
|
||||||
|
|
||||||
|
-- explode(seperator, string)
|
||||||
|
-- From http://lua-users.org/wiki/SplitJoin
|
||||||
|
function explode(delim, str)
|
||||||
|
local ll, is_done
|
||||||
|
local delim_length = string.len(delim)
|
||||||
|
ll = 0
|
||||||
|
is_done = false
|
||||||
|
|
||||||
|
return function()
|
||||||
|
if is_done then return end
|
||||||
|
|
||||||
|
local result = nil
|
||||||
|
local loc = string.find(str, delim, ll, true) -- find the next d in the string
|
||||||
|
if loc ~= nil then -- if "not not" found then..
|
||||||
|
result = string.sub(str, ll, loc - 1) -- Save it in our array.
|
||||||
|
ll = loc + delim_length -- save just after where we found it for searching next time.
|
||||||
|
else
|
||||||
|
result = string.sub(str, ll) -- Save what's left in our array.
|
||||||
|
is_done = true
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- From http://lua-users.org/wiki/StringTrim
|
||||||
|
function trim(s)
|
||||||
|
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/multi", {
|
||||||
|
params = "//<command_a> <args> //<command_b> <args> .....",
|
||||||
|
description = "Executes multiple chat commands in sequence.",
|
||||||
|
privs = { worldedit = true },
|
||||||
|
func = function(name, params_text)
|
||||||
|
-- Things start at 1, not 0 in Lua :-(
|
||||||
|
local i = 0
|
||||||
|
for command in explode(" /", string.sub(params_text, 2)) do
|
||||||
|
local found, _, command_name, args = command:find("^([^%s]+)%s(.+)$")
|
||||||
|
if not found then command_name = command end
|
||||||
|
command_name = trim(command_name)
|
||||||
|
|
||||||
|
worldedit.player_notify(name, "Executing #"..i..": "..command.." ("..command_name..")")
|
||||||
|
|
||||||
|
local cmd = minetest.chatcommands[command_name]
|
||||||
|
if not cmd then
|
||||||
|
return false, "Error: "..command_name.." isn't a valid command."
|
||||||
|
end
|
||||||
|
if not minetest.check_player_privs(name, cmd.privs) then
|
||||||
|
return false, "Your privileges are insufficient."
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("action", name.." runs "..command)
|
||||||
|
cmd.func(name, args)
|
||||||
|
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user