summaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-12-02 12:43:57 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-12-02 12:43:57 +0200
commitb9e8e20c9cb87e441b3998b42f8d7f31c71f8a3f (patch)
tree9ff91e7afb0a90feb0c5380eee75dbfb51610b40 /src/scriptapi.cpp
parent932988af4650cdd844669d4cd238907409413db6 (diff)
downloadminetest-b9e8e20c9cb87e441b3998b42f8d7f31c71f8a3f.tar.gz
minetest-b9e8e20c9cb87e441b3998b42f8d7f31c71f8a3f.tar.bz2
minetest-b9e8e20c9cb87e441b3998b42f8d7f31c71f8a3f.zip
Script-defined creative inventory
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp13
1 files changed, 12 insertions, 1 deletions
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
*/