Ranks

Location of the Videos
Post Reply
User avatar
august
Posts: 21
Joined: Mon Apr 05, 2010 9:27 am

Ranks

Post by august »

Fiddled with some code and did something on my own from what I've learned using this forum so I thought I'd share it with you all, even though most of you probably know how to do this anyone it could help some!

Create a new table called 'ranks' with 3 fields, rank (varchar), ranklevel (smallint), and race (varchar), however in all of halls tutorials he has used class insted of race, so for this I will just call class for now!

Create a new field in players table called rank (smallint)

Create query (did this in my statpanel.php as this is the only place its used and easier than adding it to each individual page).

Code: Select all

$ranklevel=$playerinfo3['rank'];
$rankclass=$playerinfo3['class'];
$rankinfo="SELECT * from ranks WHERE ranklevel='$ranklevel' AND race='$rankclass'";
$rankinfo2=mysql_query($rankinfo) or die("could not get rank!");
$rankinfo3=mysql_fetch_array($rankinfo2);
add code (again this is in my statpanel)

Code: Select all

echo "" . $rankinfo3['rank'] . "";
Two new pages are needed, I used rankup.php, rankup2.php (basically copies of the levelup.php and levelup2.php with a few tweaks)

changed levelup.php code that was in my new rankup.php code to this

Code: Select all

<?php
$rankexperneeded = ($playerinfo3['rank'] * 250) * $playerinfo3['rank'];
  if ($playerinfo3['exper'] >= $rankexperneeded)
 {
 
really not much different here, could still use the levelup code, I changed mine to be multiplied by 250, meaning ranking up happens alot less often.

Code: Select all

 echo "<u>Choose what you would like to level up in</u><br><br>"; 
 echo "<A href='rankup2.php?stat=att'>Attack</a><br>";
 echo "<A href='rankup2.php?stat=def'>Defense</a><br>";
 echo "<A href='rankup2.php?stat=hp'>Hit Points</a><br>";
  echo "<A href='rankup2.php?stat=tp'>Tech Points</a><br>";
I haven't touch this bit yet, but I'm sure once you add more stats to your game (like I will be doing eventually) you'll be able to find some new stats to increase that are different from your leveling up stats.

Code: Select all

 
 else 
 {
  echo "Your exp. is only " . $playerinfo3['exper'] . "<br>" . $rankexperneeded . " exp. is needed before your next promotion. <br><br> <A href='index.php'>Go Back</a>";
 }
we're still using expneeded, nothings changed there, its just a larger amount needed for each promotion in rank.

I then inserted some data into my ranks field. Name of the rank, the rank level (thought about having this as an autoinc, but choose against it because ...) and the name of the class ... which is matched to the name of class in the players tables, this allows for unique promotion title for each class seperately.

Heres a screen of my ranks table so you can see what I mean:

Code: Select all

<?php

echo "PHP kicks your ASP";

?>
User avatar
august
Posts: 21
Joined: Mon Apr 05, 2010 9:27 am

Re: Ranks

Post by august »

Code: Select all

$rankexperneeded = ($playerinfo3['rank'] * 250) * $playerinfo3['rank'];
  if ($playerinfo3['exper'] >= $rankexperneeded)
 {
 ///do not make the get variable = the actual stat name, could cause cheating\\\\\\\\\\\\\
 $stat = $_GET['stat'];

 switch($stat)
 {
 case 'att':
 $statname = 'attack';
 $mod = 1;
 break;
 case 'def':
 $statname = 'defense';
 $mod = 1;
 break;
 case 'hp':
 $statname = 'maxhp';
 $mod = (2 * $playerinfo3['level']);
 break;
 case 'tp':
 $statname = 'maxtp';
 $mod = (2 * $playerinfo3['level']);
 break;
 }
  $updateplayer="update players set `$statname`=`$statname`+'$mod',rank=rank+1 WHERE name='$player'";
  mysql_query($updateplayer) or die("Could not update player");
 echo "You have successfully levelled up. <br><A href='index.php'>Go Back</a>";
 
forgot my rankup2.php code .... your rank wouldn't update without this ... rank=rank+1 insted of level=level+1

also ive changed so of my modifers, (2 * $playerinfo3['level']); ... because I thought just adding 5 on each time wasnt really enough for the high level players ... but you should know all about this if you've gone through halls amazing tutorials!

Code: Select all

<?php

echo "PHP kicks your ASP";

?>
User avatar
august
Posts: 21
Joined: Mon Apr 05, 2010 9:27 am

Re: Ranks

Post by august »

theres a bit in the stat panel code that needs changing from level to rank also.

Code: Select all

<?php

echo "PHP kicks your ASP";

?>
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Ranks

Post by hallsofvallhalla »

thanks for sharing, i will look through it in a bit.
Post Reply

Return to “Older Browser MMO Videos”