Ranks
Posted: Thu Apr 08, 2010 10:42 pm
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).
add code (again this is in my statpanel)
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
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.
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.
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:
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);
Code: Select all
echo "" . $rankinfo3['rank'] . "";
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)
{
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>";
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>";
}
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: