|
| 17 Jun 2016 08:33 AM |
How would you want to do this? I don't want to create X number of children and select randomly because that's messy. I don't want to enter items into a table more than once.
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 17 Jun 2016 08:39 AM |
uhmmm this is pseudo code but maybe try something like this
local itemRarity = { ['Item1'] = 10, --Increasing == more common ['Item2'] = 2 }
local select = function() local pseudoTable = {} for Item,Rarity in next, itemRarity do for i=1,Rarity do table.insert(pseudoTable,Item) end end local value = math.random(1,#pseudoTable) return pseudoTable[value] end
local SelectedItem = select()
#code io.write('( ͡° ͜ʖ ͡°)') |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2016 08:41 AM |
Thought about doing that, was hoping there was a cleaner solution. Oh well.
|
|
|
| Report Abuse |
|
|
Isosta
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 17 Jun 2016 09:09 AM |
probably a good idea to create the pseudo table outside of the function if you plan on running the function more than once.
#code io.write('( ͡° ͜ʖ ͡°)') |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 17 Jun 2016 09:22 AM |
| I can make a Module for that if u like, or I could ask a friend, but yeah, there is no easy way out, remember that :P |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2016 09:43 AM |
No need for a module, it's not hard, it's just not as clean as I wish I could make it. Oh well.
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 17 Jun 2016 01:24 PM |
Lol... I could easily make so u could do something like this
require(Module) Choose({Stuff = 5; Other = 1}) --The higher the number the more common
And I mean WITHOUT having to even define 'Choose' all u gotta do is set it up with require() and ur set, but if u dont want it, then sure whatever u say lol :P |
|
|
| Report Abuse |
|
|