• 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++ How to fetch leech amount?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
177
Location
Sweden
C++:
                if (casterPlayer->getHealth() < casterPlayer->getMaxHealth()) {
                    uint16_t chance = casterPlayer->getSpecialSkill(SPECIALSKILL_LIFELEECHCHANCE);
                    uint16_t skill = casterPlayer->getSpecialSkill(SPECIALSKILL_LIFELEECHAMOUNT);
                    if (chance > 0 && skill > 0 && normal_random(1, 100) <= chance) {
                        leechCombat.primary.value = std::round(totalDamage * (skill / 100.));
                        g_game.combatChangeHealth(nullptr, casterPlayer, leechCombat);
                        casterPlayer->sendMagicEffect(casterPlayer->getPosition(), CONST_ME_MAGIC_RED);
                        casterPlayer->sendAnimatedText("hej", casterPlayer->getPosition(), TEXTCOLOR_BLUE);
                    }
                }


Instead of "hej" how do i fetch the leech amount? In Lua you use: fetchleech = "100" sendmsg ".. fetchLeech ..", how do you do in c++?
 
Could this be what you're asking for 🤔
C++:
casterPlayer->sendAnimatedText(leechCombat.primary.value, casterPlayer->getPosition(), TEXTCOLOR_BLUE);
 
Could this be what you're asking for 🤔
C++:
casterPlayer->sendAnimatedText(leechCombat.primary.value, casterPlayer->getPosition(), TEXTCOLOR_BLUE);
Tried it but it returned errors when compiling.



Code:
1>------ Build started: Project: theforgottenserver, Configuration: Release x64 ------
1>combat.cpp
1>C:\forgottenserver-master\src\combat.cpp(871,108): error C2664: 'void Player::sendAnimatedText(const std::string &,const Position &,TextColor_t)': cannot convert argument 1 from 'int32_t' to 'const std::string &'
1>C:\forgottenserver-master\src\combat.cpp(871,108): message : Reason: cannot convert from 'int32_t' to 'const std::string'
1>C:\forgottenserver-master\src\combat.cpp(871,108): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\forgottenserver-master\src\player.h(827,8): message : see declaration of 'Player::sendAnimatedText'
1>C:\forgottenserver-master\src\combat.cpp(882,108): error C2664: 'void Player::sendAnimatedText(const std::string &,const Position &,TextColor_t)': cannot convert argument 1 from 'int32_t' to 'const std::string &'
1>C:\forgottenserver-master\src\combat.cpp(882,108): message : Reason: cannot convert from 'int32_t' to 'const std::string'
1>C:\forgottenserver-master\src\combat.cpp(882,108): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\forgottenserver-master\src\player.h(827,8): message : see declaration of 'Player::sendAnimatedText'
1>C:\forgottenserver-master\src\combat.cpp(1039,108): error C2664: 'void Player::sendAnimatedText(const std::string &,const Position &,TextColor_t)': cannot convert argument 1 from 'int32_t' to 'const std::string &'
1>C:\forgottenserver-master\src\combat.cpp(1039,108): message : Reason: cannot convert from 'int32_t' to 'const std::string'
1>C:\forgottenserver-master\src\combat.cpp(1039,108): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\forgottenserver-master\src\player.h(827,8): message : see declaration of 'Player::sendAnimatedText'
1>C:\forgottenserver-master\src\combat.cpp(1050,108): error C2664: 'void Player::sendAnimatedText(const std::string &,const Position &,TextColor_t)': cannot convert argument 1 from 'int32_t' to 'const std::string &'
1>C:\forgottenserver-master\src\combat.cpp(1050,108): message : Reason: cannot convert from 'int32_t' to 'const std::string'
1>C:\forgottenserver-master\src\combat.cpp(1050,108): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\forgottenserver-master\src\player.h(827,8): message : see declaration of 'Player::sendAnimatedText'
1>Done building project "theforgottenserver.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 
Try this
C++:
casterPlayer->sendAnimatedText(std::to_string(leechCombat.primary.value), casterPlayer->getPosition(), TEXTCOLOR_BLUE);
Nice that worked, so its std::to_string you use, how do i do if i want like: Hej: leechCombat.primary.value

Edit: is it possible to set the max skill of leech in there aswell?
 
Last edited:
Nice that worked, so its std::to_string you use, how do i do if i want like: Hej: leechCombat.primary.value

C++:
std::string leechDmg = "Text: " + std::to_string(leechCombat.primary.value);
casterPlayer->sendAnimatedText(leechDmg, casterPlayer->getPosition(), TEXTCOLOR_BLUE);

Edit: is it possible to set the max skill of leech in there aswell?
Not sure I understand this part 🤔
 
C++:
std::string leechDmg = "Text: " + std::to_string(leechCombat.primary.value);
casterPlayer->sendAnimatedText(leechDmg, casterPlayer->getPosition(), TEXTCOLOR_BLUE);


Not sure I understand this part 🤔
Thank you so much!
Now the max skill of leech in game is 100%, can i reduce that to 50% in the sources somewhere?

Edit: Also, i did see your post about gdb, any possiblities you would like to help with this topic aswell: Linux - Compiling with -g? (https://otland.net/threads/compiling-with-g.275606/)
 
I don't get it. Wym its 100%?

Are you trying to reduce this by 50%?
C++:
uint16_t skill = casterPlayer->getSpecialSkill(SPECIALSKILL_LIFELEECHAMOUNT);
I'd want to set this one to a max, is it something i can do in sources or is it client sided?
this.png
 
I'd want to set this one to a max, is it something i can do in sources or is it client sided?
View attachment 57115

Amount depends on items you're wearing.

The maximum amount sent to the client is 100
 
Amount depends on items you're wearing.

The maximum amount sent to the client is 100
Thank you so much for all help!


Last question if you bother, do you know why i cant start my server with gdb? (using ubuntu) It says config is missing but the tfs directory is the same as before.
 
Back
Top