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

[Solved] [C++] Fooling around with creatureHide()

Tufte

Member
Joined
Nov 19, 2007
Messages
652
Reaction score
24
Location
Norway
So I've made a lua function that hides a player, but when he does this, all his summons disapears. How can I make so that the summons of a hidden player can still see the player? I have a table of the hidden players summons in the code that hides the player, but I dont know if its possible to make these summons still see the player. Here's the code:
Code:
void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bool known, uint32_t remove)
{
    CreatureType_t creatureType = creature->getType();

    const Player* otherPlayer = creature->getPlayer();

    if (known) {
        msg.add<uint16_t>(0x62);
        msg.add<uint32_t>(creature->getID());
    } else {
        msg.add<uint16_t>(0x61);
        msg.add<uint32_t>(remove);
        msg.add<uint32_t>(creature->getID());
        msg.AddByte(creatureType);
        msg.AddString(creature->getName());
    }

    if (creature->isHealthHidden()) {
        for (Creature* summon : creature->getSummons()) {
            std::cout << "Name " << summon->getName() << std::endl;
// DO SOMETHING WITH SUMMONS SO THAT THEY CAN SEE MASTER

        }

        msg.AddByte(0x00);
    } else {
        msg.AddByte((int32_t)std::ceil(((float)creature->getHealth()) * 100 / std::max<int32_t>(creature->getMaxHealth(), 1)));
    }
 
My problem is, when you use hideHealth, it follows many steps that eventially goes here: AddCreatureHealth in protocolcame, and checks if the player is hidden.
Code:
void ProtocolGame::AddCreatureHealth(NetworkMessage& msg, const Creature* creature)
{
    msg.AddByte(0x8C);
    msg.add<uint32_t>(creature->getID());

    if (creature->isHealthHidden()) {
        std::cout << "Name " << creature->getName() << std::endl;
        //msg.AddByte((int32_t)std::ceil(((float)creature->getHealth()) * 100 / std::max<int32_t>(creature->getMaxHealth(), 1)));
        msg.AddByte(0x00);
    } else {
        msg.AddByte((int32_t)std::ceil(((float)creature->getHealth()) * 100 / std::max<int32_t>(creature->getMaxHealth(), 1)));
    }
}

But this is not where the creature is actually hidden, because if you replace the byte 0x00 with the normal byte, it dosent make any difference. Where the health is actually hidden, is under AddCreature, but there when I use hideHealth from luascript/game or whatever, I cant see where AddCreature is involved, because its always using AddCreatureHealth

Code:
void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bool known, uint32_t remove)
{
    CreatureType_t creatureType = creature->getType();

    const Player* otherPlayer = creature->getPlayer();

    if (known) {
        msg.add<uint16_t>(0x62);
        msg.add<uint32_t>(creature->getID());
    } else {
        msg.add<uint16_t>(0x61);
        msg.add<uint32_t>(remove);
        msg.add<uint32_t>(creature->getID());
        msg.AddByte(creatureType);
        msg.AddString(creature->getName());
    }

    if (creature->isHealthHidden()) {

       
        msg.AddByte(0x00);
    } else {
        msg.AddByte((int32_t)std::ceil(((float)creature->getHealth()) * 100 / std::max<int32_t>(creature->getMaxHealth(), 1)));
    }
 
I've managed to not hide the health for my self by doing the following:
Code:
    if (creature->isHealthHidden() && creature != player) {
        msg.AddByte(0x00);
    } else {
        msg.AddByte((int32_t)std::ceil(((float)creature->getHealth()) * 100 / std::max<int32_t>(creature->getMaxHealth(), 1)));
    }

But, my summons still gets removed. However, if I summon monsters AFTER I've hidden myself, they will see me just fine.

I guess I could do it the bad way, and resummon the creatures after I set the hide in lua, but I would prefer to do it in source if anyone has any ideas.
 
Back
Top