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
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
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
})
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
-- 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,
})
Users browsing this forum: No registered users and 2 guests