diff options
author | bigfoot547 <bigfoot547@users.noreply.github.com> | 2017-03-22 15:13:03 -0500 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-03-22 21:13:03 +0100 |
commit | 9efc5da0fb7d276deff55db6e4eb89d24ca72b5d (patch) | |
tree | 5f6c3d614d2f2780867c3407c7a94c0f26a29b41 | |
parent | c4b98deb616fbe204c503d678fb920baa33cbede (diff) | |
download | minetest-9efc5da0fb7d276deff55db6e4eb89d24ca72b5d.tar.gz minetest-9efc5da0fb7d276deff55db6e4eb89d24ca72b5d.tar.bz2 minetest-9efc5da0fb7d276deff55db6e4eb89d24ca72b5d.zip |
[CSM] Add function to get player names in range (#5435)
* [CSM] Add function to get currently connected player names
-rw-r--r-- | clientmods/preview/init.lua | 9 | ||||
-rw-r--r-- | doc/client_lua_api.md | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_client.cpp | 17 | ||||
-rw-r--r-- | src/script/lua_api/l_client.h | 3 |
4 files changed, 33 insertions, 2 deletions
diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 008f7ac14..c57a62155 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -102,7 +102,7 @@ core.register_on_punchnode(function(pos, node) print(dump(itemstack:get_count())) print(dump(itemstack:get_wear())) print(dump(itemstack:get_meta())) - print(dump(itemstack:get_metadata())) + print(dump(itemstack:get_metadata() print(dump(itemstack:is_known())) --print(dump(itemstack:get_definition())) print(dump(itemstack:get_tool_capabilities())) @@ -120,3 +120,10 @@ core.register_on_punchnode(function(pos, node) print("node:" .. dump(node)) return false end) + +-- This is an example function to ensure it's working properly, should be removed before merge +core.register_chatcommand("list_players", { + func = function(param) + core.display_chat_message(dump(core.get_player_names())) + end +}) diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md index 5fba66c69..ced1a40a4 100644 --- a/doc/client_lua_api.md +++ b/doc/client_lua_api.md @@ -737,6 +737,10 @@ Call these functions only at load time! * `minetest.get_wielded_item()` * Returns the itemstack the local player is holding +### Client Environment +* `minetest.get_player_names()` + * Returns list of player names on server + ### Misc. * `minetest.parse_json(string[, nullvalue])`: returns something * Convert a string containing JSON data into the Lua equivalent @@ -870,4 +874,4 @@ Named colors are also supported and are equivalent to [CSS Color Module Level 4](http://dev.w3.org/csswg/css-color/#named-colors). To specify the value of the alpha channel, append `#AA` to the end of the color name (e.g. `colorname#08`). For named colors the hexadecimal string representing the alpha -value must (always) be two hexadecima
\ No newline at end of file +value must (always) be two hexadecima diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 1673a62ce..52c7f6f30 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -69,6 +69,22 @@ int ModApiClient::l_display_chat_message(lua_State *L) return 1; } +// get_player_names() +int ModApiClient::l_get_player_names(lua_State *L) +{ + const std::list<std::string> &plist = getClient(L)->getConnectedPlayerNames(); + lua_createtable(L, plist.size(), 0); + int newTable = lua_gettop(L); + int index = 1; + std::list<std::string>::const_iterator iter; + for (iter = plist.begin(); iter != plist.end(); iter++) { + lua_pushstring(L, (*iter).c_str()); + lua_rawseti(L, newTable, index); + index++; + } + return 1; +} + // show_formspec(formspec) int ModApiClient::l_show_formspec(lua_State *L) { @@ -154,6 +170,7 @@ void ModApiClient::Initialize(lua_State *L, int top) { API_FCT(get_current_modname); API_FCT(display_chat_message); + API_FCT(get_player_names); API_FCT(set_last_run_mod); API_FCT(get_last_run_mod); API_FCT(show_formspec); diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index def9b48a3..fcf8c39ea 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -31,6 +31,9 @@ private: // display_chat_message(message) static int l_display_chat_message(lua_State *L); + + // get_player_names() + static int l_get_player_names(lua_State *L); // show_formspec(name, fornspec) static int l_show_formspec(lua_State *L); |