• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

How see the table on C++

login12

void newbie scripter()
Joined
Feb 26, 2011
Messages
164
Reaction score
24
Location
Brazil
Yo.
I have returned to studying C ++ and I am developing a auto-loot system for 1.3 as a form of study.
But I have a doubt. Well, when I try to check which items are inside the container (body), it returns me a table, probably with the informations of items inside, but I don't know how to handle them in C ++.

Funcion used:

C++:
            if (player->canOpenCorpse(corpseOwner)) {
                std::cout << "List of Items: " << container->getItem() << std::endl;
            }

Someone know how i can do that?
 
Solution
Sorry, that's the wrong function, it should be:
C++:
for (Item* item : container->getItemList()) {
    std::cout << item->getName() << '\n';
}
The container (std::deque) holds pointers to Item objects, so when you iterate it, you need to use the same type for the loop variable.
C++:
for (Item* item : container->getItems()) {
    std::cout << item->getName() << '\n';
}

Can u explain why u use Item* item to reference?
I think I know why, but need certain
Thanks for reply btw<3

I got error on compile check that:

C++:
/home/forgottenserver/src/actions.cpp: In member function ‘ReturnValue Actions::internalUseItem(Player*, const Position&, uint8_t, Item*, bool)’:
/home/forgottenserver/src/actions.cpp:386:34: error: ‘class Container’ has no member named ‘getItem ’
     for (Item* item : container->getItems()) {
                                  ^
CMakeFiles/tfs.dir/build.make:101: recipe for target 'CMakeFiles/tfs.dir/src/actions.cpp.o' failed
 
Sorry, that's the wrong function, it should be:
C++:
for (Item* item : container->getItemList()) {
    std::cout << item->getName() << '\n';
}
The container (std::deque) holds pointers to Item objects, so when you iterate it, you need to use the same type for the loop variable.
 
Solution
Back
Top