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

Powergamers script

ntmr

hi!
Senator
Joined
Jul 7, 2007
Messages
1,835
Reaction score
15
Location
Santa Catarina, Brazil
I want to create a script for my site like the "erig.net powergamers".

I know the basics of php, but don't know how to do it :confused:

Someone can give me an example how to do it? ^_^
 
You could save the experience of each player at a certain time every day/week and then check how much it has increased by the next stop. Then filter out those who has increased the most.

If you got any questions, don't hestitate to ask me. :)
 
Last edited:
Uhmm, that makes sense :p

But my server has ~52000 registered players, I want to filter only the players that logged on the last day (yesterday), but I don't know how the time string on the databse works :S
 
Ah I see. Good point!
Anyways, do you happen to know the name of the DB column? And do you mind showing me a value from any player at all? Would help a lot.
 
Ah ok, there is the structures

Player fields (only the necessary to the script)
Code:
id [int(11)] - example: 1
experience [bigint(20)] - example: 58681110
lastlogin [bigint(20)] - example: 1203214543
 
It's on its way mister!
powergamerslp7.png
 
Last edited:
Yeah it will, however I'm making it as userfriendly as I can, and I'll also make a readme with everything you have to do (unless I do an install file).

So basically you got nothing to fear my friend! :)
 
Hehe yeah I'm Chris at Phobos (Old Xaar), why? :)
Anyways, I'm done with the script now and here it comes:


File: Config.php (Notice: It must have a capital C in the filename!)
PHP:
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<?PHP


	/** Database Connection Data **/
	$config['DB'] = array
	(
	
		'localhost',			# Hostname
		'root',				 # Username
		'',				     # Password
		'scripts',			  # Database
		
		'chris_players',		# Players table
		'chris_powergamers'	 # PowerGamers table
	
	);
	
	
	/** General Configuration **/
	$config['GENERAL'] = array
	(
	
		7,					  # Lastlogin (X days before today).	(Default =  7)
		60,					 # [Forgot about this, so it's out of function] Refresh every X minutes.			(Default = 60)
		30,					 # Show X players at highscore.		(Default = 30)
	
	);
	

?>

File: stylesheet.css
Code:
.info
{
	font: 11px Tahoma;
	background: url(images/info.png) repeat #F2F2F2;
	border: 1px solid #D2D2D2;
	padding: 5px;	
	margin-bottom: 5px;
	text-align: center;
	min-width: 400px;
}

.info h1
{
	font: 16px Tahoma;
	margin: 3px;
	font-weight: bold;
}

.score
{
	border-top: 1px solid #D2D2D2;
	border-bottom: 1px solid #D2D2D2;
}

.score1
{
	font: 13px Tahoma;
	background-color: #F2F2F2;
	border-left: 1px solid #D2D2D2;
	border-right: 1px solid #D2D2D2;
	padding: 5px;
	min-width: 400px;
}

.score2
{
	font: 13px Tahoma;
	background-color: #F7F7F7;
	border-left: 1px solid #D2D2D2;
	border-right: 1px solid #D2D2D2;
	padding: 5px;
	min-width: 400px;
}

.score a:link, a:visited
{
	color: #000;	
	text-decoration: none;
}
.score a:active, a:hover
{
	color: #4c555b;	
	font-weight: bold;
	text-decoration: none;
}

.scoretitles
{
	font: 11px Tahoma;
	font-weight: bold;
	min-width: 400px;
	padding: 5px;
	padding-bottom: 0px;
}

File: DBConnect.php (Notice: It contains 3 capital letters in the filename!)
PHP:
<?PHP


	// Creating a class called Database.
	class Database
	{
		
		// Creating a function called dbConnection.
		function dbConnection ( )
		{
			
			
			// Including the configuration file.
			require ( './Config.php' );
			
			
			// Connect and select the database that was set in the configuration file.
			$db['CONNECT'] = mysql_connect ( $config['DB'][0] , $config['DB'][1] , $config['DB'][2] ) or die ( mysql_error() );
			$db['SELECT']  = mysql_select_db ( $config['DB'][3] , $db['CONNECT'] ) or die ( mysql_error() );
			
		}
	
	}
	
	
	// Print database connection.
	Database::dbConnection();

?>

