Jump to content
MakeWebGames

Exp. Gain Help


Seker

Recommended Posts

So, I'm trying to make it so that attacking people gives you a SET amount of experience based on the person you're attacking's level. For example, if you attack a player the same level as yourself, you gain 200 exp.

I'm having a little trouble with the code, though. Just feel like there should be a cleaner way to do it, and wondering if my way is even correct.

At the moment, the base exp. gain is displayed like this:

$qe = ($r['level'] + 10) * $r['level'] * $ir['level'];
       $expgain = ($qe / 4);

 

Here's how my attempt at thinking shows up:

if $r['level'] < $ir['level']
		{
			$qe = 50;
		}
	else if $r['level'] = $ir['level']
		{
			$qe = 200;
		}
	else if $r['level'] = $ir['level'] + 1
		{
			$qe = 250;
		}
	else if $r['level'] = $ir['level'] + 2
		{
			$qe = 300;
		}
	else if $r['level'] = $ir['level'] + 3
		{
			$qe = 350;
		}

 

And etc., etc.

My question is, does this look like it actually works? Or is there a simpler way of going about this?

Link to comment
Share on other sites

If your intent on the 50 exp increase per each level higher;

if ($r['level'] < $ir['level']) {
   $expGain = 50;
} else if ($r['level'] == $ir['level']) {
   $expGain = 200;
} else {
   $baseline = 200;
   $expGain = (($r['level'] - $ir['level']) * 50) + $baseline;
}
Link to comment
Share on other sites

I just knew it. Thank you so much. This is the first time I've tried something on my own, and I figured it had to be much simpler than what I was doing. I am, literally, wet behind the ears when it comes to php, so I'm definitely learning as I go.

Now, I just need to figure out how to add a cap to that. As in, say, at ten levels ahead, it caps at whatever experience that gives. Perhaps something like....?

 

if ($r['level'] < $ir['level']) {
   $expGain = 50;
} else if ($r['level'] == $ir['level']) {
   $expGain = 200;
} else if {
   $baseline = 200;
   $expGain = (($r['level'] - $ir['level']) * 50) + $baseline;
} else if $r['level'] > $ir['level'] + 10 {
  $expGain = 700;
}

 

As in 700 would be the experience gain of the tenth level above, so it would stop there.

Edited by Seker
Link to comment
Share on other sites

All I can say is, at least your attempting to learn, unlike some. :p

We're here to help if needed.

Almost, for an if statement you need a condition.

if ($r['level'] < $ir['level']) {
   $expGain = 50;
} else if ($r['level'] == $ir['level']) {
   $expGain = 200;
} else if ($r['level'] >= ($ir['level'] + 10)) {
   $expGain = 700;
} else {
   $baseline = 200;
   $expGain = (($r['level'] - $ir['level']) * 50) + $baseline;
}
Edited by Djkanna
Y ISNT THE TOUNGE SMILEY ":P" ?
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...