Hi,
create an table in database :
edit the creaturescripts event="login" script file, add 1 if it dont exists :
create the php image file : chartonline.php
get the pChart class from : pChart and make sure u get the path correct when you unzip.
create an table in database :
Code:
CREATE TABLE `forgottenserver`.`z_onlineplayers` (
`world_id` int(10) unsigned NOT NULL,
`timestamp` int(10) unsigned NOT NULL,
`count` int(10) unsigned NOT NULL
) ENGINE=MyISAM
edit the creaturescripts event="login" script file, add 1 if it dont exists :
Code:
<event type="login" name="PlayerLogin" event="script" value="login.lua"/>
Code:
function onLogin (cid)
db.executeQuery("INSERT INTO `z_onlineplayers` (`world_id`, `timestamp`, `count`) SELECT " .. getConfigValue('worldId') .. ", " .. os.time() .. ", count(*) FROM players where online =1;")
db.executeQuery("DELETE FROM forgottenserver.z_onlineplayers WHERE FROM_UNIXTIME(timestamp) < DATE_SUB(NOW(),INTERVAL 24 HOUR)")
return true
end
create the php image file : chartonline.php
Code:
<?php
$hoursCount = 23;
$dbhost = '127.0.0.1';
$dblogin = 'root';
$dbpass = '';
$dbname = 'forgottenserver';
mysql_connect($dbhost, $dblogin, $dbpass);
mysql_select_db($dbname);
$seq="SELECT 0 AS id";
for ($i=1;$i<=$hoursCount;$i++)
{
$seq .= " UNION SELECT " . $i;
}
$query = "SELECT HOUR(tid) as hour, max(ifnull(count,0)) as count " .
"FROM " .
"(SELECT DATE_FORMAT(DATE_SUB(now(),INTERVAL (id) HOUR),'%Y-%m-%d %H') as tid FROM (" . $seq . ") seq) s left join " .
"forgottenserver.z_onlineplayers o on s.tid = DATE_FORMAT(FROM_UNIXTIME(timestamp),'%Y-%m-%d %H') " .
"group by s.tid " .
"ORDER BY s.tid";
$result = mysql_query($query);
$maxy = 0;
$miny = 9999;
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$aCount[$i] = '';
if ($row['count'] <> 0)
$aCount[$i] = $row['count'];
$aHour[$i] = $row['hour'];
if($maxy < $aCount[$i])
$maxy = floor($aCount[$i]/10)*10+10;
if($miny >= $aCount[$i])
$miny = floor($aCount[$i]/10)*10;
$i++;
}
// Standard inclusions
include("pChart/pChart/pData.class");
include("pChart/pChart/pChart.class");
// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint($aCount,"Serie1");
$DataSet->AddPoint($aHour,"Serie3");
$DataSet->AddSerie("Serie1");
$DataSet->SetAbsciseLabelSerie("Serie3");
// Initialise the graph
$Test = new pChart(700,300);
$Test->setFixedScale($miny,$maxy);
$Test->setFontProperties("pChart/Fonts/tahoma.ttf",10);
$Test->setGraphArea(40,30,680,200);
$Test->drawGraphArea(252,252,252);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,90,0,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,255);
// Write values on Serie1 & Serie2
$Test->setFontProperties("pChart/Fonts/tahoma.ttf",8);
$Test->writeValues($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1");
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
// Set labels
$Test->setFontProperties("pChart/Fonts/tahoma.ttf",8);
$Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","6","globalSave",239,233,195);
// Finish the graph
$Test->setFontProperties("pChart/Fonts/tahoma.ttf",10);
$Test->Stroke();
?>
get the pChart class from : pChart and make sure u get the path correct when you unzip.