Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- V0.2.0 current
- *V0.1.2: http://pastebin.com/dq8xJnns (does not work correctly (gives you average time played per player total and has some formatting issues));
- *V0.1.1: http://pastebin.com/UvXen9dB (does not work correctly (gives you average time played per player total));
- Made by Mikkel Jeppsen, a.k.a. smuttenDK a.k.a. dumle29.
- Script to get the average survival time of the players on your bliss based dayz privatehived server,
- and show it on your site.
- To use this:
- Option 1:
- Put this code in a file and name it NAME.php
- Then, the place you want it on your site, enter <?php include 'PATH/TO/FILE/NAME.php' ?>
- Option 2:
- Paste this code in to your site, the place you want it to appear.
- */
- /*---------------Start of config---------------*/
- $host = "HOSTNAME"; //Put the hostname or the ip of your database server here.
- $user = "USERNAME"; //Put your username here.
- $pass = "PASSWORD"; //Enter your password to the database here.
- $dataBase = "DBNAME"; //Enter the name of your database here.
- $minLim = 50; //Minimum amount of minutes to have lived before it is included in the average
- $hourSingular = "hour"; //Allows you to change the word used for the singularium of hour.
- $hourPlural = "hours"; //Allows you to change the word used for the plural of hour.
- $andStr = "and"; //Allows you to change the word used to combine the hours and minutes string.
- $minuteSingular = "minute"; //Allows you to change the word used for the singularium of minute.
- $minutePlural = "minutes"; //Allows you to change the word used for the plural of minute.
- /*---------------End of config---------------*/
- $minutes = 0;
- $hours = 0;
- $average = 0;
- $con = mysql_connect($host,$user,$pass);
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db($dataBase, $con) or die(mysql_error());
- $sql = "SELECT AVG(survival_time) FROM survivor WHERE survival_time >= ".$minLim." AND is_dead = 0";
- $resultRaw = mysql_query($sql);
- if(!$averageArr = mysql_fetch_row($resultRaw))
- {
- $minutes = 0;
- }
- else
- {
- $minutes = round($averageArr[0],0);
- }
- if($minutes > 59)
- {
- $hours = floor($minutes / 60);
- $minutes = $minutes % 60;
- }
- if($hours > 1)
- {
- $hourStr = $hours . ' ' . $hourPlural;
- }
- else if($hours <= 1 && $hours > 0)
- {
- $hourStr = $hours. ' ' . $hourSingular;
- }
- else
- {
- $hourStr = '';
- }
- if($minutes > 1)
- {
- $minuteStr =$minutes. ' ' . $minutePlural;
- }
- else if($minutes <= 1 && $minutes > 0)
- {
- $minuteStr =$minutes. ' ' . $minuteSingular;
- }
- else if($minutes == 0 && !$hours)
- {
- $minuteStr =$minutes. ' ' . $minutePlural;
- }
- else
- {
- $minuteStr = '';
- }
- if($hourStr != '' && $minutes != '')
- {
- $andStr =' '. $andStr .' ';
- }
- else
- {
- $andStr = '';
- }
- echo $hourStr . $andStr . $minuteStr;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement