#### Gesior.pl

##### Mega Noob&LOL 2012

**This is not 'code release' (only)! There is full description of problem with maximum number value in C++.**

Let's fix max. level problem (for high exp servers)!

Let's fix max. level problem (for high exp servers)!

__THIS FIX YOU CAN ONLY INSTALL BEFORE SERVER START. THIS FIX REQUIRES ALL CHARACTERS RESET (level and exp).__Example with formulat with max. level over 250.000.000:

1. First thing to do is to

**reduce exp ratio**/exp from monsters [.xml / .lua files].

**When experience reaches '18.446.744.073.709.551.615' it stops leveling.**

2. Change

**getExpForLevel**function in

**player.h**(sources)

**There is something like:**

Code:

```
static uint64_t getExpForLevel(int32_t lv) {
... (no matter what is here, we replace it!) ...
}
```

**Replace it with (this is just example function, you should make some better, as it's growing flat lvl 1 = X exp, lvl 2 = 2*X exp, .. lvl N = N * X exp):**

Code:

```
static uint64_t getExpForLevel(int32_t lv) {
lv--;
return ((150ULL * lv * lv) - (50ULL * lv * lv) + (1200ULL)) / 3ULL;
}
```

**Rebuild sources**(this change requires 'rebuild', not just 'compile'!)

[How to rebuild 0.3.6/0.4 on linux? Remove all .o files from compilation folder:

**rm *.o**]

**Compare exp required for level:**

Normal formula 'lvl 29' exp is equal to new formula 'lvl 100' exp - players gain levels much faster with same exp ratio!

-------------------------------------------------------------

**Why? What? Where? Short explanation:**

Exp-level formula is:

**((50ULL * lv * lv * lv) - (150ULL * lv * lv) + (400ULL * lv)) / 3ULL**

Now change it into math parts that computer must calculate (in computer-calculation order - different then school/human calculation):

$x1 = 400ULL * lv

$x2 = 150ULL * lv * lv

$x3 = 50ULL * lv * lv * lv

$x4 = $x3 + ($x1 - $x2)

$x5 = 3ULL

$x6 = $x4 / $x5

Now use some level in these calculations, hmm... 5.000.000 level? OK!

$lv =

**5.000.000**

$x1 =

**2.000.000.000**

$x2 =

**3.750.000.000.000.000**

$x3 = 6.249.

**999.999.999.999.475.712**

$x4 = 6.249

**.996.250.001.999.659.008**

$x5 =

**3**

$x6 = 2.083.

**332.083.333.999.886.336**

18.

**446.744.073.709.551.615**- this is max. allowed value for math calculation [high precision] in C++ [and many other languanges]

(first 18 digits of numbers are

**bold**to let you see which numbers are too high)

As you can see value of

**$x3**[50ULL * lv * lv * lv] for level 5.000.000 is much higher then maximum allowed value for number (and because of it

**$x4**and

**$x6**are also too high). So problem is with too high 'exp' value, not too high 'level' value.

**Can you change maximum value in C++?**

**No**(there is possibility, but it's not easy.. it's super hard! - you must change it everywhere is sources).

Only thing you can do is to give more levels for X 'exp points'. Then when player reaches exp 'max', his level will be 5.000.000 not 717.206.

--------------------------------------------

**Extra info + calculator:**

**ULL**- unsigned long long (integer) -

**max. value: 18.446.744.073.709.551.615**, you must add it to every number in math formula to tell computer to calculate with highest precision (highest maximum value)

__Awesome formula level calculator. Find too high number easy.__http://writecodeonline.com/php/

Paste in this *magic* formula (compare your exp-level calculation part values with maximum possible 'unsigned 64 bit integer value'):

Code:

```
$lv = 5000000;
$x1 = 400 * $lv;
$x2 = 150 * $lv * $lv;
$x3 = 50 * $lv * $lv * $lv;
$x4 = $x3 + ($x1 - $x2);
$x5 = 3;
$x6 = $x4 / $x5;
echo number_format($x1, 0, '', '.') . "\n" . number_format($x2, 0, '', '.') . "\n" . number_format($x3, 0, '', '.') . "\n" . number_format($x4, 0, '', '.') . "\n" . number_format($x5, 0, '', '.') . "\n" . number_format($x6, 0, '', '.') . "\n18.446.744.073.709.551.615 - this is max. allowed value";
```

**$x1**to

**$x5**and check why some changes in formula does not help.

Last edited: