Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Randomise items taking rarity into account — Gideros Forum

Randomise items taking rarity into account

totebototebo Member
edited May 2017 in General questions
I'm building a rarity system, where I have a bunch of items, each with a rarity attached to them, spanning from 1 (common) to 5 (very rare).

To get a random item I create a table with lots of 1s, a bit less of 2s etc and one of each 5. Then table[math.random(#)] that table.

The problem is that this is terribly inefficient, since the table contains hundreds/thousands of items, because I want 1 to be very common and 5 to be very rare indeed.

Is there a better way of doing this?
My Gideros games: www.totebo.com

Comments

  • talistalis Guru
    edited May 2017
    Use simple RPG dice logic;
    Roll a dice with 100 sides;
    1-40 ----->1 (common item)
    40-70 ----->2 (less comon)
    70-90 ------> 3 (magical item)
    90 - 98 ------> 4 (rare item)
    98 - 100 -----> 5 (legendary item)

    Note: Change the interval how you want, and arrange the possibility. In addition you can change the rarity possibility easilly by events, like power ups, special magical items.
    Sword of luck - Magical property increase chance of finding rare items %5
    :D

    Likes: hgy29, totebo

    +1 -1 (+2 / -0 )Share on Facebook
  • talistalis Guru
    edited May 2017
    Just for info if you are interested; dungeons and dragons have this method of deciding your talent actions if it succeeds or not and the effect of your action in this way.
    1-Event dice - Talent dice (usually 100 sides)
    2-Effect dice -Result dice (can change but let us assume 6 sides)

    Player wish: I want climb to tree.
    Note :Player agility points are so low.
    So first we need to decide about the action: Roll a dice and let us assume it is 10 out of 100 .
    Hence 10 is so much low it means that there will be a bad consequence of his action and not a successful event. Player can not climb a tree.
    Roll a effect dice;
    1-3 ---> 3 hp loss
    4-5---> 5 hp loss, arm hurts.
    6-----> broken leg, unconscious for 2 turns

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • stetsostetso Member
    edited May 2017
    There is also the weightedchoice() function in lume which I use for a similar task, it works very well for me :) you might have to turn around your numbering though because the function will return entries with a higher number more often...
    Also, here is some help to design your own probability distribution from dice-rolls. Maybe you can create something that works well for your system.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited May 2017
    Would just using a random number be wrong???
    local items = {
      tier5 = {}, -- best items
      tier4 = {}, -- very good items
      tier3 = {}, -- good items
      tier2 = {}, -- okay items
      tier1 = {}, -- crap items
    }
     
    local random = math.random
    local tier
    local r = random()
    if r <= 0.05 then -- super fantastic!
      tier = items.tier5
    elseif r <= 0.10 then -- pretty good
      tier = items.tier4
    elseif r <= 0.20 then -- okay
      tier = items.tier3
    elseif r <= 0.50 then -- so so
      tier = items.tier2
    else -- haha, you got vendor trash <img class="emoji" src="http://forum.giderosmobile.com/resources/emoji/lol.png" title=":D" alt=":D" height="20" />
      tier = items.tier1
    end
     
    -- now you have your table of items so choose an item from that table and spawn it
    This is how I am choosing pools of item modifications for my ARPG game. It's only just starting to be developed but currently this seems to work pretty well.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    Wow guys, amazing responses! This is more than enough for me to make something that works for my game.

    Likes: antix

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.