diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 40 | ||||
-rw-r--r-- | src/script/lua_api/l_object.h | 3 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 6c6415a09..86e5a71cd 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1090,6 +1090,45 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L) return 1; } +// set_sky(self, bgcolor, type, list) +int ObjectRef::l_set_sky(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + video::SColor bgcolor(255,255,255,255); + if (!lua_isnil(L, 2)) + bgcolor = readARGB8(L, 2); + + std::string type = luaL_checkstring(L, 3); + + std::vector<std::string> params; + if (lua_istable(L, 4)) { + int table = lua_gettop(L); + lua_pushnil(L); + while (lua_next(L, table) != 0) { + // key at index -2 and value at index -1 + if (lua_isstring(L, -1)) + params.push_back(lua_tostring(L, -1)); + else + params.push_back(""); + // removes value, keeps key for next iteration + lua_pop(L, 1); + } + } + + if (type == "skybox" && params.size() != 6) + throw LuaError(L, "skybox expects 6 textures"); + + if (!getServer(L)->setSky(player, bgcolor, type, params)) + return 0; + + lua_pushboolean(L, true); + return 1; +} + ObjectRef::ObjectRef(ServerActiveObject *object): m_object(object) { @@ -1207,5 +1246,6 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, hud_set_hotbar_itemcount), luamethod(ObjectRef, hud_set_hotbar_image), luamethod(ObjectRef, hud_set_hotbar_selected_image), + luamethod(ObjectRef, set_sky), {0,0} }; diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index c8c67f2c5..b41938ca7 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -225,6 +225,9 @@ private: // hud_set_hotbar_selected_image(self, name) static int l_hud_set_hotbar_selected_image(lua_State *L); + // set_sky(self, type, list) + static int l_set_sky(lua_State *L); + public: ObjectRef(ServerActiveObject *object); |