diff options
author | Philipp Sehmisch <crush@themanaworld.org> | 2009-02-10 14:42:43 +0100 |
---|---|---|
committer | Philipp Sehmisch <crush@themanaworld.org> | 2009-02-10 14:42:43 +0100 |
commit | ef5d6d3c0c8c35aabc0ee208572d95b7d1838147 (patch) | |
tree | e0b8b33f55033e17235580821fab78cc9bf3e422 /src | |
parent | fa0e4565313bd186300d24e69356169250e9f519 (diff) | |
download | manaserv-ef5d6d3c0c8c35aabc0ee208572d95b7d1838147.tar.gz manaserv-ef5d6d3c0c8c35aabc0ee208572d95b7d1838147.tar.bz2 manaserv-ef5d6d3c0c8c35aabc0ee208572d95b7d1838147.tar.xz manaserv-ef5d6d3c0c8c35aabc0ee208572d95b7d1838147.zip |
Implemented script binding item_drop to create floor items in the game world.
Diffstat (limited to 'src')
-rw-r--r-- | src/scripting/lua.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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<Script *>(lua_touserdata(s, -1)); + MapComposite* map = t->getMap(); + + i->setMap(map); + Point pos(x, y); + i->setPosition(pos); + GameState::insertSafe(i); + + return 0; +} + + LuaScript::LuaScript(): nbArgs(-1) { @@ -1017,6 +1053,7 @@ LuaScript::LuaScript(): { "effect_create", &effect_create }, { "test_tableget", &test_tableget }, { "get_map_id", &get_map_id }, + { "item_drop", &item_drop }, { NULL, NULL } }; luaL_register(mState, "tmw", callbacks); |