diff --git a/init.lua b/init.lua index c7df09d..1c6bb6d 100644 --- a/init.lua +++ b/init.lua @@ -48,12 +48,14 @@ minetest.register_node("mysoundblocks:block", { local meta = minetest.get_meta(pos) minetest.show_formspec(player:get_player_name(),"fs", - "size[6,5;]".. + "size[6,6;]".. "field[1,1;4.5,1;snd;Enter Sound Name;]".. - "field[1,2.5;2,1;sndl;Length;5]".. - "field[3.5,2.5;2,1;sndhd;Radius;3]".. + "field[1,2;4.5,1;txt;Enter Chat Message;]".. + "field[1,3;2,1;sndl;Length;5]".. + "field[3.5,3;2,1;sndhd;Radius;3]".. "button_exit[1,4;2,1;ents;Sound]".. - "button_exit[3,4;2,1;entc;Chat]") + "button_exit[3,4;2,1;entc;Chat]".. + "button_exit[2,5;2,1;entb;Both]") minetest.register_on_player_receive_fields(function(player, formname, fields) local meta = minetest.get_meta(pos) @@ -61,24 +63,36 @@ minetest.register_node("mysoundblocks:block", { local thing1 = fields["snd"] local thing2 = fields["sndl"] local thing3 = fields["sndhd"] - local thing4 = "" + local thing4 = fields["txt"] + local thing5 = "" if fields["ents"] or - fields["entc"] then + fields["entc"] or + fields["entb"] then if fields["ents"] then - thing4 = "sound" + thing5 = "sound" meta:set_string("a",thing1) meta:set_string("b",thing2) meta:set_string("c",thing3) meta:set_string("d",thing4) + meta:set_string("e",thing5) minetest.swap_node(pos,{name = "mysoundblocks:block_hidden"}) elseif fields["entc"] then - thing4 = "chat" + thing5 = "chat" meta:set_string("a",thing1) meta:set_string("b",thing2) meta:set_string("c",thing3) meta:set_string("d",thing4) + meta:set_string("e",thing5) + minetest.swap_node(pos,{name = "mysoundblocks:block_hidden"}) + elseif fields["entb"] then + thing5 = "both" + meta:set_string("a",thing1) + meta:set_string("b",thing2) + meta:set_string("c",thing3) + meta:set_string("d",thing4) + meta:set_string("e",thing5) minetest.swap_node(pos,{name = "mysoundblocks:block_hidden"}) end @@ -159,35 +173,28 @@ minetest.register_chatcommand("hidesb", { minetest.register_abm({ nodenames = {"mysoundblocks:block_hidden"}, - interval = 1, -- abm's start from 1 second and above + interval = 0.2, -- abm's start from 1 second and above chance = 1, catch_up = false, action = function(pos, node, active_object_count, active_object_count_wider) local meta = minetest.get_meta(pos) + local block_sound = meta:get_string("a") - - if block_sound == nil or - block_sound == "" then - minetest.swap_node(pos,{name = "mysoundblocks:block"}) - return - end - local block_time = tonumber(meta:get_string("b")) + local rad_dist = tonumber(meta:get_string("c")) + local block_text = meta:get_string("d") + local sound_chat = meta:get_string("e") if block_time == nil then block_time = 5 end - local rad_dist = tonumber(meta:get_string("c")) - if rad_dist == nil then rad_dist = 3 end - local sound_chat = meta:get_string("d") - local all_objects = minetest.get_objects_inside_radius(pos, rad_dist) local p @@ -202,14 +209,38 @@ minetest.register_abm({ player_name[p] = true if sound_chat == "sound" then + if block_sound then + minetest.sound_play(block_sound, { + max_hear_distance = 10, + to_player = p, + gain = 1.0, + }) + else + minetest.swap_node(pos,{name = "mysoundblocks:block"}) + return + end + + elseif sound_chat == "chat" then + if block_text then + minetest.chat_send_player(p,block_text) + else + minetest.swap_node(pos,{name = "mysoundblocks:block"}) + return + end + + elseif sound_chat == "both" then + if block_sound and block_text then + minetest.sound_play(block_sound, { + max_hear_distance = 10, + to_player = p, + gain = 1.0, + }) + minetest.chat_send_player(p,block_text) + else + minetest.swap_node(pos,{name = "mysoundblocks:block"}) + return + end - minetest.sound_play(block_sound, { - max_hear_distance = 10, - to_player = p, - gain = 1.0, - }) - else - minetest.chat_send_player(p,block_sound) end minetest.after(block_time, function(p) -- time before player can hear the sound again