Skip to content

Commit 174416b

Browse files
author
Cy
committedJun 30, 2014
Randomized set
Can /set node node2 node3 and it will randomly choose between those three.
1 parent 2c4a791 commit 174416b

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
 

‎worldedit/manipulations.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ worldedit.volume = function(pos1, pos2)
2424
end
2525

2626
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
27-
worldedit.set = function(pos1, pos2, nodename)
27+
worldedit.set = function(pos1, pos2, nodenames)
28+
if type(nodenames) == 'string' then
29+
nodenames = {nodenames}
30+
end
31+
2832
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
2933

3034
--set up voxel manipulator
@@ -40,9 +44,12 @@ worldedit.set = function(pos1, pos2, nodename)
4044
end
4145

4246
--fill selected area with node
43-
local node_id = minetest.get_content_id(nodename)
47+
local node_ids = {}
48+
for i,v in ipairs(nodenames) do
49+
node_ids[i] = minetest.get_content_id(nodenames[i])
50+
end
4451
for i in area:iterp(pos1, pos2) do
45-
nodes[i] = node_id
52+
nodes[i] = node_ids[math.random(#node_ids)]
4653
end
4754

4855
--update map nodes

‎worldedit_commands/init.lua

+13-9
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,26 @@ minetest.register_chatcommand("/volume", {
278278
end,
279279
})
280280

281-
local check_set = function(name, param)
282-
local node = get_node(name, param)
283-
if not node then return nil end
284-
return check_region(name, param)
285-
end
286-
287281
minetest.register_chatcommand("/set", {
288282
params = "<node>",
289283
description = "Set the current WorldEdit region to <node>",
290284
privs = {worldedit=true},
291285
func = safe_region(function(name, param)
286+
local nodes = {}
287+
288+
for nodename in param:gmatch("[^%s]+") do
289+
local node = get_node(name, nodename)
290+
if not node then
291+
worldedit.player_notify(name, 'Could not identify node "'..name..'"')
292+
return
293+
end
294+
nodes[#nodes+1] = node
295+
end
296+
292297
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
293-
local node = get_node(name, param)
294-
local count = worldedit.set(pos1, pos2, node)
298+
local count = worldedit.set(pos1, pos2, nodes)
295299
worldedit.player_notify(name, count .. " nodes set")
296-
end, check_set),
300+
end, check_region),
297301
})
298302

299303
local check_replace = function(name, param)

0 commit comments

Comments
 (0)
Please sign in to comment.