ID:1806097
 
Code:
mob/proc
Choose()
prob(90)
for(var/Item/I in src.NormalItems)
pick(I)
I == src.loc


Problem description:
How would you create a /proc that could pick from a list in the src list with a probability of the item being rare or not. like 99.5% is going to be a normal item and .5% its going to be rare? and how would you interpret the rarity var of the item into it if that would be more efficient.

Well with what you're got there, the actual way to go about using prob/pick for this would be to say:
mob/proc/Choose()
var/list/chosenList = pick(prob(P); NormalItems, prob(100 - P); RareItems)

// P => % of probability

// In this case it'd be the amount you'd want to attribute to the NormalItems\
list, as its likelihood of being chosen.


// You can slightly alter the above to\
pick(P;NormalItems, (100-P);RareItems)\
based on the info on pick/prob given in the F1 Help section


var/I = pick(chosenList) // no need for the for loop, this will pick out any element 'randomly'
// from within a list by itself if passed this way
I == loc


By the way, you might notice that i've ommitted the whole 'src.' when referencing the src's list or location later on. This is just due to the style in which i choose to program or code, in this case not spending time writing something unnecessarily: you see, writing out 'loc' -for instance- when intepreted/compiled is ultimately the same as typing 'src.loc'. I'm not sure if this is a good explanation, but basically there isn't a need to especially note the src. before vars, procs and so on because automatically DM will default you might want to define in this way to having this behaviour without you having to explicitly state as much.
The pick(prob()) format is really old, and isn't great for clarity; I wouldn't use it.
var/p = rand()
if(p < 0.005) // rare
item = pick(RareItems)
else if(p < 0.1) // uncommon
item = pick(UncommonItems)
else if(p < 0.9) // common
item = pick(NormalItems)
else
// 10% chance--no drop for you!
return