• 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!

C++ How to Print in Console

CastorFlynn

Member
Joined
Aug 29, 2021
Messages
88
Reaction score
8
I would like to click on the corpse and then return who owns it, because I have a bug on reward system and I want to know who are stealing the kill.

C++:
        uint32_t corpseOwner = container->getCorpseOwner();
        if (container->isRewardCorpse()) {
            //only players who participated in the fight can open the corpse
            if (player->getGroup()->id >= 4 || player->getAccountType() >= 3) {
                return RETURNVALUE_YOUCANTOPENCORPSEADM;
            }
            if (!player->getReward(container->getIntAttr(ITEM_ATTRIBUTE_DATE), false)) {
                return RETURNVALUE_YOUARENOTTHEOWNER;
            }
        } else if (corpseOwner != 0 && !player->canOpenCorpse(corpseOwner)) {
            return RETURNVALUE_YOUARENOTTHEOWNER;
        }
 
if you want to get the name of the creature, add this code below line 1
C++:
std::cout << g_game.getCreatureByID(corpseOwner)->getName() << std::endl;
 
if you want to get the name of the creature, add this code below line 1
C++:
std::cout << g_game.getCreatureByID(corpseOwner)->getName() << std::endl;
TFS crash when login.
std::cout << corpseOwner << std::endl;
This print a big number in console, but unfortunately that didn't help me to find the owner of the loot, since all corpses, even the ones that say I don't own it, print the same number.
2147483647

Thank you guys anyway
 
Last edited:
ok i'm no expert but this seem to work for me atleast, it prints the name in console. using tfs 1.5
C++:
uint32_t corpseOwner = container->getCorpseOwner();
if (corpseOwner != 0) {
    Creature* ownerName = g_game.getCreatureByID(corpseOwner);
    if (ownerName) {
        std::cout << ownerName->getName() << std::endl;
    }
}
 
ok i'm no expert but this seem to work for me atleast, it prints the name in console. using tfs 1.5
C++:
uint32_t corpseOwner = container->getCorpseOwner();
if (corpseOwner != 0) {
    Creature* ownerName = g_game.getCreatureByID(corpseOwner);
    if (ownerName) {
        std::cout << ownerName->getName() << std::endl;
    }
}
Dont crash now, but don't print. Maybe I put this on a wrong way?

C++:
        uint32_t corpseOwner = container->getCorpseOwner();       
        if (corpseOwner != 0) {
            Creature* ownerName = g_game.getCreatureByID(corpseOwner);
                if (ownerName) {
                std::cout << ownerName->getName() << std::endl;
            }
        }
        if (container->isRewardCorpse()) {
            //only players who participated in the fight can open the corpse
            if (player->getGroup()->id >= 4 || player->getAccountType() >= 3) {
                return RETURNVALUE_YOUCANTOPENCORPSEADM;
            }
            if (!player->getReward(container->getIntAttr(ITEM_ATTRIBUTE_DATE), false)) {
                return RETURNVALUE_YOUARENOTTHEOWNER;
            }
        } else if (corpseOwner != 0 && !player->canOpenCorpse(corpseOwner)) {
            return RETURNVALUE_YOUARENOTTHEOWNER;
        }
 
Try this see what prints
C++:
uint32_t corpseOwner = container->getCorpseOwner();       
        if (corpseOwner != 0) {
            Creature* owner = g_game.getCreatureByID(corpseOwner);
            std::cout << "Corpse has an owner. Getting Owner Name..." << std::endl;
                if (owner) {
                std::cout << "[Name]: " << owner->getName() << std::endl;
            }
        }
        if (container->isRewardCorpse()) {
            //only players who participated in the fight can open the corpse
            if (player->getGroup()->id >= 4 || player->getAccountType() >= 3) {
                return RETURNVALUE_YOUCANTOPENCORPSEADM;
            }
            if (!player->getReward(container->getIntAttr(ITEM_ATTRIBUTE_DATE), false)) {
                return RETURNVALUE_YOUARENOTTHEOWNER;
            }
        } else if (corpseOwner != 0 && !player->canOpenCorpse(corpseOwner)) {
            return RETURNVALUE_YOUARENOTTHEOWNER;
        }
 
Try this see what prints
C++:
uint32_t corpseOwner = container->getCorpseOwner();      
        if (corpseOwner != 0) {
            Creature* owner = g_game.getCreatureByID(corpseOwner);
            std::cout << "Corpse has an owner. Getting Owner Name..." << std::endl;
                if (owner) {
                std::cout << "[Name]: " << owner->getName() << std::endl;
            }
        }
        if (container->isRewardCorpse()) {
            //only players who participated in the fight can open the corpse
            if (player->getGroup()->id >= 4 || player->getAccountType() >= 3) {
                return RETURNVALUE_YOUCANTOPENCORPSEADM;
            }
            if (!player->getReward(container->getIntAttr(ITEM_ATTRIBUTE_DATE), false)) {
                return RETURNVALUE_YOUARENOTTHEOWNER;
            }
        } else if (corpseOwner != 0 && !player->canOpenCorpse(corpseOwner)) {
            return RETURNVALUE_YOUARENOTTHEOWNER;
        }
Print this:
1662309616076.png
 
Back
Top