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

Feature [0.4] All heal / damage in percentage

Amiroslo

Excellent OT User
Joined
Jul 28, 2009
Messages
6,767
Solutions
5
Reaction score
769
Hello,
I was looking around and saw this thread, and the idea for a high exp server seemed pretty wonderful, but I couldn't find it released anywhere, so I got some help, and we made things work! So I'd want to share this with anyone else who would like to have this implemented on their server!

What is this?
This will change every healing (runes, potions, spells etc) and every damage (melee, spells etc) to a percentage looking
Example:
image.png
riL34U1.png


Open your game.cpp

Replace
Code:
sprintf(buffer, "+%d", healthChange);
with
Code:
int percentHealthChange = (int) round(healthChange / (target->getMaxHealth() / 100));
sprintf(buffer, "+%d%%", percentHealthChange);

replace
Code:
sprintf(buffer, "%d", manaDamage);
with
Code:
int percentManaChange = (int) round(manaDamage / (target->getMaxMana() / 100.));
sprintf(buffer, "%d%%", percentManaChange);

replace
Code:
sprintf(buffer, "%d", damage);
with
Code:
int percentHealthChange2 = (int) round(damage / (target->getMaxHealth() / 100.));
sprintf(buffer, "%d%%", percentHealthChange2);

replace
Code:
sprintf(buffer, "+%d", manaChange);
with
Code:
int percentManaChange2 = (int) round(manaChange / (target->getMaxMana() / 100.));
sprintf(buffer, "+%d%%", percentManaChange2);

and replace
Code:
sprintf(buffer, "%d", manaLoss);
with
Code:
int percentManaChange3 = (int) round(manaLoss / (target->getMaxMana() / 100.));
sprintf(buffer, "%d%%", percentManaChange3);

Shoutout to Carcoo & GPedro for making it happen
 
int percentManaChange2 = (int) round(getMaxMana( / (target->manaChangegetMaxMana() / 100.));
 
what is this error?

C++:
game.cpp: In member function ‘bool Game::combatChangeHealth(const CombatParams&, Creature*, Creature*, int32_t, bool)’:
game.cpp:4864:81: error: call of overloaded ‘round(int32_t)’ is ambiguous
    int percentHealthChange = round(healthChange / (target->getMaxHealth() / 100));
                                                                                 ^
done.
solution on TFS 0.3.6
C++:
            int32_t percentHealthChange = (int32_t) (healthChange / (target->getMaxHealth() / 100));
            sprintf(buffer, "+%d%%", percentHealthChange);
 
Last edited:
Hello,
I was looking around and saw this thread, and the idea for a high exp server seemed pretty wonderful, but I couldn't find it released anywhere, so I got some help, and we made things work! So I'd want to share this with anyone else who would like to have this implemented on their server!

What is this?
This will change every healing (runes, potions, spells etc) and every damage (melee, spells etc) to a percentage looking
Example:
image.png
riL34U1.png


Open your game.cpp

Replace
Code:
sprintf(buffer, "+%d", healthChange);
with
Code:
int percentHealthChange = (int) round(healthChange / (target->getMaxHealth() / 100));
sprintf(buffer, "+%d%%", percentHealthChange);

replace
Code:
sprintf(buffer, "%d", manaDamage);
with
Code:
int percentManaChange = (int) round(manaDamage / (target->getMaxMana() / 100.));
sprintf(buffer, "%d%%", percentManaChange);

replace
Code:
sprintf(buffer, "%d", damage);
with
Code:
int percentHealthChange2 = (int) round(damage / (target->getMaxHealth() / 100.));
sprintf(buffer, "%d%%", percentHealthChange2);

replace
Code:
sprintf(buffer, "+%d", manaChange);
with
Code:
int percentManaChange2 = (int) round(manaChange / (target->getMaxMana() / 100.));
sprintf(buffer, "+%d%%", percentManaChange2);

and replace
Code:
sprintf(buffer, "%d", manaLoss);
with
Code:
int percentManaChange3 = (int) round(manaLoss / (target->getMaxMana() / 100.));
sprintf(buffer, "%d%%", percentManaChange3);

Shoutout to Carcoo & GPedro for making it happen
could you put it to be equal to the quoted topic?
damage per 'k' : 2k/50k/100k ...
 
Can you share this code here, please??
I modified OTCv8 to do this, mine shows M for millions as well.

Firstly add this function into:
src/client/protocolgameparse.cpp
C++:
std::string formatNumberText(uint value)
{
    if (value > 1000000) {
        return stdext::format("%.1fM", value / 1000000.0);
    }
    else if (value > 1000) {
        return stdext::format("%.1fK", value / 1000.0);
    } else {
        return stdext::to_string(value);
    }
}

Then in the same file add the formatNumberText there, make sure to change only the line below:
animatedText->setText(formatNumberText(value));
C++:
case Otc::MessageDamageOthers:
    {
        Position pos = getPosition(msg);
        uint value[2];
        int color[2];
        // physical damage
        value[0] = msg->getU32();
        color[0] = msg->getU8();
        // magic damage
        value[1] = msg->getU32();
        color[1] = msg->getU8();
        if(g_game.getFeature(Otc::GameAnimatedTextCustomFont))
            font = msg->getString();
        text = msg->getString();
        for (int i = 0; i < 2; ++i) {
            if (value[i] == 0)
                continue;
            AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
            animatedText->setColor(color[i]);
            animatedText->setText(stdext::to_string(value[i]));
            animatedText->setText(formatNumberText(value[i]));
            if (font.size())
                animatedText->setFont(font);

            g_map.addThing(animatedText, pos);
        }
        break;
    }
 
Last edited:
Back
Top