notbugme 14 Posted January 12, 2018 Share Posted January 12, 2018 Hello, I had problem with adding this function: Spoiler ACMD(do_sort_inventory) { std::vector<CItem*> collectItems; std::vector<WORD> oldCells; int totalSize = 0; for (auto i = 0; i < INVENTORY_MAX_COUNT; ++i) { auto item = ch->GetInventoryItem(i); if (item) { totalSize += item->GetSize(); oldCells.push_back(item->GetCell()); collectItems.push_back(item); } } if (totalSize - 3 >= INVENTORY_MAX_COUNT) { ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT")); return; } for (auto& item : collectItems) { item->RemoveFromCharacter(); } std::sort(collectItems.begin(), collectItems.end(), []( CItem* a, CItem* b) { return a->GetVnum() < b->GetVnum(); }); for (auto& sortedItem : collectItems) { auto cell = ch->GetEmptyInventory(sortedItem->GetSize()); sortedItem->AddToCharacter(ch, TItemPos(INVENTORY, cell), false); } } When I add this code I get this errors: Spoiler cmd_general.cpp: In function 'void do_sort_inventory(CHARACTER*, const char*, int, int)': cmd_general.cpp:3641: error: ISO C++ forbids declaration of 'i' with no type cmd_general.cpp:3641: error: 'INVENTORY_MAX_COUNT' was not declared in this scope cmd_general.cpp:3642: error: ISO C++ forbids declaration of 'item' with no type cmd_general.cpp:3642: error: invalid conversion from 'CItem*' to 'int' cmd_general.cpp:3644: error: request for member 'GetSize' in 'item', which is of non-class type 'int' cmd_general.cpp:3645: error: request for member 'GetCell' in 'item', which is of non-class type 'int' cmd_general.cpp:3646: error: invalid conversion from 'int' to 'CItem*' cmd_general.cpp:3646: error: initializing argument 1 of 'void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = CItem*, _Alloc = std::allocator<CItem*>]' cmd_general.cpp:3649: error: 'INVENTORY_MAX_COUNT' was not declared in this scope cmd_general.cpp:3654: error: a function-definition is not allowed here before ':' token cmd_general.cpp:3659: error: expected primary-expression before '[' token cmd_general.cpp:3659: error: expected primary-expression before ']' token cmd_general.cpp:3659: error: expected primary-expression before '*' token cmd_general.cpp:3659: error: 'a' was not declared in this scope cmd_general.cpp:3659: error: expected primary-expression before '*' token cmd_general.cpp:3659: error: 'b' was not declared in this scope cmd_general.cpp:3663: error: expected primary-expression before 'for' cmd_general.cpp:3663: error: expected `)' before 'for' cmd_general.cpp:3663: error: a function-definition is not allowed here before ':' token cmd_general.cpp:3667: error: expected primary-expression before '}' token cmd_general.cpp:3667: error: expected `;' before '}' token cmd_general.cpp:3667: error: expected primary-expression before '}' token cmd_general.cpp:3667: error: expected `)' before '}' token cmd_general.cpp:3667: error: expected primary-expression before '}' token cmd_general.cpp:3667: error: expected `;' before '}' token Link to comment Share on other sites More sharing options...
kasko30 19 Posted January 12, 2018 Share Posted January 12, 2018 you have problem with putting ; and ] error: expected `;' before '}' token Link to comment Share on other sites More sharing options...
notbugme 14 Posted January 12, 2018 Author Share Posted January 12, 2018 9 minut temu, kasko30 napisał: you have problem with putting ; and ] error: expected `;' before '}' token I know it but i can't found where Link to comment Share on other sites More sharing options...
Салом 20 Posted January 12, 2018 Share Posted January 12, 2018 (edited) AddToCharacter take two agrguments not three. INVENTORY_MAX_COUNT dosen't exist in source, unless you changed his name. C++11 is required for these codes to work. You are using lambda expression which is a c++11 feature, same for auto. Here it's the fixed version. Spoiler { std::vector<CItem*> collectItems; std::vector<WORD> oldCells; int totalSize = 0; for (auto i = 0; i < INVENTORY_MAX_NUM; ++i) { auto item = ch->GetInventoryItem(i); if (item) { totalSize += item->GetSize(); oldCells.push_back(item->GetCell()); collectItems.push_back(item); } } if (totalSize - 3 >= INVENTORY_MAX_NUM) { ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT")); return; } for (auto& item : collectItems) { item->RemoveFromCharacter(); } std::sort(collectItems.begin(), collectItems.end(), []( CItem* a, CItem* b) { return a->GetVnum() < b->GetVnum(); }); for (auto& sortedItem : collectItems) { auto cell = ch->GetEmptyInventory(sortedItem->GetSize()); sortedItem->AddToCharacter(ch, TItemPos(INVENTORY, cell)); } } You get the errors because your compiler dosen't support C++11. From what source did you steal the codes? Edited August 24, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
notbugme 14 Posted January 12, 2018 Author Share Posted January 12, 2018 I don't steal this i found on another forum bro, thanks for checks. Someone can transform this code to older compiler? Link to comment Share on other sites More sharing options...
Premium Galet 509 Posted January 12, 2018 Premium Share Posted January 12, 2018 il y a 9 minutes, notbugme a dit : I don't steal this i found on another forum bro, thanks for checks. Someone can transform this code to older compiler? What is your compiler at the moment ? You can simply add -std=c++11 into your makefile, but I clearly suggest you to update your compiler (either clang or gcc) Link to comment Share on other sites More sharing options...
notbugme 14 Posted January 12, 2018 Author Share Posted January 12, 2018 Now i had GCC 4.8.3, i'ts on 9.2 FreeBSD Link to comment Share on other sites More sharing options...
Honorable Member xP3NG3Rx 19657 Posted January 12, 2018 Honorable Member Share Posted January 12, 2018 Here is the code for old compilers: struct s_sort { bool operator() (LPITEM src, LPITEM dst) { return (src->GetVnum()<dst->GetVnum()); } } _sort; ACMD(do_sort_inventory) { std::vector<LPITEM> collectItems; std::vector<WORD> oldCells; int totalSize = 0; for (WORD i = 0; i < INVENTORY_MAX_NUM; ++i) { LPITEM item = ch->GetInventoryItem(i); if (item) { totalSize += item->GetSize(); oldCells.push_back(item->GetCell()); collectItems.push_back(item); } } if (totalSize - 3 >= INVENTORY_MAX_NUM) { ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT")); return; } std::vector<LPITEM>::iterator it = collectItems.begin(), end = collectItems.end(); for (; it != end; ++it) ((LPITEM)*it)->RemoveFromCharacter(); std::sort(collectItems.begin(), collectItems.end(), _sort); std::vector<LPITEM>::iterator it1 = collectItems.begin(), end1 = collectItems.end(); for (; it1 != end1; ++it1) { WORD cell = ch->GetEmptyInventory(((LPITEM)*it1)->GetSize()); ((LPITEM)*it1)->AddToCharacter(ch, TItemPos(INVENTORY, cell)/*, isNew=false*/); } } 2 Link to comment Share on other sites More sharing options...
thespeedy 20 Posted January 12, 2018 Share Posted January 12, 2018 vor 19 Minuten schrieb xP3NG3Rx: Here is the code for old compilers: struct s_sort { bool operator() (LPITEM src, LPITEM dst) { return (src->GetVnum()<dst->GetVnum()); } } _sort; ACMD(do_sort_inventory) { std::vector<LPITEM> collectItems; std::vector<WORD> oldCells; int totalSize = 0; for (WORD i = 0; i < INVENTORY_MAX_NUM; ++i) { LPITEM item = ch->GetInventoryItem(i); if (item) { totalSize += item->GetSize(); oldCells.push_back(item->GetCell()); collectItems.push_back(item); } } if (totalSize - 3 >= INVENTORY_MAX_NUM) { ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT")); return; } std::vector<LPITEM>::iterator it = collectItems.begin(), end = collectItems.end(); for (; it != end; ++it) ((LPITEM)*it)->RemoveFromCharacter(); std::sort(collectItems.begin(), collectItems.end(), _sort); std::vector<LPITEM>::iterator it1 = collectItems.begin(), end1 = collectItems.end(); for (; it1 != end1; ++it1) { WORD cell = ch->GetEmptyInventory(((LPITEM)*it1)->GetSize()); ((LPITEM)*it1)->AddToCharacter(ch, TItemPos(INVENTORY, cell)/*, isNew=false*/); } } with auto stack or not? <3 1 Link to comment Share on other sites More sharing options...
notbugme 14 Posted January 13, 2018 Author Share Posted January 13, 2018 (edited) Thanks for help, xP3NG3Rx <3 Works, very nice. One more time thanks!! Spoiler Edited September 3, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
thespeedy 20 Posted January 13, 2018 Share Posted January 13, 2018 (edited) vor 33 Minuten schrieb notbugme: Thanks for help, xP3NG3Rx <3 Works, very nice. One more time thanks!! how to cmd.cpp? and can anyone add stack? i have 4x 30pots and make 1x 120 pots? Spoiler Edited September 3, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Kingsman 9 Posted January 13, 2018 Share Posted January 13, 2018 if (totalSize - 3 >= INVENTORY_MAX_NUM) { ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT")); return; } This function don't work for me. I have 5 inventory.Can help me? Thank! Link to comment Share on other sites More sharing options...
thespeedy 20 Posted February 4, 2018 Share Posted February 4, 2018 Am 13.1.2018 um 01:35 schrieb thespeedy: how to cmd.cpp? and can anyone add stack? i have 4x 30pots and make 1x 120 pots? push no stack items Link to comment Share on other sites More sharing options...
Premium North 1172 Posted February 5, 2018 Premium Share Posted February 5, 2018 On 2/4/2018 at 10:26 AM, thespeedy said: push no stack items fuck off Link to comment Share on other sites More sharing options...
thespeedy 20 Posted February 5, 2018 Share Posted February 5, 2018 vor 7 Minuten schrieb Fleon: fuck off kid... 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