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

AAC Powergamers/Exp History - strange xp values

Unknown Soldier

Mapping a map
Joined
Oct 30, 2010
Messages
294
Solutions
11
Reaction score
665
Hi everyone,

I have a problem with Powergamers page on Gesior AAC, sometimes it counts very strage amouns ouf exp, and I have no idea why. I am using commonly available php file, which I have modified a little so it shows 3 instead of 7 days of exp.

At the beginning it seemed to work fine, the table updated nicely, exp changes seemed correct, but I've noticed a problem when someone dies, especially when day xp balance is below 0. Also these scripts revealed more problems when I started to count exact amounts of exp gained/lost and comparing them with Highscores/Client Exp Table.

Example:
Someone dies, loses 450 000 xp, no another + exp, so day balance is -450 000. But on Powergamers table it will be something like... -490 000. What's more, when this person kills any monster afterwards, lets say +1000 xp, day balance on website changes to something totally absurd, like -850 000...

Example 2: Another problem I have noticed is + exp balance. Usually it show correct values, but when I have killed 2 test monsters which should give in total 4 000 000 exp, on the website was +6 900 000 xp... Before killing them, all daily exp values were set to 0... I have a thought, that it could be error caused by too-high-exp monster (because normal hunting was almost always ok) or something related to exp stages maybe... no idea

Those are my scripts:

Globalevents serversave which shutdowns the server and updates exp days (lines 6-11):
Lua:
local shutdownAtServerSave = true
local cleanMapAtServerSave = false

