covfefe 33 Posted December 9, 2022 Share Posted December 9, 2022 Hi, I wonder if anyone knows how to get the count of an inventory item in C++, like the C++ equivalent of LUA's pc.count_item() function. I've spent a lot of time looking around in the source before asking here, I couldn't figure it out. Would definitely appreciate any help. Thank you to the non haters and non bullies. 1 Link to comment Share on other sites More sharing options...
Filiq 23 Posted December 9, 2022 Share Posted December 9, 2022 (edited) CountSpecifyItem(item_vnum) int pc_count_item(lua_State* L) { if (lua_isnumber(L, -1)) lua_pushnumber(L,CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem((DWORD)lua_tonumber(L, -1))); else if (lua_isstring(L, -1)) { DWORD item_vnum; if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum)) { sys_err("QUEST count_item call error : wrong item name : %s", lua_tostring(L,1)); lua_pushnumber(L, 0); } else { lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(item_vnum)); } } else lua_pushnumber(L, 0); return 1; } and this is the function, you can find her in char_item.cpp int CHARACTER::CountSpecifyItem(DWORD vnum) const { int count = 0; LPITEM item; for (int i = 0; i < INVENTORY_MAX_NUM; ++i) { item = GetInventoryItem(i); if (NULL != item && item->GetVnum() == vnum) { // ���� ������ ��ϵ� �����̸� �Ѿ��. if (m_pkMyShop && m_pkMyShop->IsSellingItem(item->GetID())) { continue; } else { count += item->GetCount(); } } } return count; } Edited December 9, 2022 by Filiq 1 Link to comment Share on other sites More sharing options...
covfefe 33 Posted December 9, 2022 Author Share Posted December 9, 2022 19 minutes ago, Filiq said: CountSpecifyItem(item_vnum) int pc_count_item(lua_State* L) { if (lua_isnumber(L, -1)) lua_pushnumber(L,CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem((DWORD)lua_tonumber(L, -1))); else if (lua_isstring(L, -1)) { DWORD item_vnum; if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum)) { sys_err("QUEST count_item call error : wrong item name : %s", lua_tostring(L,1)); lua_pushnumber(L, 0); } else { lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(item_vnum)); } } else lua_pushnumber(L, 0); return 1; } and this is the function, you can find her in char_item.cpp int CHARACTER::CountSpecifyItem(DWORD vnum) const { int count = 0; LPITEM item; for (int i = 0; i < INVENTORY_MAX_NUM; ++i) { item = GetInventoryItem(i); if (NULL != item && item->GetVnum() == vnum) { // ���� ������ ��ϵ� �����̸� �Ѿ��. if (m_pkMyShop && m_pkMyShop->IsSellingItem(item->GetID())) { continue; } else { count += item->GetCount(); } } } return count; } Thanks for your help, you will laugh, i figured it out on my own within 5 min after creating the post. But thank you brother! Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now