Page 1 of 1

place block chat command

PostPosted: Mon Jul 27, 2015 10:22
by RHR
Hey guys I need some help:
I want to create a mod with a chat command that places a block on a position, but I have no idea how to do that. The idea behind that is that it would be very useful in creative mode if you use the singlenode mapgen (currently I always have to use worldedit to do that).

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
in general:
/placeblock modname:nodename x,y,z
example:
/placeblock default:stone 10,15,10

Re: place block chat command

PostPosted: Mon Jul 27, 2015 17:08
by Krock
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
/placeblock default:stone 10,15,10

given: player name and param ("default:stone 10,15,10")

Now let's split this param string:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local args = param:split(" ")

-> Outputs an array: { "default:stone", "10,15,10" }

Now split the 2nd element into numbers:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local arg_pos = args[2]:split(",")
local pos = { x = tonumber(arg_pos[1]), y = tonumber(arg_pos[2]), z = tonumber(arg_pos[3]) }


And the final code:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local args = param:split(" ")
if #args ~= 2 then
   return false, "Wrong arguments"
end
local arg_pos = args[2]:split(",")
if #arg_pos ~= 3 then
   return false, "Wrong arguments"
end
local pos = { x = tonumber(arg_pos[1]), y = tonumber(arg_pos[2]), z = tonumber(arg_pos[3]) }
minetest.set_node(pos, { name = args[1] })

Re: place block chat command

PostPosted: Tue Jul 28, 2015 17:49
by Hybrid Dog
lf you use worldedit and don't want to have to type the commands, you could use the chatcommand tool making it execute the chatcommands "//pos1", "//pos2" and "//set default:cobble" when using it.
https://github.com/HybridDog/command_tool

Re: place block chat command

PostPosted: Wed Jul 29, 2015 13:57
by RHR
@Krock:
Thx for that code that helps a lot! :D

@Hybrid Dog:
Thx, but I was just looking for a simple way to place a single block in the air. :)