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

Compiling rateExperienceFromPlayers same ip block.

DukeeH

Active Member
Joined
Dec 6, 2010
Messages
550
Solutions
3
Reaction score
39
I found this code on EvilHero's thread, it's for 0.4 but it's really old, and it's not working.
Code:
if(attackerPlayer->getIP() == getIP())
return 0;
I've put it into Player::getGainedExperience function.
Is there another way to deny exp from the same ip or a fix to this code?

Thanks.
 
Do you may provide the code including your changes?
Sure, thanks for your time.
Code:
double Player::getGainedExperience(Creature* attacker) const
{
    if(!skillLoss)
        return 0;

    double rate = g_config.getDouble(ConfigManager::RATE_PVP_EXPERIENCE);
    if(rate <= 0)
        return 0;

    Player* attackerPlayer = attacker->getPlayer();
    if(!attackerPlayer || attackerPlayer == this)
        return 0;
    if(attackerPlayer->getIP() == getIP())
        return 0;

    double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble(
        ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD);
    if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 &&
        level > (uint32_t)std::floor(attackerLevel * max)))
        return 0;

    /*
        Formula
        a = attackers level * 0.9
        b = victims level
        c = victims experience

        result = (1 - (a / b)) * 0.05 * c
        Not affected by special multipliers(!)
    */
    uint32_t a = (uint32_t)std::floor(attackerLevel * 0.9), b = level;
    uint64_t c = getExperience();
    return (double)std::max((uint64_t)0, (uint64_t)std::floor(getDamageRatio(attacker)
        * std::max((double)0, ((double)(1 - (((double)a / b))))) * 0.05 * c)) * rate;
}
 
Did you already try debugging and set breakpoints at attackerPalyer->getIP() and getIP() to see what these functions return?
 
You can do that using visual studio, another method is printing these values to the console.
Probably easier by printing since im using linux vm
How to make it print and what values? both ?
something like:
Code:
print (attackerPlayer->getIP())
print (getIP())
before the return 0; ?
 
Function is like this:
Code:
double Player::getGainedExperience(Creature* attacker) const
{
    if(!skillLoss)
        return 0;

    double rate = g_config.getDouble(ConfigManager::RATE_PVP_EXPERIENCE);
    if(rate <= 0)
        return 0;

    Player* attackerPlayer = attacker->getPlayer();
    if(!attackerPlayer || attackerPlayer == this)
        return 0;
    if(attackerPlayer->getIP() == getIP())
        std::cout << attackerPlayer->getIP() << std::endl;
        std::cout << getIP() << std::endl;
        return 0;

    double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble(
        ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD);
    if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 &&
        level > (uint32_t)std::floor(attackerLevel * max)))
        return 0;

    /*
        Formula
        a = attackers level * 0.9
        b = victims level
        c = victims experience

        result = (1 - (a / b)) * 0.05 * c
        Not affected by special multipliers(!)
    */
    uint32_t a = (uint32_t)std::floor(attackerLevel * 0.9), b = level;
    uint64_t c = getExperience();
    return (double)std::max((uint64_t)0, (uint64_t)std::floor(getDamageRatio(attacker)
        * std::max((double)0, ((double)(1 - (((double)a / b))))) * 0.05 * c)) * rate;
}

Console picture:
yOQzGW0.png

First two ips (83..) it's me with mc killing myself, no exp.
Third ip (83...) it's my friend killing me without mc, no exp.
Last two ips (14...) it's my friend killing himself with mc, no exp.
 
Last edited:
What you do in your script you call the ip of the attacking player and check if its the same as the ip of the actual player, which is also the attacking player

you must change your script to get the ip of the attacker/killer and the ip of the target/killed then compare the two

I mean your console also shows that; the third one who killed you is your friend you said, but he is shown with your ip / so the script must not have taken his ip, it has taken yours as the target
 
What you do in your script you call the ip of the attacking player and check if its the same as the ip of the actual player, which is also the attacking player

