Add the "sayer" node

This commit is contained in:
palige 2015-09-03 18:12:41 +02:00
parent ab837d4775
commit 85afcc1f42
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,2 @@
mesecons
default

View File

@ -0,0 +1,40 @@
local MAX_DISTANCE = 8
local sayer_activate = function(pos)
local players = minetest.get_connected_players()
local text = minetest.get_meta(pos):get_string("text")
for index, player in pairs(players) do
local distance = vector.distance(pos, player:getpos())
if distance <= MAX_DISTANCE then
minetest.chat_send_player(player:get_player_name(), "Sayer at pos "
..tostring(pos.x)..","
..tostring(pos.y)..","
..tostring(pos.z)
.." says : "
..text)
end
end
end
minetest.register_node("moremesecons_sayer:sayer", {
description = "sayer",
tiles = {"mesecons_noteblock.png", "default_wood.png", "default_wood.png", "default_wood.png", "default_wood.png", "default_wood.png"},
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
groups = {dig_immediate = 2},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "field[text;text;${text}]")
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
meta:set_string("text", fields.text)
end,
mesecons = {effector = {
action_on = sayer_activate
}}
})