• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Need help with a piece of my random item code

  • 6
    Posts
    1
    Years
    • Seen Mar 1, 2024
    so i found this (Giving a random item from a list) and i tweaked it a bit
    But i've been testing it in game and the only Items i was getting was from the first array (commonItems), and i dont know if i did it correctly
    Ruby:
    def chooseRandomItemM(qty=1)
      # Array of items
      commonItems = [
      :IRONBUTTON,
      :IRONORE,
      :IRONORE,
      :EXPCANDYXS
      ]
    
      rareItems = [
      :ENERGYROOT,
      :ENERGYROOT,
      :BIGNUGGET,
      :NUGGET,
      :NUGGET,
      :TMMATERIAL,
      :TMMATERIAL,
      :ICYROCK,
      :HEATROCK,
      :EXPCANDYS
      ]
     
      evoItems = [
      :DAWNSTONE,
      :DUSKSTONE,
      :FIRESTONE,
      :ICESTONE,
      :LEAFSTONE,
      :MOONSTONE,
      :SUNSTONE,
      :THUNDERSTONE,
      :WATERSTONE,
      :EXPCANDYL
      ]
     
      fossilItems = [
      :ARMORFOSSIL,
      :CLAWFOSSIL,
      :COVERFOSSIL,
      :FOSSILIZEDBIRD,
      :FOSSILIZEDDINO,
      :FOSSILIZEDDRAKE,
      :FOSSILIZEDFISH,
      :HELIXFOSSIL,
      :JAWFOSSIL,
      :OLDAMBER,
      :PLUMEFOSSIL,
      :ROOTFOSSIL,
      :SAILFOSSIL,
      :EXPCANDYM
      ]
     
      megaItems = [
      :ABOMASITE,
      :ABSOLITE,
      :AERODACTYLITE,
      :AGGRONITE,
      :ALAKAZITE,
      :ALTARIANITE,
      :AMPHAROSITE,
      :BANETTITE,
      :BEEDRILLITE,
      :BLASTOISINITE,
      :BLAZIKENITE,
      :CAMERUPTITE,
      :CHARIZARDITEX,
      :CHARIZARDITEY,
      :DIANCITE,
      :GARCHOMPITE,
      :GARDEVOIRITE,
      :GENGARITE,
      :GLALITITE,
      :HERACRONITE,
      :HOUNDOOMINITE,
      :KANGASKHANITE,
      :LATIASITE,
      :LATIOSITE,
      :MAWILITE,
      :MEDICHAMITE,
      :METAGROSSITE,
      :MEWTWONITEX,
      :MEWTWONITEY,
      :PINSIRITE,
      :SABLENITE,
      :SALAMENCITE,
      :SCEPTILITE,
      :SCIZORITE,
      :SHARPEDONITE,
      :SLOWBRONITE,
      :SWAMPERTITE,
      :TYRANITARITE,
      :VENUSAURITE,
      :EXPCANDYXL,
      :EXPCANDYXL
      ]
     
      # Randomly select item from above array
    m = rand(1..13)
    if m = (1..4)
      pbReceiveItem(commonItems[rand(0...commonItems.length)],qty)
    elsif m = (5..7)
      pbReceiveItem(rareItems[rand(0...rareItems.length)],qty)
    elsif m = (8..10)
      pbReceiveItem(fossilItems[rand(0...fossilItems.length)],qty)
    elsif m = (9..12)
      pbReceiveItem(evoItems[rand(0...evoItems.length)],qty)
    else
      pbReceiveItem(megaItems[rand(0...megaItems.length)],qty)
    end
    end
     
    Last edited:
    So first, why the code isn't working.
    This m = (1..4) means set m to (1..4), rather than check it against it, with ==. Since everything in Ruby is truthy, except false and nil, the first if is always the one that runs.

    I would replace this with a case when statement, as I know that works with ranges (I'm not sure m == (1..4) works).
    Ruby:
    case rand(1..13)
    when 1..4
      pbReceiveItem(commonItems[rand(commonItems.length)],qty)
    when 5..7
      pbReceiveItem(rareItems[rand(rareItems.length)],qty)
    when 8..10
      pbReceiveItem(fossilItems[rand(fossilItems.length)],qty)
    when 9..12
      pbReceiveItem(evoItems[rand(evoItems.length)],qty)
    else
      pbReceiveItem(megaItems[rand(megaItems.length)],qty)
    end
     
    So first, why the code isn't working.
    This m = (1..4) means set m to (1..4), rather than check it against it, with ==. Since everything in Ruby is truthy, except false and nil, the first if is always the one that runs.

    I would replace this with a case when statement, as I know that works with ranges (I'm not sure m == (1..4) works).
    Ruby:
    case rand(1..13)
    when 1..4
      pbReceiveItem(commonItems[rand(commonItems.length)],qty)
    when 5..7
      pbReceiveItem(rareItems[rand(rareItems.length)],qty)
    when 8..10
      pbReceiveItem(fossilItems[rand(fossilItems.length)],qty)
    when 9..12
      pbReceiveItem(evoItems[rand(evoItems.length)],qty)
    else
      pbReceiveItem(megaItems[rand(megaItems.length)],qty)
    end
    thanks so much
     
    Back
    Top