• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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] Give Randomized Items?

PunkPhantom

"midna's a cat" -vinny, vinesauce
78
Posts
10
Years
    • Age 29
    • Seen Nov 20, 2016
    I'm trying to make something in my game that's similar to Pokestops in Pokemon Go, mainly they will give the player 3 or 4 random items a day or twice a day.

    What I don't know is how to generate random items. I'm sorry if this is already on the forum/wiki. How do I give the player a random item chosen from a specific selection of items?
     
    Last edited by a moderator:
    296
    Posts
    9
    Years
  • Code:
      def extractRandomItems
        maxItems=600 #Change 600 to your Item list maximum
        itemsArray=[]
        for i in 1...maxItems+1
          itemsArray[i]=i
        end
        items=[]
        loop do
          tempItem=itemsArray[rand(itemsArray.length)+1]
          items.push(tempItem)
          itemsArray.delete(tempItem)
          break if items.length==4
        end
        return items
      end
    If you call this function, it will returns items array. To store each item, you have to refer as follow:

    Code:
    item1=extractRandomItems[0]
    item2=extractRandomItems[1]
    item3=extractRandomItems[2]
    item4=extractRandomItems[3]
     
    Last edited:

    Telemetius

    Tele*
    267
    Posts
    9
    Years
  • TheMaster's answer is very useful and complete. Just to add in the discussion if you need to give an item based on a specific default list of items you could do something like this:

    Code:
    def extractRandomItem
        itemsArray=["POKEBALL","MEGABALL","ULTRABALL"]
        items=[]
        tempItem=itemsArray[rand(itemsArray.length)]
        items.push(tempItem)
        item=items[0]
        $PokemonBag.pbStoreItem(item)
      end

    And call it with: "extractRandomItem" so that it will only choose between those three items. Of course this is just a small adjustment of his script.
     
    Back
    Top