• 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++ [C++/Lua] Percentage level range for pvp-enforced exp instead of flat level range

Silba

is stephany, the josh wife
Joined
Aug 22, 2013
Messages
458
Solutions
9
Reaction score
386
Hello I would like to modify the source code or create a script which will allow me to set the level range for pvp-enforced experience to be based on a percentage rather than the normal level range which never changes.

Right now in config.lua I have expFromPlayersLevelRange = 80 and this is very limited and pretty much useless if players can reach high levels such as 1k+. Set it high and low level pvp is weird, set it low and high level pvp is weird, there's no way to make this work well for high level players and low level players.
The source code is:
C++:
{
    if (g_config.getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) {
        Player* attackerPlayer = attacker->getPlayer();
        if (attackerPlayer && attackerPlayer != this && skillLoss && std::abs(static_cast<int32_t>(attackerPlayer->getLevel() - level)) <= g_config.getNumber(ConfigManager::EXP_FROM_PLAYERS_LEVEL_RANGE)) {
            return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75));
        }
    }
    return 0;
}

I pretty much die inside looking at source code, could someone help me with modifying the source to make expFromPlayersLevelRange represent the percentage difference instead?
Otherwise an lua script would be ideal but a problem I ran in to looking at scripts I found on the forum was making sure everyone who attacks the players gets some experience proportionate to their damage dealt. Way too complicated for me.

For example expFromPlayersLevelRange = 15 would mean a player level 200 would get exp if he killed a player 30 levels above(230) or below(170) him. 15% difference and not a flat 15 level difference.

Any help is appreciated, thank you :)
 
Solution
pls help me

Try this
C++:
uint64_t Player::getGainedExperience(Creature* attacker) const
{
    if (g_config.getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) {
        Player* attackerPlayer = attacker->getPlayer();
        if (attackerPlayer && attackerPlayer != this && skillLoss) {
            uint32_t attackerLevel = attackerPlayer->getLevel();
            uint32_t range = ((uint32_t)std::floor(attackerLevel * 15 / 100)); // just make the '15' value configurable
            if (level < (attackerLevel - range) || level > (attackerLevel + range))
                return 0;

            return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75));
        }
    }
    return 0;
}
pls help me

Try this
C++:
uint64_t Player::getGainedExperience(Creature* attacker) const
{
    if (g_config.getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) {
        Player* attackerPlayer = attacker->getPlayer();
        if (attackerPlayer && attackerPlayer != this && skillLoss) {
            uint32_t attackerLevel = attackerPlayer->getLevel();
            uint32_t range = ((uint32_t)std::floor(attackerLevel * 15 / 100)); // just make the '15' value configurable
            if (level < (attackerLevel - range) || level > (attackerLevel + range))
                return 0;

            return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75));
        }
    }
    return 0;
}
 
Solution
Try this
C++:
uint64_t Player::getGainedExperience(Creature* attacker) const
{
    if (g_config.getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) {
        Player* attackerPlayer = attacker->getPlayer();
        if (attackerPlayer && attackerPlayer != this && skillLoss) {
            uint32_t attackerLevel = attackerPlayer->getLevel();
            uint32_t range = ((uint32_t)std::floor(attackerLevel * 15 / 100)); // just make the '15' value configurable
            if (level < (attackerLevel - range) || level > (attackerLevel + range))
                return 0;

            return std::max<uint64_t>(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75));
        }
    }
    return 0;
}
Seems to work from my initial testing, thanks a lot :)
 
Back
Top