ID:266939
 
I know in some games it is random with certain things with certain items and stats you get... I was wondering, how would i set up a list for something like this so I can make it where everything has an equal chance? like with my game I'm having wands, but I only know how to have it where there are different odds of a certain part of the wand instead of the exact same odds.... anyone know how to solve that?
Eagle Madigan wrote:
I know in some games it is random with certain things with certain items and stats you get... I was wondering, how would i set up a list for something like this so I can make it where everything has an equal chance? like with my game I'm having wands, but I only know how to have it where there are different odds of a certain part of the wand instead of the exact same odds.... anyone know how to solve that?

I am not exactly sure what you mean, since using pick() automatically gives everything the same odds... unless you specify otherwise. However, here is a snippet I put together a while back that may help:
proc/wpick(list/l) // pick an item from a weighted list
var/list/picklist = list()
var/base_num = 0
for(var/i in l)
var/cur_num = base_num + l[i]
picklist[i] = list()
for(var/n in base_num to cur_num) picklist[i] += n
base_num = cur_num+1
var/roll = rand(0,base_num-1)
for(var/i in picklist)
if(roll in picklist[i])
return i


You can use it to pick items from a weighted list. Just make a list that looks like this:
list("small chance"=1, "normal chance"=5, "large change" =10)


And call wpick with the list as the arguement. It will return an item in the list. You can give all items the same change or weigh them however you like.
In response to Ebonshadow (#1)
umm... ooook, I think I'll clear it up... I accually don't need a list then and I got some misinformation... what I mean is... what would I do to change this to where it has even odds:

usr.random = rand(1,1000)
if(usr.random == 1000)
alert("A Phoenix Feather in your wand can do great things, [usr]. Let's see how you do with it.")
usr.Core = "Phoenix Feather"
usr.Core2 = "1"
usr.loc=locate(48,3,1)

if(usr.random < 999 && usr.random >= 899)

alert("A Phoenix Feather in your wand can do great things, [usr]. Let's see how you do with it.")
usr.Core = "Phoenix Feather"
usr.loc=locate(48,3,1)
usr.Core2 = "1"
if(usr.random < 898 && usr.random >= 700)
alert("A Dragon Heartstring is a PERFECT match for you, [usr]!")
usr.Core = "Dragon Heartstring"
usr.loc=locate(48,3,1)
usr.Core2 = "1"
if(usr.random < 699 && usr.random >= 400)
alert("Unicorn Hair. Of course!")
usr.Core = "Unicorn Hair"
usr.loc=locate(48,3,1)
usr.Core2 = "1"
if(usr.random < 399 && usr.random >= 100)
alert("A Dragon Heartstring is a PERFECT match for you, [usr]!")
usr.Core = "Dragon Heartstring"
usr.loc=locate(48,3,1)
usr.Core2 = "1"
if(usr.random < 99 && usr.random >= 1)
alert("Unicorn Hair. Of course!")
usr.Core = "Unicorn Hair"
usr.loc=locate(48,3,1)
usr.Core2 = "1"

usr.Core2 = 1

I know there are some duplicate things, but that was to even things out according to my old coder...
In response to Eagle Madigan (#2)
You know, if you went from lowest to highest, using else/if, it would work out better, for example...

var/random = rand(1,10)
if(random < 5) A()
else if(random < 7) B()
else C()

But to have even chances...

switch(rand(1,10))
if(1)
//blah blah blah
if(2)
//blah blah blah
if(3)
//etc...