From: Perttu Ahola Date: Fri, 30 Mar 2012 10:45:51 +0000 (+0300) Subject: Add minetest.get_connected_players() X-Git-Tag: 0.4.dev-20120408~73 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=80a64341f0f2ab0ae418fdf313c9a9f04c0f8047;p=oweals%2Fminetest.git Add minetest.get_connected_players() --- diff --git a/builtin/builtin.lua b/builtin/builtin.lua index 71cd4cf53..55220a607 100644 --- a/builtin/builtin.lua +++ b/builtin/builtin.lua @@ -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 -- diff --git a/games/minimal/mods/experimental/init.lua b/games/minimal/mods/experimental/init.lua index f1b8ec44a..55ea64132 100644 --- a/games/minimal/mods/experimental/init.lua +++ b/games/minimal/mods/experimental/init.lua @@ -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