From f93d86be617ba143d7cf87a99b3121ac007c870c Mon Sep 17 00:00:00 2001 From: "Tai @ Flex" Date: Tue, 28 Feb 2017 20:32:50 +0000 Subject: [PATCH] proximity --- proximity_mode.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 proximity_mode.lua diff --git a/proximity_mode.lua b/proximity_mode.lua new file mode 100644 index 0000000..4251eb3 --- /dev/null +++ b/proximity_mode.lua @@ -0,0 +1,36 @@ + +-- Proximity mode + +local playerproximitypref = {} + +local maxproximity = int(minetest.setting_get("chat_modes.maxproximity") ) or 100 + +chat_modes.register("proximity", { + help = "Send messages to players within a certain distance", + + register = function(playername, params) + local proxpref = int(params[1]) or maxproximity + if proxpref > maxproximity then + proxpref = maxproximity + end + + playerpxoimitypref[playername] = proxpref + end, + + deregister = function(playername) + playerpxoimitypref[playername] = nil + end, + + getPlayers = function(playername, message) + local targetplayers = {} + local thisplayer = minetest.get_player_by_name(playername) + + for _,player in pairs(minetest.get_connected_players() ) do + if vector.distance(player:getpos(), thisplayer:getpos() ) <= playerpxoimitypref[playername] then + targetplayers[#targetplayers] = player + end + end + + return targetplayers + end +})