Author Topic: Level System Help  (Read 967 times)

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Level System Help
« on: October 23, 2010, 05:48:10 PM »
Hello everyone, I am making a game with lots of skills like woodcutting etc. And I want to create a function that can be called and it calculates the skill level. Here is the function:

Code: [Select]
function calculateSkillLevel($exp) {

}

Now, my issue is, I want to do this an easier way than I did before. Which was basically a bunch of if and if else statements going until it find the actual level.

I was thinking maybe a for loop. What would you guys think?
It would of course calculate the EXP needed for next level using an equation. The default level being 1.

Offline pixlepix

  • Level 12
  • *
  • Posts: 90
  • Reputation: +0/-0
    • View Profile
Re: Level System Help
« Reply #1 on: October 23, 2010, 08:22:32 PM »
wouldnt it be better to store the skill levels in a database?

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Re: Level System Help
« Reply #2 on: October 24, 2010, 01:51:25 AM »
I thought it would be better for it to go off of an equation. The initial creation would be easy and if I decided to change it later, it would be easy as well.

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Level System Help
« Reply #3 on: October 24, 2010, 03:41:47 AM »
Not sure what you want...
Quote
It would of course calculate the EXP needed for next level using an equation
return xpNeededForNextLevel-currentXp

currentXP has to be known, level if unknown should be easily determinable based on the formula for xpNeededForCertainLevel

perhaps you need to tell us more specifics about your system, data etc.
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Level System Help
« Reply #4 on: October 24, 2010, 03:50:54 AM »
Two way formula for "level^2" shape.

Code: [Select]
for($lvl=1;$lvl<=10;$lvl++)
{
$exp=pow($lvl,2);
echo "[$lvl]$exp, ";

$lvl=sqrt($exp);
echo "[$lvl]$exp, ";

echo'<br>';
}

echo'<br>';

for($exp=1;$exp<=100;$exp+=10)
{
$currentlvl=(int)sqrt($exp);
$lvl=$currentlvl+1;
$nextexp=pow($lvl,2);
$needexp=$nextexp-$exp;
$lvl=sqrt($nextexp);
echo "[$currentlvl]$exp need:$needexp for [$lvl], <br>";
}

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Re: Level System Help
« Reply #5 on: October 24, 2010, 05:07:26 AM »
Not sure what you want...
Quote
It would of course calculate the EXP needed for next level using an equation
return xpNeededForNextLevel-currentXp

currentXP has to be known, level if unknown should be easily determinable based on the formula for xpNeededForCertainLevel

perhaps you need to tell us more specifics about your system, data etc.

When the function is executed $exp will equal the amount of experience the user already has. I then want to use an equation that goes through the levels till it finds the right one.

Now that I think about it, would it just be safer to include it in the database? Since perhaps it could be heavy on the server?

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Level System Help
« Reply #6 on: October 24, 2010, 05:16:01 AM »
That's just repetition of what you said, no new info... why not you use what I wrote? Anyway it would be better to pass the level too (which is surely known) to remove the problem

Is there a reason for keeping it in database? I'd store data in database, not mechanics
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline saljutin

  • Level 22
  • *
  • Posts: 266
  • Reputation: +6/-0
    • View Profile
Re: Level System Help
« Reply #7 on: October 24, 2010, 05:36:29 AM »
you are looking for some formula right?
so lets say if you take y=x^2
y ... exp needed for that level
x ... level

now u turn that around $X=$exp^(1/2)
-return floor($X);
$X ... your level

what kind of formula ... you decide
I suggest you use excel and create a graph so you can see how it develops
y=x^Z ... for Z I recommend value between 1 and 2, OR not? depends on how fast you want user to level :)

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Level System Help
« Reply #8 on: October 25, 2010, 12:42:29 PM »
I started my design on this system over the weekend...  here were my thoughts.

I concluded it would be best to store the current level of each skill in the database for each user (ie, user 1 has woodcutting lvl 1, rock mining lvl 2 :: user 2 is Woodcutting lvl 2, rock mining lvl 3 :: and so on).  This requires more code, and it has to be run each time a user gains or loses xp, but its better than the alternative.  If you were to loop through how much experience you have every single time you needed to reference a users level, you'd be stuck with a major tax on your server.  Not only that, but in my experience, it becomes cumbersome to manage.

What you do need is a function that takes in your current level, and returns how much exp is needed for the next level.  This also requires you to keep your current exp in each skill. 

This brings me to another dilemma that I believe I've fixed.  When it comes to leveling in terms of fighting monsters, you want monster lvl 2 to yield more exp than monster level 1.  This is especially true if monster level 2 deals significantly more damage.  However, if you double exp from monster level 1 to monster level 2, you'll soon have an exp system that grows wildly out of control (we're talking trillions+ of exp points very very soon).  So, how do you keep the user fighting higher level monsters while having a system that make sense?  The answer I came up with here is to increase xp rewards by 5% from each enemy (slow exponential growth), and divide the reward by (your level - monster level + 1, minimum value 1).  This will let you reasonably scale your xp through 350 levels, entice players to keep attacking up, and provides a system that appears logical.

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Re: Level System Help
« Reply #9 on: October 26, 2010, 01:20:50 PM »
Now that is a detailed and lengthy response. I thought that it might be taxing on the server to loop through but I really wasn't sure. I will store the experience, and level in the database.

This is actually probably more effecient for me because on my game, a player sets to working for an hour or more and then just logs off and comes back. So I wouldn't even be calling the database very often.

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Level System Help
« Reply #10 on: October 26, 2010, 01:41:59 PM »
One other added benefit I failed to mention here is updating.  Many times, you'll want to give a resource (wood, diamonds) in proportion to the number of level of buildings (mills, mines).  It is much easier to update when you have the level stored as opposed to just the raw exp.

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Level System Help
« Reply #11 on: October 28, 2010, 03:17:05 AM »
It's imho not much taxing - though as I said I see no reason not to use inversed formula - but it's much better to store level, not just for this but then you can also query based on their levels (e.g. list me all players with any skill with level higher then 10)
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal