Add speaker node

Minor cleanups and fixes by sofar.
Added reading of existing message for easy editing.
Add attribution for sound effect.
This commit is contained in:
Extex101 2020-03-16 02:33:41 +00:00 committed by Auke Kok
parent 75cfc90fe3
commit 4673d6dfcd
6 changed files with 54 additions and 1 deletions

View File

@ -1,3 +1,4 @@
boxes
frame
sounds
fsc

View File

@ -1,4 +1,3 @@
--[[
mech - mechanisms for Inside The Box
@ -1378,6 +1377,57 @@ minetest.register_node("mech:randomizer", {
end,
})
minetest.register_node("mech:speaker", {
description = S("Speaker"),
tiles = {"speaker.png"},
groups = {node = 1, unbreakable = 1},
sounds = sounds.metal,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("msg", "")
end,
on_rightclick = function(pos, node, puncher, itemstack, pointed_thing)
local name = puncher:get_player_name()
if not puncher then
return itemstack
elseif not boxes.players_editing_boxes[name] then
return do_player_place(pos, node, puncher, itemstack, pointed_thing)
end
local meta = minetest.get_meta(pos)
local metatable = meta:to_table()
local msg = ""
if metatable.fields and metatable.fields.msg then
msg = metatable.fields.msg
end
local form = "field[msg;message;" .. msg .. "]"
fsc.show(name, form, {}, function(player, fields, context)
if fields.msg then
meta:set_string("msg", fields.msg)
return true
end
return nil
end)
return itemstack
end,
on_trigger = function(pos)
local box = boxes.find_box(pos)
if not box then
return
end
local meta = minetest.get_meta(pos)
local msg = meta:get_string("msg")
if msg then
-- underline text character
local underline = string.char(0xcd) .. string.char(0x9f)
local newstring = ""
for i = 0, #msg, 1 do
newstring = newstring .. string.sub(msg, i, i) .. underline
end
minetest.chat_send_player(box.name, newstring)
minetest.sound_play("speaker_trigger", {to_player = box.name}, true)
end
end,
})
-- event reactors:
-- doors

View File

@ -0,0 +1,2 @@
* speaker_trigger : From AlienX, CC-BY-3.0
- https://freesound.org/people/AlienXXX/sounds/249975/

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B