Add minetest.get_connected_players()
authorPerttu Ahola <celeron55@gmail.com>
Fri, 30 Mar 2012 10:45:51 +0000 (13:45 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 30 Mar 2012 10:45:51 +0000 (13:45 +0300)
builtin/builtin.lua
games/minimal/mods/experimental/init.lua

index 71cd4cf5339e3afcd30fbc89e79f2049da0c297d..55220a607012970bfca1708cd99267fd9b3b0b26 100644 (file)
@@ -837,6 +837,17 @@ function minetest.check_player_privs(name, privs)
        return true, ""
 end
 
+function minetest.get_connected_players()
+       -- This could be optimized a bit, but leave that for later
+       local list = {}
+       for _, obj in pairs(minetest.env:get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
+               if obj:get_player_name() then
+                       table.insert(list, obj)
+               end
+       end
+       return list
+end
+
 --
 -- Chat commands
 --
index f1b8ec44ae7e620a297bc18fd119181747cb7ebc..55ea64132ef98405ac568111b787bc034259172c 100644 (file)
@@ -8,13 +8,11 @@ experimental = {}
 
 experimental.player_visual_index = 0
 function switch_player_visual()
-       for _, obj in pairs(minetest.env:get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
-               if obj:get_player_name() then
-                       if experimental.player_visual_index == 0 then
-                               obj:set_properties({visual="upright_sprite"})
-                       else
-                               obj:set_properties({visual="cube"})
-                       end
+       for _, obj in pairs(minetest.get_connected_players()) do
+               if experimental.player_visual_index == 0 then
+                       obj:set_properties({visual="upright_sprite"})
+               else
+                       obj:set_properties({visual="cube"})
                end
        end
        experimental.player_visual_index = (experimental.player_visual_index + 1) % 2