place block chat command

User avatar
RHR
Member
 
Posts: 214
Joined: Mon Jan 27, 2014 20:07
GitHub: RHRhino

place block chat command

by RHR » Mon Jul 27, 2015 10:22

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
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: place block chat command

by Krock » Mon Jul 27, 2015 17:08

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] })
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: place block chat command

by Hybrid Dog » Tue Jul 28, 2015 17:49

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
 

User avatar
RHR
Member
 
Posts: 214
Joined: Mon Jan 27, 2014 20:07
GitHub: RHRhino

Re: place block chat command

by RHR » Wed Jul 29, 2015 13:57

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


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 26 guests

cron