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

HP/MANA in % tfs 1.2+! HELP with the code

Edroniasty

New Member
Joined
Oct 2, 2015
Messages
84
Reaction score
1
Hello! I wanted to compile my tfs 1.2 so that my HP/MANA bar displays in a percents not amount like 4200 HP/ 1000 Mana must be like 100 HP/100 MP, I am looking for help here:
https://otland.net/threads/jak-wysylac-hp-i-mane-w-procentach.181560/

but my protocolgame.cpp lines are different:

Code:
    msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(std::min<int32_t>(player->getPlayerInfo(PLAYERINFO_MAXHEALTH), std::numeric_limits<uint16_t>::max()));

instead like in tutorial:

Code:
    msg->put<uint16_t>(player->getHealth());
    msg->put<uint16_t>(player->getPlayerInfo(PLAYERINFO_MAXHEALTH));

how to solve it? what is the working code for tfs 1.2+?

( sorry for my bad English) rep++ for help!
 
Try:

Code:
if (player->getPlayerInfo(PLAYERINFO_MAXHEALTH) > 0) {
    msg.add<uint16_t>(player->getHealth() * 100 / player->getPlayerInfo(PLAYERINFO_MAXHEALTH));
    msg.add<uint16_t>(100);
} else {
    msg.add<uint16_t>(0);
    msg.add<uint16_t>(0);
}
 
Last edited:
I changed it but I have errors:
1>..\src\protocolgame.cpp(2838): error C2146: syntax error: missing ';' before identifier 'msg'
1>..\src\protocolgame.cpp(2839): error C2181: illegal else without matching if
1>..\src\protocolgame.cpp(2844): error C2065: 'end': undeclared identifier
1>..\src\protocolgame.cpp(2844): error C2146: syntax error: missing ';' before identifier 'msg'
1>..\src\protocolgame.cpp(2855): error C2146: syntax error: missing ';' before identifier 'msg'
1>..\src\protocolgame.cpp(2856): error C2181: illegal else without matching if
1>..\src\protocolgame.cpp(2861): error C2065: 'end': undeclared identifier
1>..\src\protocolgame.cpp(2861): error C2146: syntax error: missing ';' before identifier 'msg'
 
This don't work for me... @Printer

I have replace this

Code:
msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));

 msg.add<uint16_t>(std::min<int32_t>(player->getPlayerInfo(PLAYERINFO_MAXHEALTH), std::numeric_limits<uint16_t>::max()));

To this

Code:
if (player->getPlayerInfo(PLAYERINFO_MAXHEALTH) > 0) {
    msg.add<uint16_t>(player->getHealth() * 100 / player->getPlayerInfo(PLAYERINFO_MAXHEALTH));
    msg.add<uint16_t>(100);
} else {
    msg.add<uint16_t>(0);
    msg.add<uint16_t>(0);
}

Have i done it wrong or what?
 
Back
Top