Page 1 of 1

Place a schematic

Posted: Tue Dec 16, 2014 01:55
by Don
Is there a way to place a node and it places a schematic file. Doesn't matter if it is a .we or .mts
Also, is there a way to use on_punch to place or replace a schematic

Re: Place a schematic

Posted: Tue Dec 16, 2014 03:17
by addi
Don wrote:Is there a way to place a node and it places a schematic file. Doesn't matter if it is a .we or .mts
Also, is there a way to use on_punch to place or replace a schematic
yes, shure.

just have a look into my gates mod. it does something like you want.
partial code of gates mod:

Code: Select all

local function open_gate(pos)
--local start_time = os.clock()
local meta = minetest.get_meta(pos);
if meta:get_string("state") == "closed" then -- only open the gate if its closed
local pos1 = minetest.string_to_pos(meta:get_string("pos1"))
local pos2 = minetest.string_to_pos(meta:get_string("pos2"))
minetest.create_schematic(pos1, pos2,{}, savedir..minetest.pos_to_string(pos).."_closed.schematic")--save the closed gate before opening
minetest.place_schematic(pos1, savedir..minetest.pos_to_string(pos).."_opend.schematic", nil, nil, true)
meta:set_string("state","opend");
meta:set_string("infotext","opend");
minetest.swap_node(pos, {name="gates:controler_opend"})
end
--local end_time = os.clock()
--elapsed_time = end_time-start_time
--print('start time: '   .. start_time .. 's')
--print('end time: '     .. end_time .. 's')
--print('time elapsed: ' .. elapsed_time .. 's')
end

local function toggle(pos)
local meta = minetest.get_meta(pos);
if meta:get_string("state") == "opend" then
close_gate(pos);
return "closed"
else
open_gate(pos);
return "opend"
end
end

local function punched(pos, node, puncher, pointed_thing)
--print(schematic_exists(pos,"closed"),schematic_exists(pos,"opend"))
local playername = puncher:get_player_name()
	if schematic_exists(pos,"closed") and schematic_exists(pos,"opend") then
		local status = toggle(pos);
		if status == "opend" then
		minetest.chat_send_player(playername, "Gate Opened")
		elseif status == "closed" then
		minetest.chat_send_player(playername, "Gate Closed")
		else
		minetest.chat_send_player(playername, "ERROR: Unknown state of Gate")
		end	
	end
end
minetest.register_node("gates:controler",{
description ="Gate controller",
tiles = {"gates_bg.png","gates_bg.png","gates_bg.png^gates_unknown.png"},
groups = {oddly_breakable_by_hand = 1},
after_place_node = placed,
on_receive_fields =submitted,
on_punch = punched
})
OT: i dont know how you will place a *.mts file in a minetest world since its avchd a video file :-P
so please call your file not *.mts, call it *.shemtic or *.mtsheme or...

Re: Place a schematic

Posted: Tue Dec 16, 2014 03:57
by Don
Thanks. I will look this over in the morning

Re: Place a schematic

Posted: Tue Dec 16, 2014 04:29
by Napiophelios
You should check out DeployNodes by cornernote
its not new but it still works and there are plenty of examples to study from

Also Maze by echo and HedgeMaze by thefamilygrog66
both kinda similar and both still work

Re: Place a schematic

Posted: Tue Dec 16, 2014 05:45
by Don
Napiophelios wrote:You should check out DeployNodes by cornernote
its not new but it still works and there are plenty of examples to study from

Also Maze by echo and HedgeMaze by thefamilygrog66
both kinda similar and both still work
Thanks

Re: Place a schematic

Posted: Sun Dec 28, 2014 18:53
by Sokomine
My apartments mod uses .mts files for placing schematics. Just give yourshelf an apartment:build_chest, place it in the world, and spawn any schematic you like and which you have placed in the mod's schems/ folder. It also takes care of orientation and will spawn the building rotated according to the building spawner's facedir.
The mod can be found via the link in my signature.

Re: Place a schematic

Posted: Sun Dec 28, 2014 21:54
by Don
Thanks. I am busy over the holidays but hope to work on my mods lots in January.

Re: Place a schematic

Posted: Mon Dec 29, 2014 10:42
by TenPlus1
Here is a quick example of a node, when placed that loads a schematic file:

Code: Select all

-- Schematic Block
minetest.register_node("test:schemblock", {
	description = "Schematic Block",
	tiles = {"default_grass.png"},
	groups = {crumbly=3},
	on_construct = function(pos)
		-- Remove Schematic Block
		minetest.remove_node(pos)
		-- Define Schematic File
		local schem = minetest.get_modpath("test").."/schems/build1.mts"
		-- Define Placecment Coords
		local spos = {x=pos.x-3,y=pos.y,z=pos.z-3}
		-- Place Schematic
		minetest.place_schematic(spos,schem,"0",{},false)
	end,
})

Re: Place a schematic

Posted: Mon Dec 29, 2014 15:37
by Don
Exactly what I needed. Thank you!