• 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++ config exp per player

Makin

New Member
Joined
Sep 17, 2018
Messages
37
Solutions
1
Reaction score
2
hi, how can I make 0.75 work in config and not 1. I use tfs 1.2.
I don't know much about c ++

it works
expenfo = 1
it doesn't work anymore
expenfo = 0.75


I know my English is poor
 
player.cpp
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 && 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) * g_config.getNumber(ConfigManager::EXP_ENFO_PLAYER)));
        }
    }
    return 0;
}

I've already added to
configmanager.cpp
integer[EXP_ENFO_PLAYER] = getGlobalNumber(L, "expenfo");
configmanager.h
EXP_ENFO_PLAYER,
config.lua
expenfo = 1
and only full numbers work. And I want them to work after the decimal point.
for example
expenfo = 0.75
 
have a simple solution, go to data/events/player.lua
check for
Code:
return exp
change to
Code:
return exp / 100
now u can use in xml exp 75 -> will be 0.75
 
add configmanager.cpp
C++:
    floating[EXP_ENFO_PLAYER] = getGlobalFloat(L, "expenfo", 0.75);
under
C++:
int32_t ConfigManager::getNumber(integer_config_t _what) const
{
    if (_what >= LAST_INTEGER_CONFIG) {
        std::cout << "[Warning - ConfigManager::getNumber] Accessing invalid index: " << _what << std::endl;
        return 0;
    }
    return integer[_what];
}
add
C++:
float ConfigManager::getFloat(floating_config_t _what) const
{
    if (_what >= LAST_FLOATING_CONFIG) {
        std::cout << "[Warning - ConfigManager::getFloat] Accessing invalid index: " << _what << std::endl;
        return 0.0f;
    }
    return floating[_what];
}
under
C++:
int32_t ConfigManager::getGlobalNumber(lua_State* L, const char* identifier, const int32_t _default)
{
    lua_getglobal(L, identifier);
    if (!lua_isnumber(L, -1)) {
        return _default;
    }

    int32_t val = lua_tonumber(L, -1);
    lua_pop(L, 1);
    return val;
}
add
C++:
float ConfigManager::getGlobalFloat(lua_State* L, const char* identifier, const float defaultValue)
{
    lua_getglobal(L, identifier);
    if (!lua_isnumber(L, -1)) {
        lua_pop(L, 1);
        return defaultValue;
    }

    float val = lua_tonumber(L, -1);
    lua_pop(L, 1);
    return val;
}

configmanager.h
under
C++:
LAST_INTEGER_CONFIG /* this must be the last one */
        };
add
C++:
enum floating_config_t {
            EXP_ENFO_PLAYER,
           
            LAST_FLOATING_CONFIG
        };
under
C++:
        bool getBoolean(boolean_config_t _what) const;
add
Code:
        float getFloat(floating_config_t _what) const;
under
Code:
        static int32_t getGlobalNumber(lua_State* L, const char* identifier, const int32_t _default = 0);
add
C++:
        float getGlobalFloat(lua_State* L, const char* identifier, const float defaultValue = 0.0f);
under
C++:
        bool boolean[LAST_BOOLEAN_CONFIG];
add
C++:
        float floating[LAST_FLOATING_CONFIG];
 
Back
Top