From ef5d6d3c0c8c35aabc0ee208572d95b7d1838147 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 10 Feb 2009 14:42:43 +0100 Subject: Implemented script binding item_drop to create floor items in the game world. --- src/scripting/lua.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index fc9bb483..010179b4 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -976,6 +976,42 @@ static int get_map_id(lua_State *s) return 1; } +/** + * Creates an item stack on the floor + * tmw.drop_item(x, y, id[, number]) + */ +static int item_drop(lua_State *s) +{ + int x = lua_tointeger(s, 1); + int y = lua_tointeger(s, 2); + int type = lua_tointeger(s, 3); + int number = 1; + if (lua_isnumber(s, 4)) + { + number = lua_tointeger(s, 4); + } + + ItemClass *ic = ItemManager::getItem(type); + if (!ic) + { + raiseScriptError(s, "item_drop called with unknown item ID"); + } + Item *i = new Item(ic, number); + + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast