• 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++ Sending custom attributes to client

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,421
Solutions
68
Reaction score
1,074
How can I do this?

This is what I have so far

Server Side: void NetworkMessage::addItem(const Item* item)
C++:
// Send custom attributes to client.
Item* tmpItem = item->clone();
add<uint16_t>(CUSTOM_ATTR_LAST - 1); // Send size of custom attributes

for (uint16_t key = CUSTOM_ATTR_RARITY; key < CUSTOM_ATTR_LAST; key++) {
    add<uint16_t>(key); // Send key
    add<uint64_t>(0); // Send default value
}
delete tmpItem;

Client Side: ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id, bool hasDescription)
C++:
if (g_game.getFeature(Otc::GameItemCustomAttributes)) {
    uint16 size = msg->getU16();
    for (uint16 i = 0; i < size; ++i) {
        uint16 key = msg->getU16();
        int64 value = msg->getI64();
        item->setCustomAttribute(key, value);
    }
}

When I call getCustomAttribute(key) client side it shows the -1 value for all of them. I just need to know how to get an items custom attribute value.
 
Last edited:
I know I am close to getting this because I can std::cout << attr->value and get the correct value for my custom attribute on the item. For some reason I cannot for the life of me get the value out of it when sending it to the client though. I can't just use attr->value.. I tried to copy how the value is checked in item.cpp but even that does nothing. I know the value stored inside is an int so this should work for it.
Post automatically merged:

SOLVED

1726800559902.webp
 
Last edited:
You can always send info about new / custom info by protocolgame.cpp from server side and receive it by client side, thats easier than reading custom attributes, anyway congratulations that you solved your problem!
 
You can always send info about new / custom info by protocolgame.cpp from server side and receive it by client side, thats easier than reading custom attributes, anyway congratulations that you solved your problem!
Yeah I just didn't want to have to recode a bunch of stuff. The client was already set up to handle all the information and use it as I want too but the server wasn't. Now it is and I can utilize all the functionality the client already came with. Thanks for the congrats. It is a key thing to have working for my game seems the client needs to be able to display item information in multiple places without making constant calls to the server to get it which of course means better performance for the player even if just a small amount.
 
Back
Top