• 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++ - TFS 1.0] Health/Mana Change

Aleada

Unknown Member
Joined
Mar 14, 2013
Messages
231
Reaction score
7
I'm sorry if this sounds very noobish to some but I honestly can not figure out how to add "+" and "-" to damage/healing effects. For example, if you get hit for 24 hitpoints it will say "-24"... Here's what I've written so far but it doesn't work :/

game.cpp
Code:
...
TextMessagemessage;
message.position=targetPos;
message.primary.value=realHealthChange;
message.primary.color=TEXTCOLOR_MAYABLUE;
message.sign="+";
...
message.primary.value=manaDamage;
message.primary.color=TEXTCOLOR_BLUE;
message.sign="-";
...
message.primary.value=damage;
message.sign="-";
addMagicEffect(list,targetPos,hitEffect);
...

protocolgame.cpp
Code:
voidProtocolGame::sendTextMessage(constTextMessage&message)
{
NetworkMessagemsg;
msg.AddByte(0xB4);
msg.AddByte(message.type);
switch(message.type){
caseMESSAGE_DAMAGE_DEALT:
caseMESSAGE_DAMAGE_RECEIVED:
caseMESSAGE_DAMAGE_OTHERS:{
msg.AddPosition(message.position);
msg.add<uint32_t>(message.primary.value);
msg.AddByte(message.primary.color);
msg.add<uint32_t>(message.secondary.value);
msg.AddByte(message.secondary.color);
break;
}
caseMESSAGE_HEALED:
caseMESSAGE_HEALED_OTHERS:
caseMESSAGE_EXPERIENCE:
caseMESSAGE_EXPERIENCE_OTHERS:{
msg.AddPosition(message.position);
msg.add<uint32_t>(message.primary.value);
msg.AddByte(message.primary.color);
break;
}
default:{
break;
}
}
msg.AddString(message.text);
msg.AddString(message.sign);
writeToOutputBuffer(msg);
}

protocolgame.h
Code:
structTextMessage
{
MessageClassestype;
std::stringtext;
std::stringsign;
Positionposition;
struct{
int32_tvalue;
TextColor_tcolor;
}primary,secondary;
TextMessage()
{
primary.value=0;
secondary.value=0;
}
};
 
Thanks Nikolai for tagging a well known person :)

I'm just trying to learn C++ :p I would be grateful if someone would help lead me in the right direction.. whether I'm not even looking at the correct part in the sources or if I'm just completely messing it up lmfao
 
edit: nvm just taken a look at sources of 1.0 seems a bit harder to do then I guessed first, will try to make a way around for you guys.
 
Last edited:
does it even show an animated text right now, I mean does it pop the numbers once you heal / got attacked or nothing at all?
 
It shows how much you are healed for/damaged for but I just can't track down where it's coming from :/
 
try:
Code:
message.primary.value = realHealthChange;
change it to:
Code:
message.primary.value = "+" += realHealthChange;

not sure if it works but let's give it a shot :)
 
Nope :/
Code:
1 IntelliSense: expression must be a modifiable lvalue

I was trying this earlier:
Code:
message.primary.value="+"+realHealthChange;

But you can't combine a string/char with a int :/
 
I'm not that much of a pro in c++ but let's try to convert it then
Code:
std::ostringstream test;
       test << realHealthChange;
       message.primary.value = "+"+test.str();;
not sure if it works tho.
 
Last edited:
Unless if I completely messed it up, it doesn't work :(
This is what I put:
Code:
message.position=targetPos;
std::ostringstreamtest;
test<<realHealthChange;
test.str();
message.primary.value="+"+test;
message.primary.color=TEXTCOLOR_MAYABLUE;

This is the error:
Code:
 1 IntelliSense: no operator "+" matches these operands
  operand types are: const char [2] + std::ostringstream
 
just beeing curious now test this:
Code:
message.primary.value="+-100";
I just wanna see if the message output can even handle anything else then int.
 
Nope that's why you can't really convert it to string either... Unless you change wherever it's sending to to accept strings :/

Code:
 1 IntelliSense: a value of type "const char *" cannot be assigned to an entity of type "int32_t"
 
that makes it rather difficult this way.
you could rebuild the function so it works with string not with int but that would require tons of changes
I mean like:
player.h
Code:
void sendTextMessage(MessageClasses mclass, const std::string& message, Position* pos = nullptr, uint32_t value = 0, TextColor_t color = TEXTCOLOR_NONE) const {
       if (client) {
         client->sendTextMessage(mclass, message, pos, value, color);
       }
     }
to:
Code:
void sendTextMessage(MessageClasses mclass, const std::string& message, Position* pos = nullptr, const std::string& value, TextColor_t color = TEXTCOLOR_NONE) const {
       if (client) {
         client->sendTextMessage(mclass, message, pos, value, color);
       }
     }

and this stuff:
Code:
void ProtocolGame::sendTextMessage(MessageClasses mclass, const std::string& message, Position* pos/* = nullptr*/, const std::string& value/* = 0*/, TextColor_t color/* = TEXTCOLOR_NONE*/)
{
   NetworkMessage msg;
   if (pos != nullptr && (mclass == MESSAGE_DAMAGE_DEALT || mclass == MESSAGE_DAMAGE_RECEIVED || mclass == MESSAGE_HEALED || mclass == MESSAGE_EXPERIENCE || mclass == MESSAGE_DAMAGE_OTHERS || mclass == MESSAGE_HEALED_OTHERS || mclass == MESSAGE_EXPERIENCE_OTHERS)) {
     msg.AddByte(0xB4);
     msg.AddByte(mclass);
     msg.AddPosition(*pos);
     msg.addString(value);
     msg.AddByte(color);
     msg.AddString(message);
   } else {
     msg.AddByte(0xB4);
     msg.AddByte(mclass);
     msg.AddString(message);
   }

   writeToOutputBuffer(msg);
}

void ProtocolGame::sendTextMessage(const TextMessage& message)
{
   NetworkMessage msg;
   msg.AddByte(0xB4);
   msg.AddByte(message.type);
   switch (message.type) {
     case MESSAGE_DAMAGE_DEALT:
     case MESSAGE_DAMAGE_RECEIVED:
     case MESSAGE_DAMAGE_OTHERS: {
       msg.AddPosition(message.position);
       msg.addString(message.primary.value);
       msg.AddByte(message.primary.color);
       msg.addString(message.secondary.value);
       msg.AddByte(message.secondary.color);
       break;
     }
     case MESSAGE_HEALED:
     case MESSAGE_HEALED_OTHERS:
     case MESSAGE_EXPERIENCE:
     case MESSAGE_EXPERIENCE_OTHERS: {
       msg.AddPosition(message.position);
       msg.addString(message.primary.value);
       msg.AddByte(message.primary.color);
       break;
     }
     default: {
       break;
     }
   }
   msg.AddString(message.text);
   writeToOutputBuffer(msg);
}
 
Last edited:
unless you downgraded your client server for any client version lower than 9.1, its not possible because of client limitations (I may be right, or may not lol)
 
Back
Top