File: powergamers.php
PHP:
<?PHP

	
	// Include the configuration & database connection files.
	require ( './Config.php' );
	require ( './DBConnect.php' );


	// Creating a class called powerGamers.
	class powerGamers
	{
		
		// Creating a function called onRefresh.
		function onRefresh ( )
		{
			 
		 	// Include the configuration file.
			require ( './Config.php' );
			
			
			// Variables required by the onRefresh function.
			$refreshTime	= $config['GENERAL'][1];
			$limitTop		= $config['GENERAL'][2];
			
			echo "<div class=\"info\"><h1>Top $limitTop PowerGamers</h1>The scoreboard will refresh each and every <strong>$refreshTime</strong> minutes.</div>";
			
		}
		
		
		
		// Creating a function called updateScores.
		function updateScores ( )
		{
		
			// Include the configuration file.
			require ( './Config.php' );
			
			
			// Variables required by the updateScores function.
			$onlineDays		= $config['GENERAL'][0];
			$DBPlayers		= $config['DB'][4];
			$DBPGs			= $config['DB'][5];
			
			$updated		= fread ( fopen ( 'update.txt' , 'r' ) , filesize ( 'update.txt' ) );
			$lastLogin		= date ( "d-m-Y" , mktime ( 0 , 0 , 0 , date ( "m" ) , date ( "d" ) - $onlineDays , date ( "Y" ) ) );
			
			$DBPlayersResult 	= mysql_query ( "SELECT * FROM `$DBPlayers`" );
			
			// Loop the players.
			while ( $row = mysql_fetch_array ( $DBPlayersResult ) )
			{
				
				// Required variables.
				$playerLastLogin	= date ( "d-m-Y" , $row[lastlogin] );
				$DBPGsResult		= mysql_query ( "SELECT * FROM `$DBPGs` WHERE `id` = $row[id]" );
				$checkPGs			= mysql_num_rows ( $DBPGsResult );
				$fetchPGs			= mysql_fetch_array ( $DBPGsResult );
				
				// Check which player has been online the past X days.
				if ( $playerLastLogin >= $lastLogin )
				{
					
					// Check if the players already exists in the PowerGamers table.
					if ( $checkPGs == 0 )
					{
						
						// Add new powergamers.
						mysql_query ( "
							INSERT INTO $DBPGs ( id , oldexperience , newexperience , difference )
							VALUES ( '$row[id]' , '$row[experience]' , '$row[experience]' , '0' )
						" );
						
					}
					elseif ( $checkPGs >= 1 && $updated != date ( "H" ) )
					{
						
						$experience[old] = $fetchPGs[newexperience];
						$experience[now] = $row[experience];
						$experience[dif] = $experience[now] - $experience[old];
						
						// Update the current powergamers.
						mysql_query ( "
							UPDATE $DBPGs
							SET oldexperience = '$experience[old]',
							newexperience = '$experience[now]',
							difference = '$experience[dif]'
							WHERE id = $row[id]
						" );
						
						// Change update.txt to contain 1 instead of 0.
						$fileHandle = fopen ( 'update.txt' , 'w' );
						fwrite ( $fileHandle, date ( "H" ) );
						fclose ( $fileHandle );
						
					}
					
				}
				
			}
			
		}
		
		
		
		// Creating a function called publicScoreboard.
		function publicScoreboard ( )
		{
			
			// Include the configuration file.
			require ( './Config.php' );
			
			
			// Including the onRefresh & updateScores function.
			$obj = new powerGamers;
			$obj -> onRefresh();
			$obj -> updateScores();
			
			
			// Variables required by the publicScoreboard function.
			$limitTop		= $config['GENERAL'][2];
			$DBPlayers		= $config['DB'][4];
			$DBPGs			= $config['DB'][5];
			
			$DBPGsResult 	= mysql_query ( "SELECT * FROM `$DBPGs` WHERE `difference` != '0' ORDER BY `difference` DESC LIMIT $limitTop" );
			$DBPGsCheck		= mysql_num_rows ( mysql_query ( "SELECT * FROM `$DBPGs` WHERE `difference` != '0'" ) );
			$i 				= 0;
			
			
			// Print scoretable titles.
			echo "<div class=\"scoretitles\">";
			echo "<div style=\"width: 5%; float: left;\">#</div>";
			echo "<div style=\"width: 35%; float: left;\">Character</div> ";
			echo "<div style=\"width: 35%; float: left;\">Old / New Experience</div> ";
			echo "<div style=\"width: 23%; float: left;\">Difference</div>";
			echo "&nbsp;</div>";
			echo "<div class=\"score\">";
			
			
			// Check if all the entries have difference 0.
			if ( $DBPGsCheck == 0 )
			{
			
				echo "<div class=\"score1\"><div>There are currently no players with an experience increasement.</div></div>";
				
			}
			
			
			// Loop the players.
			while ( $row = mysql_fetch_array ( $DBPGsResult ) )
			{
				
				
				// Required variables.
				$i++;
				$PGName			= mysql_fetch_array ( mysql_query ( "SELECT * FROM `$DBPlayers` WHERE `id` = $row[id]" ) );


				// Make every second background a different color.
				switch ( $i % 2 )
				{
					case 1:
						$bg = 1;
					break;
					
					default:
						$bg = 2;
					break;
				}
				
				
				// Print the result.
				echo "<div class=\"score$bg\">";
				echo "<div style=\"width: 5%; float: left;\">$i</div>";
				echo "<div style=\"width: 35%; float: left;\"><a href=\"characters.php?char=$PGName[name]\">$PGName[name]</a></div> ";
				echo "<div style=\"width: 35%; float: left;\"><strike style=\"color: #900808;\">$row[oldexperience]</strike> -> $row[newexperience]</div> ";
				echo "<div style=\"width: 23%; float: left;\"><strong style=\"color: #539c33;\">+$row[difference]</strong></div>";
				echo "&nbsp;</div>";
				
			}
			
			
			echo "</div>";
			
		}
		
	}
	
	
	// Print the publicScoreboard function.
	powerGamers::publicScoreboard();


?>

File: update.txt
Code:
0

MySQL: xxx_powergamers
Code:
`ID` INT, PRIMARY KEY
`oldexperience` VARCHAR(60)
`newexperience` VARCHAR(60)
`difference` VARCHAR(60)


EDIT: Forgot to mention, this is the file for images/info.png:
http://img98.imageshack.us/img98/3976/infozn9.png
 
Last edited:
Sure, my pleasure! :) If any errors occurr, feel free to message me about it!
Hehe sweet, I'll check it out (although I'm more than sure I've been on it before!).
 
That script would lagg the server, but might be unnoticed if set to every 24 hrs.
 
I get this error:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\script\powergamers.php on line 155
 
Why do you select everything from the tables, it would be alot faster if you only selected the required field(s).

Talking about this line:
Code:
$PGName            = mysql_fetch_array ( mysql_query ( "SELECT * FROM `$DBPlayers` WHERE `id` = $row[id]" ) );
 
Good point, didn't really pay attention to that either. However I'm going to update it a bit, fix the refresh function and I could fix that while doing the rest.

Thanks for pointing it out!
 
Did you set the correct players table in the config file?


Yes, I did... here is my Config.php

Code:
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<?PHP


    /** Database Connection Data **/
    $config['DB'] = array
    (
    
        'localhost',            # Hostname
        'root',                 # Username
        '****',                     # Password
        'tfs',              # Database
        
        'players',        # Players table
        'xxx_powergamers'     # PowerGamers table
    
    );
    
    
    /** General Configuration **/
    $config['GENERAL'] = array
    (
    
        7,                      # Lastlogin (X days before today).    (Default =  7)
        60,                     # [Forgot about this, so it's out of function] Refresh every X minutes.            (Default = 60)
        30,                     # Show X players at highscore.        (Default = 30)
    
    );
    

?>
 
I have this error from add MySQL:

#1064 - Something is wrong in your syntax obok 'ID` INT, PRIMARY KEY
`oldexperience` VARCHAR(60)
`newexperienc' in line 1
 
I have this error from add MySQL:

Try this:

Code:
CREATE  TABLE  `powergamers` (
`id` INT( 11  )  NOT  NULL ,
`oldexperience` BIGINT( 20  )  NOT  NULL ,
`newexperience` BIGINT( 20  )  NOT  NULL ,
`difference` BIGINT( 20  )  NOT  NULL ,
PRIMARY  KEY (  `id`  ) 
) ENGINE  = InnoDB
 
Last edited:
Back
Top