From 05065935084b989e1cc08432b38fae04e5b71a1e Mon Sep 17 00:00:00 2001 From: "alexey.min" Date: Sat, 12 May 2012 19:39:01 +0000 Subject: [PATCH] l2c_getUserItems() done --- l2detect/UserInventory.cpp | 16 +++++++++++- l2detect/UserInventory.h | 12 ++++++--- l2detect/se_funcs/SE_funcs.cpp | 1 + l2detect/se_funcs/SE_funcs.h | 1 + l2detect/se_funcs/sef_items.cpp | 45 +++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/l2detect/UserInventory.cpp b/l2detect/UserInventory.cpp index 0332aad..7e3a69f 100644 --- a/l2detect/UserInventory.cpp +++ b/l2detect/UserInventory.cpp @@ -5,6 +5,20 @@ extern class CConfig g_cfg; + +void UserInventoryItem::getItemName( char *out, size_t maxCount ) +{ + out[0] = 0; + char *aname = (char *)malloc( 1024 ); + if( aname ) + { + L2Data_DB_GetItemNamePicByID( itemID, aname, NULL ); + strncpy( out, aname, maxCount ); + free( aname ); + } +} + + UserInventory::UserInventory() { clear(); @@ -34,7 +48,7 @@ int UserInventory::addItem( UserInventoryItem& it ) int i; for( i=0; ipaperdoll_oid[ slot ] ); return 2; } + + +// table l2c_getUserItems() +int l2c_getUserItems( lua_State *L ) +{ + if( !g_game_client ) { lua_pushboolean( L, 0 ); return 1; } + UserInventory *inv = &(g_game_client->ai.inv); + // + int tableIndex = 1; + lua_createtable( L, 0, 0 ); + int i = 0; + char itemName[255] = {0}; + for( i=0; iitem[i].isUnused() ) continue; + inv->item[i].getItemName( itemName, sizeof(itemName)-1 ); + lua_pushnumber( L, tableIndex ); + lua_createtable( L, 0, 0 ); + // + lua_pushstring( L, "itemId" ); + lua_pushinteger( L, inv->item[i].itemID ); + lua_settable( L, -3 ); + // + lua_pushstring( L, "itemName" ); + lua_pushstring( L, itemName ); + lua_settable( L, -3 ); + // + lua_pushstring( L, "objectId" ); + lua_pushinteger( L, inv->item[i].objectID ); + lua_settable( L, -3 ); + // + lua_pushstring( L, "isEquipped" ); + lua_pushboolean( L, inv->item[i].isEquipped ); + lua_settable( L, -3 ); + // + lua_pushstring( L, "count" ); + lua_pushnumber( L, (lua_Number)inv->item[i].count ); + lua_settable( L, -3 ); + // + lua_settable( L, -3 ); + tableIndex++; + } + // + return 1; +}