try this
then when you understands how this works, this page can be useful:
https://dev.minetest.net/Category:Methods
and check how other people are doing their mods
Code: Select all
minetest.register_tool("noob:spawner", {
description = "item summoner",
image = "sppawner.png",
inventory_image = "spawner_block.png",
tool_capabilities = {
full_punch_interval = 0.8,
max_drop_level=1,
}
-- when the item is used
on_use=function(itemstack, user, pointed_thing)
minetest.chat_send_all("item used")
print(dump(pointed_thing))
if pointed_thing.type=="node" then
minetest.chat_send_all("item used")
local pos=pointed_thing.above
minetest.add_entity(pos, "noob:object")
end
end,
-- when the item is placed
on_place=function(itemstack, user, pointed_thing)
print(dump(pointed_thing))
minetest.chat_send_all("item placed")
minetest.add_item(pointed_thing.above, "default:wood")
end,
})
minetest.register_entity("noob:object",{
hp_max = 1,
visual = "sprite",
textures ={"default_stone.png"},
on_activate=function(self, staticdata)
minetest.chat_send_all("object spawned")
self.more_text=" ...and more text"
end.
on_step=function(self, dtime)
self.time=self.time+dtime
if self.time<5 then
minetest.chat_send_all(self.some_text_to_say .. self.more_text)
self.object:remove()
return
end
end,
time=0,
some_text_to_say="object removed",
})
minetest.register_node("noob:block", {
description = "a block",
stack_max=500,
tiles = {"default_stone.png","default_wood.png","default_dirt.png"},
groups = { choppy = 2, oddly_breakable_by_hand = 1, flammable = 1},
on_construct=function(pos)
minetest.get_node_timer(pos):start(1)
end,
on_timer = function (pos, elapsed)
minetest.chat_send_all("timer")
return true
end
})
The console is very usefull for moders, but it has been disabled by default.
enable it by go to the minetest main manu -->
settings tab -->
advanced settings -->
graphics -->
advanced -->
enable console window -->
restart the game