x_formspec =
"invsize[8,9;]"..
"label[1,3;Variable_from_node]"
minetest.register_node("X:x", {
local Variable_from_node = 10
})
1244 wrote:In which way I can add meta float from node to formspec this node? Example: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
x_formspec =
"invsize[8,9;]"..
"label[1,3;Variable_from_node]"
minetest.register_node("X:x", {
local Variable_from_node = 10
})
In which way I can do this?
"label[1,3;$(Variable_from_node)]"
on_punch = function(pos, node, puncher)
wield = puncher:get_wielded_item()
print(wield: get_count())
wield:take_item()
print(wield: get_count())
end
on_construct= function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec",
"size[8,9]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_player;main;0,5;8,4]"
)
meta:set_string("infotext", "Campfire")
local inv = meta:get_inventory()
inv:set_size("fuel",1)
end,
Exactly what I was going to ask.10twenty4 wrote:I'm trying to create a menu when you right click a node. I believe I'm doing this correctly (adding a formspec to the metadata), but nothing happens. I've tried copying the line from the furnace code and other examples, but that doesn't work either. I'm assuming I'm missing something, but I don't know what.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
on_construct= function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec",
"size[8,9]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_player;main;0,5;8,4]"
)
meta:set_string("infotext", "Campfire")
local inv = meta:get_inventory()
inv:set_size("fuel",1)
end,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
itemstack: take_item()
user:set_wielded_item(itemstack)
end
end
})
local on_place_trans = function(pos, node, placer)
if node.name == 'mod:panel_center'then
fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.env:add_node({x=pos.x+1, y=pos.y, z=pos.z}, { name = "mod:panel_right", paramtype2='none', param2=fdir})
nodeupdate(pos)
minetest.env:add_node({x=pos.x-1, y=pos.y, z=pos.z}, { name = "mode:panel_left", paramtype2='none', param2=fdir})
nodeupdate(pos)
end
end
minetest.register_on_placenode(on_place_trans)
bentleysb wrote:I am trying to make it so when a block is placed then 2 other blocks are placed to the right and left of that block....
local lookDir = placer:get_look_dir()
local pos1, pos2
if math.abs(lookDir.x) < math.abs(lookDir.z) then
pos1 = { x = pos.x-1, y = pos.y, z = pos.z }
pos2 = { x = pos.x+1, y = pos.y, z = pos.z }
else
pos1 = { x = pos.x, y = pos.y, z = pos.z-1 }
pos2 = { x = pos.x, y = pos.y, z = pos.z+1 }
end
function minetest.register_on_item_eat(hp_change, replace_with_item)
print("[register_on_item_eat] 2")
return function(itemstack, user, pointed_thing) -- closure
if itemstack:take_item() ~= nil then
user:set_hp(user:get_hp() + hp_change)
itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
end
return itemstack
end
end
function minetest.item_eat(hp_change, replace_with_item)
print("[register_on_item_eat] 1")
-- Run script hook
local _, callback
for _, callback in ipairs(minetest.registered_on_item_eat) do
-- Copy hp_change and replace_with_item because callback can modify them
local hp_change_copy = {x=pos.x, y=pos.y, z=pos.z}
local replace_copy = hp_change
callback(hp_change_copy, return_copy)
end
end
minetest.registered_on_item_eat, minetest.register_on_item_eat = make_registration()
Casimir wrote:I tried to make a register_on_item_eat function, but failed. Nothing happens.
Zsoltisawesome wrote:Is there way to make a node edible?
Likwid H-Craft wrote:Zsoltisawesome wrote:Is there way to make a node edible?
Yes
minetest.register_node("forcefield:forcefield", {
tiles = {"forcefield_forcefield.png"},
drawtype = glasslike,
sunlight_propagates = true,
walkable = true,
diggable = false,
on_punch = function(pos, node, puncher)
pos = position
a = "a" + "1"
end,
})
default.forcefield_formspec =
"size[8,9]"..
"list[current_name;coal;1,1;6,3;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("forcefield:fmaker", {
description = "Forcefield Generator",
tiles = {"forcefield_sides.png","forcefield_sides.png","forcefield_front.png","forcefield_sides.png","forcefield_sides.png","forcefield_sides.png"},
groups = {snappy=2, choppy=2},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", default.forcefield_formspec)
meta:set_string("infotext", "forcefield generator")
local inv = meta:get_inventory()
inv:set_size("coal", 18)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("coal", 18) then
return false
end
return true
end,
})
minetest.register_abm({
nodenames = {"forcefield:fmaker"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local fuel = inv:get_list("coal")
if fuel == "default:coal_lump" then
srcstack = inv:get_stack("coal", 1)
srcstack:take_item("default:coal_lump")
inv:set_stack("coal", 1, srcstack)
else
print("there was no coal")
end
end,
})
minetest.register_craft({
output = 'forcefield:fmaker',
recipe = {
{'default:mese', 'default:mese', 'default:mese'},
{'default:mese', 'default:furnace', 'default:mese'},
{'default:mese', 'default:mese', 'default:mese'},
}
})
ch98 wrote:Copy of my forcefield mod help topic:
...
I am stuck on part detecting if coal is in the forcefield generator....
function register_element (name1,image,description1)
minetest.register_alias("chemistry:..name1..","..name1..")
minetest.register_craftitem("chemistry:..name1..", {
description = "..description1..",
inventory_image = "..image.."
})
end
1244 wrote:Why this function isn't working?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
function register_element (name1,image,description1)
minetest.register_alias("chemistry:..name1..","..name1..")
minetest.register_craftitem("chemistry:..name1..", {
description = "..description1..",
inventory_image = "..image.."
})
end
function register_element (name1,image,description1)
minetest.register_alias(name1,"chemistry:"..name1)
minetest.register_craftitem("chemistry:"..name1, {
description = description1,
inventory_image = image
})
end
Users browsing this forum: No registered users and 13 guests