• 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++ Explain Formula level

Obito

0x1337
Joined
Feb 17, 2011
Messages
351
Solutions
8
Reaction score
151
Location
Egypt
Greetings OTLanders can someone explain in math this formula and how it works?
C++:
    static uint64_t getExpForLevel(int32_t level)
    {
        int64_t x = level;
    return ((50*x/3 - 100)*x + 850/3)*x - 200;
       
    }
And how to edit it to reach the maximum level to 1300 for example because the level stuck at 638 with 12,999,891 exprience
Capture.PNG
maxy.PNG
Thanks in advance!
 
Solution
Not sure why it works in cpp.sh, probably some weird optimizations, but your formula for some reason doesn't use unsigned long long literals for integer calculation. The max xp you can have is 4,294,967,295 which is why you're only able to get up to 638, if you look at @Alpha's code snippet you can see after 638 you go past that value up to 4,307,967,187 at level 639, but it will overflow and cause you to not gain levels anymore.
Look at the default TFS calculation:
C++:
static uint64_t getExpForLevel(int32_t lv) {
    lv--;
    return ((50ULL * lv * lv * lv) - (150ULL * lv * lv) + (400ULL * lv)) / 3ULL;
}
By using the ULL literal, it converts the integer on the left to uint64_t, allowing the following...
Not sure why it works in cpp.sh, probably some weird optimizations, but your formula for some reason doesn't use unsigned long long literals for integer calculation. The max xp you can have is 4,294,967,295 which is why you're only able to get up to 638, if you look at @Alpha's code snippet you can see after 638 you go past that value up to 4,307,967,187 at level 639, but it will overflow and cause you to not gain levels anymore.
Look at the default TFS calculation:
C++:
static uint64_t getExpForLevel(int32_t lv) {
    lv--;
    return ((50ULL * lv * lv * lv) - (150ULL * lv * lv) + (400ULL * lv)) / 3ULL;
}
By using the ULL literal, it converts the integer on the left to uint64_t, allowing the following calculation to result in that data type instead of the default int type (usually int32_t).

You should just be able to return 0 if lv is > 1300 as well to make that the max level.
 
Solution
Back
Top