local function serverSave()
if shutdownAtServerSave then
--update xp history======================================================================
if (tonumber(os.date("%d")) ~= getGlobalStorageValue(23456)) then
setGlobalStorageValue(23456, (tonumber(os.date("%d"))))
db.query("UPDATE players SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
end
--update xp history end==========================================================================
Game.setGameState(GAME_STATE_SHUTDOWN)
else
Game.setGameState(GAME_STATE_CLOSED)
if cleanMapAtServerSave then
cleanMap()
end

Game.setGameState(GAME_STATE_NORMAL)
end
end

local function secondServerSaveWarning()
broadcastMessage("Server is saving game in one minute. Please logout.", MESSAGE_STATUS_WARNING)
addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
broadcastMessage("Server is saving game in 3 minutes. Please logout.", MESSAGE_STATUS_WARNING)
addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
broadcastMessage("Server is saving game in 5 minutes. Please logout.", MESSAGE_STATUS_WARNING)
Game.setGameState(GAME_STATE_STARTUP)
addEvent(firstServerSaveWarning, 120000)
return not shutdownAtServerSave
end

Powergamers.php
PHP:
<?php
if(!defined('INITIALIZED'))
    exit;
$limit = 100;
$type = $_REQUEST['type'];
function coloured_value($valuein)
{
    $value2 = $valuein;
    while(strlen($value2) > 3)
    {
        $value .= '.'.substr($value2, -3, 3);
        $value2 = substr($value2, 0, strlen($value2)-3);
    }
    $value = $value2.$value;
    if($valuein > 0)
        return '<font color="green">+'.$value.'</font>';
    elseif($valuein < 0)
        return '<font color="red">'.$value.'</font>';
    else
        return '<font color="black">'.$value.'</font>';
}
if(empty($type))
    $players = $SQL->query('SELECT * FROM ' . $SQL->tableName('players') . ' WHERE ' . $SQL->fieldName('group_id') . ' < 2 ORDER BY ' . $SQL->fieldName('experience') . '-' . $SQL->fieldName('exphist_lastexp') . ' DESC LIMIT ' . $limit)->fetchAll();
elseif($type == "sum")
    $players = $SQL->query('SELECT * FROM ' . $SQL->tableName('players') . ' WHERE ' . $SQL->fieldName('group_id') . ' < 2 ORDER BY ' . $SQL->fieldName('exphist1') . '+' . $SQL->fieldName('exphist2') . '+' . $SQL->fieldName('exphist3') .  ' DESC LIMIT ' . $limit)->fetchAll();
elseif($type >= 1 && $type <= 3)
    $players = $SQL->query('SELECT * FROM ' . $SQL->tableName('players') . ' WHERE ' . $SQL->fieldName('group_id') . ' < 2 ORDER BY ' . $SQL->fieldName('exphist' . (int) $type) . ' DESC LIMIT '.$limit)->fetchAll();
        $main_content .= '<h1 align="center">Experience History</h1>';
        $main_content .= 'Table below shows recent experience changes on The Unknown fot the past 3 days plus current day. There is also sumed up experience change for this period of time.';
    $main_content .= '<CENTER></CENTER><BR><TABLE BORDER="0" CELLPADDING="4" CELLSPACING="1" WIDTH="100%"><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD style="color:white"><B>#</B></TD><TD style="color:white"><B>Name</B></TD>';
if($type == "sum")
    $main_content .= '<TD bgcolor="red"><b><center><a href="?subtopic=powergamers&type=sum">3 Days change</a></center></B></TD>';
else
    $main_content .= '<TD><b><center><a href="?subtopic=powergamers&type=sum">3 Days change</a></center></B></TD>';
for($i = 3; $i >= 2; $i--)
{
    if($type == $i)
        $main_content .= '<TD bgcolor="red"><b><center><a href="?subtopic=powergamers&type='.$i.'">'.$i.' Days Ago</a></center></B></TD>';
    else
        $main_content .= '<TD><b><center><a href="?subtopic=powergamers&type='.$i.'">'.$i.' Days Ago</a></center></B></TD>';
}
if($type == 1)
    $main_content .= '<TD bgcolor="red"><b><center><a href="?subtopic=powergamers&type=1">1 Day Ago</a></center></B></TD>';
else
    $main_content .= '<TD><b><center><a href="?subtopic=powergamers&type=1">1 Day Ago</a></center></B></TD>';
if(empty($type))
    $main_content .= '<TD bgcolor="red"><b><center><a href="?subtopic=powergamers">Today</a></center></B></TD>';
else
    $main_content .= '<TD><b><center><a href="?subtopic=powergamers">Today</a></center></B></TD>';
$main_content .= '</TR>';
foreach($players as $player)
{
    if(!is_int($number_of_rows / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $number_of_rows++;
    $main_content .= '<tr bgcolor="'.$bgcolor.'"><td align="center">'.$number_of_rows.'. </td>';
    if(Player::isPlayerOnline($player['id']))
        $main_content .= '<td><a href="?subtopic=characters&name='.urlencode($player['name']).'"><b><font color="green">'.htmlspecialchars($player['name']).'</font></b></a>';
    else
        $main_content .= '<td><a href="?subtopic=characters&name='.urlencode($player['name']).'"><b><font color="red">'.htmlspecialchars($player['name']).'</font></b></a>';
    $main_content .= '<br />'.$player['level'].' '.htmlspecialchars(Website::getVocationName($player['vocation'])).'</td><td align="right">
 
    '.coloured_value($player['exphist1'] + $player['exphist2'] + $player['exphist3'] + ($player['experience']-$player['exphist_lastexp'])).'
 
    </td>';
    $main_content .= '<td align="right">'.coloured_value($player['exphist3']).'</td><td align="right">'.coloured_value($player['exphist2']).'</td><td align="right">'.coloured_value($player['exphist1']).'</td><td align="right">'.coloured_value($player['experience']-$player['exphist_lastexp']).'</td></tr>';

    }
$main_content .= '</TABLE>';

//original formula
//'</td><td align="right">'.coloured_value($player['exphist1'] + $player['exphist2'] + $player['exphist3'] + $player['exphist4'] + $player['exphist5'] + $player['exphist6'] + $player['exphist7'] + $player['experience'] - $player['exphist_lastexp']).'</td>';

Of course I have added all needed tables in database in phpmyadmin.

I would really appreciate your help!

@Edit
I've decided to provide some "real" examples:

blue - real exp values
green - correct calculations
red - not correct calculations made by script

Single day example:
Exp before death: 1 452 559 666
Exp after death: 1 403 982 998
Calc result: -48 576 668
Powergamers.php: -48 668 576

All days summary example:
Exp 3 days ago: +27 872 252
Exp 2 days ago: 0
Exp 1 day ago: 0
Exp today: -48 668 576
Calc result: -20 796 324
Powergamers.php: -21 796 323

Afterwards, killing one troll which gave 60 exp:
In-game exp change: +60
Powergamers.php before killing: -48 668 576
Powergamers.php after killing: -48 608 576
Powergamers.php exp change: +60 000

 
Last edited:
Solution
You'll need something like this:
Code:
$exp_history = $SQL->query('SELECT `exphist1`, `exphist2`, `exphist3`, `exphist_lastexp` FROM `players` WHERE `id` = ' . $player->getID())->fetch();

Then in your code you can do something like this:
Code:
 <tr BGCOLOR="'.$config['site']['darkborder'].'"><td>3 Days Ago</td><td>" . $exp_history['exphist3'] . "</font></td></tr>
Well, I have found the solution, I guess many of you will have the same problem so I am leaving the solution.

in .php replace

PHP:
function coloured_value($valuein)
{
    $value2 = $valuein;
    while(strlen($value2) > 3)
    {
        $value .= '.'.substr($value2, -3, 3);
        $value2 = substr($value2, 0, strlen($value2)-3);
    }
    $value = $value2.$value;
    if($valuein > 0)
        return '<font color="green">+'.$value.'</font>';
    elseif($valuein < 0)
        return '<font color="red">'.$value.'</font>';
    else
        return '<font color="black">'.$value.'</font>';
}

with

PHP:
function coloured_value($valuein)
{
    $value2 = $valuein;

    $value = $value2.$value;

    if($valuein > 0)
        return '<font color="green">+'.number_format($valuein).'</font>';
    elseif($valuein < 0)
        return '<font color="red">'.number_format($valuein).'</font>';
    else
        return '<font color="black">'.number_format($valuein).'</font>';
}



BUT I still need you help :)

In Characters.php I am currently trying to add a table which shows recent exp history for selected player... no result so far... I need some loop that will check player name and read from PHPMyAdmin value from fields "exphist1", exphist2" and so on...

Table layout is like this:

PHP:
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD COLSPAN=2 WIDTH=90% CLASS=white><B>Exp History</B></TD></TR>
       
    <tr BGCOLOR="'.$config['site']['lightborder'].'"><td>Today</td><td>?</td></tr>
    <tr BGCOLOR="'.$config['site']['darkborder'].'"><td>1 Day Ago</td><td>?</td></tr>
    <tr BGCOLOR="'.$config['site']['lightborder'].'"><td>2 Days Ago</td><td>?</font></td></tr>
    <tr BGCOLOR="'.$config['site']['darkborder'].'"><td>3 Days Ago</td><td>?</font></td></tr>
    <tr BGCOLOR="'.$config['site']['lightborder'].'"><td>3 Days Ago</td><td>?</font></td></tr>
       
        <tr></TABLE>

So... for now I have:
HTRzFGO.png


Thanks in advance :)
 
I haven't worked with PHP in over a decade, but in your first function ot looks like you are assigning variables $value and $value2, but never using them. You could cut those assignments out and save a bit of cpu and memory.

I have not ever worked with OT and its MySQL schema, so I won't attempt an answer on the second one.
 
You'll need something like this:
Code:
$exp_history = $SQL->query('SELECT `exphist1`, `exphist2`, `exphist3`, `exphist_lastexp` FROM `players` WHERE `id` = ' . $player->getID())->fetch();

Then in your code you can do something like this:
Code:
 <tr BGCOLOR="'.$config['site']['darkborder'].'"><td>3 Days Ago</td><td>" . $exp_history['exphist3'] . "</font></td></tr>
 
Solution
Thanks a lot , it works perfectly, just with ' instead of " in here '. $exp_history['exphist3'] .' :)

Just one more thing, in row "Today" I need to put a formula:

player exp - last exp

how do I substract them?

@Edit
Ok, I shouldn't have asked for substraction, I made a noob question... anyway, for those interested, here goes the solution:

' . ($exp_history['experience']-$exp_history['exphist_lastexp']) . '

Well, thank you very much for help :)
 
Last edited:
Back
Top