From b9e8e20c9cb87e441b3998b42f8d7f31c71f8a3f Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 2 Dec 2011 12:43:57 +0200 Subject: Script-defined creative inventory --- src/scriptapi.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index dce454ea4..cb26fa472 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -402,6 +402,8 @@ static void setfloatfield(lua_State *L, int table, static void inventory_set_list_from_lua(Inventory *inv, const char *name, lua_State *L, int tableindex, IGameDef *gamedef, int forcesize=-1) { + if(tableindex < 0) + tableindex = lua_gettop(L) + 1 + tableindex; // If nil, delete list if(lua_isnil(L, tableindex)){ inv->deleteList(name); @@ -1808,7 +1810,7 @@ private: // Return lua_pushboolean(L, added); if(!added) - lua_pushstring(L, "does not fit"); + lua_pushstring(L, "failed to add item"); return 2; } catch(SerializationError &e){ // Return @@ -2693,6 +2695,15 @@ bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player) return positioning_handled_by_some; } +void scriptapi_get_creative_inventory(lua_State *L, ServerRemotePlayer *player) +{ + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "creative_inventory"); + luaL_checktype(L, -1, LUA_TTABLE); + inventory_set_list_from_lua(&player->inventory, "main", L, -1, + player->getEnv()->getGameDef(), PLAYER_INVENTORY_SIZE); +} + /* craftitem */ -- cgit v1.2.3