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

[PHP] Get skill percent

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,956
Solutions
98
Reaction score
3,354
Location
Poland
GitHub
gesior
Someone asked me:
How to calculate player skill percent on www?
I wrote for him example code. Maybe someone else needs it too:
PHP:
<?php
function getSkillPercent($skillId, $vocationId, $playerSkillValue, $playerSkillCount)
{
// information about skills multipliers for vocations from vocations.xml
    $vocSkillInfo = [
        0 => [1.5, 2.0, 2.0, 2.0, 2.0, 1.5, 1.1],
        1 => [1.5, 2.0, 2.0, 2.0, 2.0, 1.5, 1.1],
        2 => [1.5, 1.8, 1.8, 1.8, 1.8, 1.5, 1.1],
        3 => [1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1.1],
        4 => [1.1, 1.1, 1.1, 1.1, 1.4, 1.1, 1.1],
        5 => [1.5, 2.0, 2.0, 2.0, 2.0, 1.5, 1.1],
        6 => [1.5, 1.8, 1.8, 1.8, 1.8, 1.5, 1.1],
        7 => [1.2, 1.2, 1.2, 1.2, 1.1, 1.1, 1.1],
        8 => [1.1, 1.1, 1.1, 1.1, 1.4, 1.1, 1.1],
    ];
    // skill base, same for all Tibia servers
    $skillBase = [50, 50, 50, 50, 30, 100, 20];
    $playerNextSkillValue = $playerSkillValue + 1;
    $nextSkillTries = $skillBase[$skillId] * pow($vocSkillInfo[$vocationId][$skillId], $playerNextSkillValue - 11);
    return floor(($playerSkillCount / $nextSkillTries) * 100);
}
// distance skill (4), royal paladin (7), 70 distance, 11111 tries
echo getSkillPercent(4, 7, 70, 11111) . '%';
 
Now he asked about same code for magic level :)
PHP:
<?php
function getMagicPercent($vocationId, $playerMagicLevel, $playerManaSpent)
{
// information about vocation 'manamultiplier' from vocations.xml
    $vocMagicInfo = [
        0 => 4.0,
        1 => 1.1,
        2 => 1.1,
        3 => 1.4,
        4 => 3.0,
        5 => 1.1,
        6 => 1.1,
        7 => 1.4,
        8 => 3.0
    ];
    $playerNextMagicLevel = $playerMagicLevel + 1;
    $reqMana = floor(400 * pow($vocMagicInfo[$vocationId], $playerNextMagicLevel - 1));
    $modResult = $reqMana % 20;
    if ($modResult < 10) {
        $reqMana -= $modResult;
    } else {
        $reqMana -= $modResult + 20;
    }
    return floor(($playerManaSpent / $reqMana) * 100);
}

// royal paladin (7), 14 magic level, 28000 mana spent
echo getMagicPercent(7, 14, 28000) . '%';
 
It's PHP code. It runs on the server computer. The client, which is you usually, connects to it with a separate computer.
 
Back
Top