ID:177568
 
Ok here's a code for my game. How would I fill up the are in between without so much coding. How would I set up levels 21 - 29 keep everything the same but with out so much coding.





if(usr.mlevel == 20)
set src in view(1)
var/mlevel = rand(1,10)
if(mlevel == 20)
usr << "You obtain some iron ore!!!"
usr.mexp += rand(15,20)
usr.MLevelup()
new/obj/item/Iron(usr)
return
else
usr << "You fail to get anything!!!"
return
if(usr.mlevel == 30)
set src in view(1)
var/mlevel = rand(1,5)
if(mlevel == 30)
usr << "You obtain some iron ore!!!"
usr.mexp += rand(15,20)
usr.MLevelup()
new/obj/item/Iron(usr)
return
else
usr << "You fail to get anything!!!"
return
use if(usr.mlevel > 20)
In response to SkylineR34
will the stats change when you hit 30???
In response to Codesterz
oh wait sorry before i meant if

(usr.mlevel > 20 && usr.mlevel < 30)
use that for 20




(usr.mlevel > 30 && usr.mlevel < 40)
use that for 30 to 40


(usr.mlevel > 30)
use that for 30 and up
In response to SkylineR34
thanks...
You have a couple of flaws here, that will still be there when you apply the fix you were shown to use >= and < instead of ==.

The first flaw is that you've got a lot of redundant code. You should be taking as much info out of the repeated if statements as you possibly can. Just use if() to determine the chance of mining successfully, for instance, or use some formula. Let's pretend each turf or rock or what have you has a var called ironcontent, which goes from 0 (no iron) to 1 (standard amount of iron) or beyond. Let's say that's also the chance of a perfectly skilled miner (infinite level) getting ore, but the chance at level 10 is only, say, half that.
var/chance=1-0.5**(usr.mlevel/10)
chance=rand(0,round(chance*100000))/100000
if(chance>=ironcontent)
... // mine successfully
ironcontent*=0.9 // take out 10% of iron

That's one way of doing it, anyway. But above all else, you should do your calculations on mlevel first, and don't put the same big block of code in every if().

Here's the other problem:

if(usr.mlevel == 20)
set src in view(1)
var/mlevel = rand(1,10)
if(mlevel == 20)
usr << "You obtain some iron ore!!!"

Because you set the mlevel var from 1 to 10, it will never be 20. Thus your miner is doomed to failure.

Lummox JR
In response to Lummox JR
??? The mining works but the in between area's are still messing up. I set up level 1, 2, 3, 4, then I make a leap to Level 10. That inbetween area is the only thing that won't work.1-4 work 10 and up works but 5-9 wont work.
In response to Codesterz
You know, it'd be a lot easier to set up a formula to do your mining calculations for you. So you don't have 50 if statements. But, if you're determined on wasting 200 lines of code, I won't stop you.