you must change your script to get the ip of the attacker/killer and the ip of the target/killed then compare the two

I mean your console also shows that; the third one who killed you is your friend you said, but he is shown with your ip / so the script must not have taken his ip, it has taken yours as the target
yes, it showed my ip when i died to my friend without mc, but instead of printing the ip twice like the other cases it just showed once.
 
double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble( ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD); if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 && level > (uint32_t)std::floor(attackerLevel * max))) return 0;
dont forget to test this part too
 
dont forget to test this part too
it's working fine the min and max threshold, the only problem is i want to disable same ip, guild and party exp to prevent free kills.
if it uses attackerLevel and level on the formula to get attacker and killed player level, it should be right to get ip with attackerPlayer->getIP() and getIP(), no?
 
Code:
double Player::getGainedExperience(Creature* attacker) const
{
    if(!skillLoss)
        return 0;

    double rate = g_config.getDouble(ConfigManager::RATE_PVP_EXPERIENCE);
    if(rate <= 0)
        return 0;

    Player* attackerPlayer = attacker->getPlayer();
    if(!attackerPlayer || attackerPlayer == this)
        return 0;
    if(attackerPlayer->getIP() == getIP())
        std::cout << "Same ip, no exp" << std::endl;
        return 0;

    double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble(
        ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD);
    if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 &&
        level > (uint32_t)std::floor(attackerLevel * max))){
std::cout << "You cant get xp from this player" << std::endl;       
return 0;
        }

    /*
        Formula
        a = attackers level * 0.9
        b = victims level
        c = victims experience

        result = (1 - (a / b)) * 0.05 * c
        Not affected by special multipliers(!)
    */
    std::cout << "If you can see me this is working, the problem is elsewhere" << std::endl;
    uint32_t a = (uint32_t)std::floor(attackerLevel * 0.9), b = level;
    uint64_t c = getExperience();
    return (double)std::max((uint64_t)0, (uint64_t)std::floor(getDamageRatio(attacker)
        * std::max((double)0, ((double)(1 - (((double)a / b))))) * 0.05 * c)) * rate;
}

if you want you can try to run this code.
then post the output here. It will be easy to debug.
 
Code:
double Player::getGainedExperience(Creature* attacker) const
{
    if(!skillLoss)
        return 0;

    double rate = g_config.getDouble(ConfigManager::RATE_PVP_EXPERIENCE);
    if(rate <= 0)
        return 0;

    Player* attackerPlayer = attacker->getPlayer();
    if(!attackerPlayer || attackerPlayer == this)
        return 0;
    if(attackerPlayer->getIP() == getIP())
        std::cout << "Same ip, no exp" << std::endl;
        return 0;

    double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble(
        ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD);
    if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 &&
        level > (uint32_t)std::floor(attackerLevel * max))){
std::cout << "You cant get xp from this player" << std::endl;     
return 0;
        }

    /*
        Formula
        a = attackers level * 0.9
        b = victims level
        c = victims experience

        result = (1 - (a / b)) * 0.05 * c
        Not affected by special multipliers(!)
    */
    std::cout << "If you can see me this is working, the problem is elsewhere" << std::endl;
    uint32_t a = (uint32_t)std::floor(attackerLevel * 0.9), b = level;
    uint64_t c = getExperience();
    return (double)std::max((uint64_t)0, (uint64_t)std::floor(getDamageRatio(attacker)
        * std::max((double)0, ((double)(1 - (((double)a / b))))) * 0.05 * c)) * rate;
}

if you want you can try to run this code.
then post the output here. It will be easy to debug.
sure, will do it the second i get home, i'm at work right now, thanks for your time!

edit;
using your function exactly like you posted...
same ip kill, console mensage: same ip no exp.
different ip kill, no console mensage, no exp.
different level (more or lower than threshold on config lua) no exp, no mensage.
it looks like the function breaks at some point.
 
