Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,578 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,960 people online right now. Registration is fast and FREE... Join Now!




Help annalyizing code and how to rewrite more efficiently.

 
Reply to this topicStart new topic

Help annalyizing code and how to rewrite more efficiently.

alyis
2 Oct, 2008 - 04:17 PM
Post #1

New D.I.C Head
*

Joined: 12 Mar, 2008
Posts: 12


My Contributions
Could some one help me to understand what this section of code is doing please? I understand basicly that the game is set up so you gain experience and then based on a certain "amount" of experience it sets you to a certain level. But what I am wanting to do is recode this part of the game so that at a certain amount of exp it would set a 'row' in the 'users' table called "level" to whatever that level should be according to the "amount" of experience the user has.

CODE
function experience($L) {
  $a=0;
  $end=0;
  for($x=1; $x<$L; $x++) {
    $a += floor($x+1500*pow(4, ($x/7)));
  }
  return floor($a/4);
}

function Get_The_Level($exp) {
  $a=0;
  $end =0;
  for($x=1; ($end==0 && $x<100); $x++) {
    $a += floor($x+1500*pow(4, ($x/7)));
    if ($exp >= floor($a/4)){
    } else {
      return $x;
      $end=1;
    }
  }
}

function Get_Max_Exp($L){
$end=0;
if ($exp == 0){
    return 457;
    $end =1;
  }
    for($L=1;($L<100 && $end==0);$L++) {
      $exp = experience($L);
      //echo $exp;
      if ($exp >= $user_class->exp){
        return $exp;
        $end=1;
      }
    }
}

User is offlineProfile CardPM
+Quote Post

pr4y
RE: Help Annalyizing Code And How To Rewrite More Efficiently.
2 Oct, 2008 - 05:51 PM
Post #2

D.I.C Head
Group Icon

Joined: 19 Sep, 2008
Posts: 76


Dream Kudos: 50
My Contributions
The first thing you would need to do would be set up an extra table in the database that contains 2 fields: 'experience' and 'level' and an extra row in the 'users' table called 'curLvl'. Next you would need to manually determine how much EXP is required for each level and put all that information in the database. Instead of determining what level you are based upon your experience, you can CHECK if you have leveled up each time you gain experience (less efficient) and change the level tables accordingly.

To increase the efficiency of this, but also will require a bit more coding... you could have a 'tilNext' row in the 'users' table. Instead of checking your experience each time you kill something to see if you gained a level, you can use the 'tilNext' to create an algorythm for experience gained and leveling up. When you gain experience, if your $expGained (or whatever var) is less than your 'tilNext' value, $gainLevel = false.

Although this reduces efficiency, you can ADD a lot to the game by using this feature. You can add another field to the users table called 'maxLvl', giving you the ability to have spells that reduce your curLvl or buffs that increase your curLvl.

I'm not going to take the time to write this code for you, but hopefully you get the idea. If you have any questions just let me know.

This post has been edited by pr4y: 2 Oct, 2008 - 05:55 PM
User is offlineProfile CardPM
+Quote Post

alyis
RE: Help Annalyizing Code And How To Rewrite More Efficiently.
2 Oct, 2008 - 06:27 PM
Post #3

New D.I.C Head
*

Joined: 12 Mar, 2008
Posts: 12


My Contributions
Thanks for this I kind of understood how to go about making it using 'experience till next level' but can you explain the above code as it makes no sense to me.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:22AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month