Seker Posted April 24, 2012 Posted April 24, 2012 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? Quote
Djkanna Posted April 24, 2012 Posted April 24, 2012 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; } Quote
Seker Posted April 24, 2012 Author Posted April 24, 2012 (edited) 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 April 24, 2012 by Seker Quote
Djkanna Posted April 24, 2012 Posted April 24, 2012 (edited) 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 April 24, 2012 by Djkanna Y ISNT THE TOUNGE SMILEY ":P" ? Quote
Seker Posted April 24, 2012 Author Posted April 24, 2012 Ahh okay, thank you again. I definitely am trying to learn. Most of it comes from studying other free mods and learning from that. Next will be literally stalking security options. Not looking forward to that. :P Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.