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

Can someone adapt this code to 0.4?

demonrage

New Member
Joined
Oct 28, 2014
Messages
22
Reaction score
2
in this tutorial, the author teaches how to put damage/healing/exp, etc.. by %.. however I would like it to be by "kk" that is
damage = 1200 = 1.2k / 12500 = 12.5k etc..
thanks!

LINK:
 
I have zero knowledge of c++, but I generated this with chatgpt 4.0
You'll have to reference the other thread for the original section of code that requires replacing.

hope it works.

----------
To modify the code to display damage in "k" (thousand) and "kk" (million) instead of percentages, you can use the following changes:

Replace:

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

With:

Code:
char suffix[3] = "";
float healthChangeValue = healthChange / 1000.0f; // Divide by 1000 for 'k'
if (healthChange >= 1000000) {
  healthChangeValue = healthChange / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (healthChange >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "+%.2f%s", healthChangeValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float manaDamageValue = manaDamage / 1000.0f; // Divide by 1000 for 'k'
if (manaDamage >= 1000000) {
  manaDamageValue = manaDamage / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (manaDamage >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "%.2f%s", manaDamageValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float damageValue = damage / 1000.0f; // Divide by 1000 for 'k'
if (damage >= 1000000) {
  damageValue = damage / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (damage >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "%.2f%s", damageValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float manaChangeValue = manaChange / 1000.0f; // Divide by 1000 for 'k'
if (manaChange >= 1000000) {
  manaChangeValue = manaChange / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (manaChange >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "+%.2f%s", manaChangeValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float manaLossValue = manaLoss / 1000.0f; // Divide by 1000 for 'k'
if

 (manaLoss >= 1000000) {
  manaLossValue = manaLoss / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (manaLoss >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "%.2f%s", manaLossValue, suffix);

These changes will modify the code to display the damage values using "k" and "kk" as desired. The values will be rounded to two decimal places.
 
I have zero knowledge of c++, but I generated this with chatgpt 4.0
You'll have to reference the other thread for the original section of code that requires replacing.

hope it works.

----------
To modify the code to display damage in "k" (thousand) and "kk" (million) instead of percentages, you can use the following changes:

Replace:

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

With:

Code:
char suffix[3] = "";
float healthChangeValue = healthChange / 1000.0f; // Divide by 1000 for 'k'
if (healthChange >= 1000000) {
  healthChangeValue = healthChange / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (healthChange >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "+%.2f%s", healthChangeValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float manaDamageValue = manaDamage / 1000.0f; // Divide by 1000 for 'k'
if (manaDamage >= 1000000) {
  manaDamageValue = manaDamage / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (manaDamage >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "%.2f%s", manaDamageValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float damageValue = damage / 1000.0f; // Divide by 1000 for 'k'
if (damage >= 1000000) {
  damageValue = damage / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (damage >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "%.2f%s", damageValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float manaChangeValue = manaChange / 1000.0f; // Divide by 1000 for 'k'
if (manaChange >= 1000000) {
  manaChangeValue = manaChange / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (manaChange >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "+%.2f%s", manaChangeValue, suffix);

Replace:

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

With:

Code:
char suffix[3] = "";
float manaLossValue = manaLoss / 1000.0f; // Divide by 1000 for 'k'
if

 (manaLoss >= 1000000) {
  manaLossValue = manaLoss / 1000000.0f; // Divide by 1,000,000 for 'kk'
  strcpy(suffix, "kk");
}
else if (manaLoss >= 1000) {
  strcpy(suffix, "k");
}
sprintf(buffer, "%.2f%s", manaLossValue, suffix);

These changes will modify the code to display the damage values using "k" and "kk" as desired. The values will be rounded to two decimal places.
it worked perfectly thank you love you <3
Post automatically merged:

only the exp was not, but for me it's already solved.
 
Last edited:
Back
Top