Last edited:
I tested myself this version and it worked, just if anyone also wants. For tfs 0.3.7 or 0.4
it prevents the player from earning experience from a player in the same ip, guild, party or level restriction:
Code:
double Player::getGainedExperience(Creature* attacker) const
{
    if(!skillLoss){
        return 0;
    }

    double rate = g_config.getDouble(ConfigManager::RATE_PVP_EXPERIENCE);
    if(rate <= 0){
        return 0;
    }


    Player* attackerPlayer = attacker->getPlayer();
    if(!attackerPlayer || attackerPlayer == this){
        return 0;
    }
    if(attackerPlayer->getIP() == getIP()){
        return 0;
    }

    double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble(
        ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD);
    if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 &&
        level > (uint32_t)std::floor(attackerLevel * max))){
        return 0;
    }

    if(Party* party = this->getParty())
    {
        PlayerVector partyMembers = party->getMembers();
        PlayerVector::const_iterator it = partyMembers.begin();
        while(it != partyMembers.end())
        {
            if((*it) == attackerPlayer){
                return 0;
            }
            it++;
        }
    }

    if (this->getGuildId() && attackerPlayer->getGuildId() && attackerPlayer->getGuildId() == this->getGuildId()){
        return 0;
    }

    /*
        Formula
        a = attackers level * 0.9
        b = victims level
        c = victims experience

        result = (1 - (a / b)) * 0.05 * c
        Not affected by special multipliers(!)
    */
        uint32_t a = (uint32_t)std::floor(attackerLevel * 0.9), b = level;
        uint64_t c = getExperience();
        return (double)std::max((uint64_t)0, (uint64_t)std::floor(getDamageRatio(attacker)
            * std::max((double)0, ((double)(1 - (((double)a / b))))) * 0.05 * c)) * rate;
}
 
I tested myself this version and it worked, just if anyone also wants. For tfs 0.3.7 or 0.4
it prevents the player from earning experience from a player in the same ip, guild, party or level restriction:
Code:
double Player::getGainedExperience(Creature* attacker) const
{
    if(!skillLoss){
        return 0;
    }

    double rate = g_config.getDouble(ConfigManager::RATE_PVP_EXPERIENCE);
    if(rate <= 0){
        return 0;
    }


    Player* attackerPlayer = attacker->getPlayer();
    if(!attackerPlayer || attackerPlayer == this){
        return 0;
    }
    if(attackerPlayer->getIP() == getIP()){
        return 0;
    }

    double attackerLevel = (double)attackerPlayer->getLevel(), min = g_config.getDouble(
        ConfigManager::EFP_MIN_THRESHOLD), max = g_config.getDouble(ConfigManager::EFP_MAX_THRESHOLD);
    if((min > 0.0 && level < (uint32_t)std::floor(attackerLevel * min)) || (max > 0.0 &&
        level > (uint32_t)std::floor(attackerLevel * max))){
        return 0;
    }

    if(Party* party = this->getParty())
    {
        PlayerVector partyMembers = party->getMembers();
        PlayerVector::const_iterator it = partyMembers.begin();
        while(it != partyMembers.end())
        {
            if((*it) == attackerPlayer){
                return 0;
            }
            it++;
        }
    }

    if (this->getGuildId() && attackerPlayer->getGuildId() && attackerPlayer->getGuildId() == this->getGuildId()){
        return 0;
    }

    /*
        Formula
        a = attackers level * 0.9
        b = victims level
        c = victims experience

        result = (1 - (a / b)) * 0.05 * c
        Not affected by special multipliers(!)
    */
        uint32_t a = (uint32_t)std::floor(attackerLevel * 0.9), b = level;
        uint64_t c = getExperience();
        return (double)std::max((uint64_t)0, (uint64_t)std::floor(getDamageRatio(attacker)
            * std::max((double)0, ((double)(1 - (((double)a / b))))) * 0.05 * c)) * rate;
}

Thanks again @godoyxd, for your time and all the effort you've put into solving my problem.
:)
 
Back
Top