How to make a "Draw card" Skill?

I was looking for a way to implement a skill where you can draw a card from a deck. I think it can totally be achieved through some tiny scripting and custom formula bar, but I just don't know how to properly code it as a ruby noob.

Here's the logic of what I want:
1. You randomize a number from a set of numbers
2. You pull out the randomized number from 1. out of the set

For example, you randomize 5 numbers(1,2,3,4,5), and you got 2. The 2 is pulled out of the set. The next time you use this randomize skill, you'll randomize from just 4 numbers(1,3,4,5) without number 2, as if that card has been pulled out.

I figured that I could just keep randomize the same set of number again and again without pulling any number out, but it kinda defeat the purpose of drawing from a deck a bit.

The reason I post this here is because it's not really a full blown script, and I know that it must be able to do with formula bar, but I just don't know how, so I'd love some help in this aspect.
This is quite easy, at least if you want to use it on a basic level. First of all you can store all your numbers in an array, you can populate it directly when creating it, then you can shuffle it and get the N element of the array, where N is the number of drawn cards.

Code:
deck = Array.new(size) { |i| i } # This creates an array of elements from 0 to (size - 1)
drawn_cards = 0
deck.shuffle!

To draw a card you use something like this:
Code:
card = deck[drawn_cards]
drawn_cards += 1

In this example drawn_cards, deck and card can be each one of your game variables ($game_variables[some_id]). If you use them to store your deck (which I recommend), you should check whether or not the deck has already been initialized either using a switch or checking if it is an array already.
@Heirukichi That is a much easier way to do it than I expected. I have some questions tho.


Code:
deck = Array.new(size) { |i| i } # This creates an array of elements from 0 to (size - 1)
drawn_cards = 0
deck.shuffle!

Where should I put this? I imagine that it should be at the start of every battle since it just shuffle once, or should I put it in damage formula so it shuffle every time I use the skill? Or do you mean otherwise?
Also, can I store array in $game_variables?


Scratch that, I think I know how to make it work now. I'll just make an event in-game to initiate the deck and make a conditional branch in the Draw skill to also do .shuffle! if drawn_cards = deck.size - 1. Thanks!
Also, can I store array in $game_variables?
You might have missed this in my previous message, but you can store any of those variables I mentioned in $game_variables. This means that you can use $game_variables[id] = deck.

Where you put it depends on what you want to do. If you want the player to only draw cards until the deck is full, you should run that at the beginning of each battle, if, on the other hand, you want to let the player draw every time he/she uses the skill, you can put that in the skill itself.

In case you want to shuffle everything when using the skill, I recommend getting rid of the variable that keeps track of the amount of cards drawn since the first card will always be different and there is no need to actually draw. However, in that case, I do not recommend using an array at all, a random number is enough.
@Heirukichi Ah, sorry, I didn't see that you had replied before I go edit my last post, lol.
Yeah, I think I know now how to apply it for my situation. I'll just shuffle it every time battle start, then. I didn't miss what you said about storing deck in game_variables. I just didn't know at all that you could even store array in the game_variables, so it was a surprise for me, lol.

So, SOLVED!
@kairi_key oh, sorry then, I misunderstood what you said. In that case, just for reference, each variable in ruby is an object, which means that you can create a variable and store literally anything in it. What kind of object is stored there does not make any real difference unless you are actually using that value for something.

I hope this helps you to gain a better understanding of how ruby works. Sorry again for the misunderstanding.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-draw-card-skill.117162/