ID:272778   Jan 29 2009, 3:50 am Here's the basic functionality of gaining experiencein my game. You kill someone and if they're more than 6 levels below you (<6), the killer won't gain any experience. But any level higher than the difference of -6, the killer will gain experience in multipels of 7. ```mob/proc expGain(mob/M) var/difference = M.Level - Level if(difference>= -6) switch(difference) if(-6) src<<"+7 experience" return 7 if(-5) src<<"+14 experience" return 14 if(-4) src<<"+21 experience" return 21 if(-3) src<<"+28 experience" return 28 if(-2) src<<"+35 experience" return 35 if(-1) src<<"+42 experience" return 42 if(0) src<<"+49 experience" return 49 else src<<"+[7*difference] experience" return 7*difference else src<<"+0 expience" ``` So is there a more efficient way of doing that little tidit?
 <-> Jan 29 2009, 4:20 am ```if(difference < -6) exp = 0else exp = (difference + 7) * 7src << "+[exp] experience"return exp ``` I'm not sure that you intend your proc to work the way it does. Correct me if you do. Here's a table of experience gains by delta: ```delta | exp gain <-6 | 7*0 -6 | 7*1 -5 | 7*2 -4 | 7*3 -3 | 7*4 -2 | 7*5 -1 | 7*6 0 | 7*7 1 | 7*1 <-- wtf 2 | 7*2 ... ``` If you do want to drop back down at difference=1, you'd have to modify my snippet above like so: ```if(difference < -6) exp = 0else if(difference > 0) exp = difference * 7else exp = (difference + 7) * 7src << "+[exp] experience"return exp ```
 <-> Jan 29 2009, 7:28 am In response to PirateHead No, I didn't want it to drop back xD My bad. I didn't even think of it like that. So add a +7 into the else in the switch statement like so. ``` else src<<"+[7*(difference+7)] experience" return 7*(difference+7) ``` Any way to optimize that?
 <-> Jan 29 2009, 10:57 am In response to Mizukouken Ketsu Mizukouken Ketsu wrote: No, I didn't want it to drop back xD My bad. I didn't even think of it like that. So add a +7 into the else in the switch statement like so. ```> else> src<<"+[7*(difference+7)] experience"> return 7*(difference+7)> ``` Any way to optimize that? Yes lol: ```if(difference < -6) src << "0 experience" return 0else src << "+[7*(difference+7)] experience" return 7*(difference+7) ```
 <-> Jan 29 2009, 11:21 am In response to Mizukouken Ketsu ``` else var/X = 7*(difference+7) src<<"+[X] experience" return X ``` You save typing and it helps CPU.
 <-> Jan 29 2009, 11:31 am In response to Jeff8500 7 * (-6) + 7 = -35 They'd be losing experience. Bad.
 <-> Jan 29 2009, 11:44 am In response to Mizukouken Ketsu I took the formula straight out of your post. Besides, it would be 7 * (-6+7), anyway, so you would get 7.
 <-> Jan 29 2009, 1:01 pm In response to Jeff8500 Oh wow I gots order of operation issues x.x My bad. Thanks Jeff :)