Playing Cards
A script for RPG Maker VX Ace
"Never lost a fair game... or played one." ~ Twisted Fate, League of Legends
What does this script do?
The short answer is that this script makes it much, much easier for you to create card games in RPG Maker.
It provides the logical abstraction for a 52-card deck of playing cards or lets you build your own deck, then provides the tools to let you draw a card from the deck (and remove it from the deck if desired), show a picture of the card, and use information about the card (such as its value and suit), all using relatively simply one-line script calls.



Couldn't I just event a card game without this script?
Aside from saving you hundreds or even thousands of event commands worth of effort and processing power, this script provides several useful tools that would be difficult or impossible to accomplish with eventing alone:
Is this script useful for other minigames besides card games?
Absolutely! This script should have some useful applications in any minigame or event where you use the RNG in more-than-basic ways.
For example, if you want to give the player four random items from a set of ten, without duplicating any of the items, you can create a "deck" of ten item IDs, draw four "cards", and use the item IDs drawn to award the four items.
Can I change the player's deck of available cards during the game (to make a CCG or a game like Triple Triad, for example)?
This script is not designed for such a purpose, but if you're very clever, you might be able to make it work with just a bit of extra scripting.
Offhand, I think you'd probably want to rig the $game_party.deck array at the beginning of the game, and use the $game_party.addback method to give the player access to new cards. If you're going to leave the Removal option as 'true', you'll likely need to track the player's deck within a match and their collection of cards (which you would need to add a new array for) as separate arrays.
What setup is required for this script?
The basic setup is very easy. Simply choose which variables/names you want information about the drawn card in:
You can also change the value of the Removal option to your liking. If true, after a card is drawn it is automatically removed from the deck (until you manually add it back in or shuffle the deck). If false, the drawn card stays in the deck and can be drawn again.
If you want to show pictures of the cards that are drawn, you will need to import a picture for each card into your Graphics/Pictures folder. The name of the picture should be Cards_1.png, Cards_2.png, etc., unless you have changed the Pic_prefix or Pic_extension options (see below).
There are some more options in the "Advanced Setup" area. What do they do?
These options can be left alone, or changed to customize the script to your liking:
Picture_id, Default_x, and Default_y can be used to set defaults for display properties when you show the Picture of a drawn card.
Okay, I've completed the setup. Now how do I use all these nifty tools?
Simply call any one of the following six methods using the "Script..." command in any desired Event or Common Event. (Some methods have additional names by which they may be called; see the "How to Use this Script" documentation within the script for more info.)
You mentioned being able to reference a card's Name, Value, etc. in a message box?
Since this information is stored in the Holder variables (and Holder name), you can reference it just like any other variable or name. Booyah!
Use \V[x] where x is the (ID/Value/Suit) Holder Variable that you specified to pull its value into a message box.
Use \N[x] where x is the Actor ID you specified for the Name Holder option to pull the card's name (e.g. "the 7 of Diamonds") into a message box.
Terms of Use
Feedback and suggestions are always appreicated. Hope you guys enjoy using my script to enhance your game!
A script for RPG Maker VX Ace
"Never lost a fair game... or played one." ~ Twisted Fate, League of Legends
What does this script do?
The short answer is that this script makes it much, much easier for you to create card games in RPG Maker.
It provides the logical abstraction for a 52-card deck of playing cards or lets you build your own deck, then provides the tools to let you draw a card from the deck (and remove it from the deck if desired), show a picture of the card, and use information about the card (such as its value and suit), all using relatively simply one-line script calls.



Couldn't I just event a card game without this script?
Aside from saving you hundreds or even thousands of event commands worth of effort and processing power, this script provides several useful tools that would be difficult or impossible to accomplish with eventing alone:
- Remove cards from the deck as they are drawn, if desired
- Get information about the value and suit of a randomly-drawn card using a single-line script call
- Show a picture of that randomly-drawn card using a single-line script call
- Show the name (or value) of that randomly-drawn card in a single message box
- Automatically convert a playing card's value for use in a minigame; e.g., make all Jacks, Queens, & Kings worth 10 when playing Blackjack
Is this script useful for other minigames besides card games?
Absolutely! This script should have some useful applications in any minigame or event where you use the RNG in more-than-basic ways.
For example, if you want to give the player four random items from a set of ten, without duplicating any of the items, you can create a "deck" of ten item IDs, draw four "cards", and use the item IDs drawn to award the four items.
Can I change the player's deck of available cards during the game (to make a CCG or a game like Triple Triad, for example)?
This script is not designed for such a purpose, but if you're very clever, you might be able to make it work with just a bit of extra scripting.
Offhand, I think you'd probably want to rig the $game_party.deck array at the beginning of the game, and use the $game_party.addback method to give the player access to new cards. If you're going to leave the Removal option as 'true', you'll likely need to track the player's deck within a match and their collection of cards (which you would need to add a new array for) as separate arrays.
What setup is required for this script?
The basic setup is very easy. Simply choose which variables/names you want information about the drawn card in:
- Card_holder is the variable that holds the card's ID (its "place" in the deck - e.g., in a 52-card deck the 2 of Clubs has ID 1 and the Ace of Hearts has ID 52).
- For example, if you want Variable 382 to hold the ID of the last card drawn, set the Card_holder option to 382.
- Value_holder is the variable that holds the card's value - this is probably the variable you'll reference most often from your events.
- Suit_holder is the variable that holds the card's suit.
- Name_holder is the ID of the actor whose name field will store the name of the last card selected.
You can also change the value of the Removal option to your liking. If true, after a card is drawn it is automatically removed from the deck (until you manually add it back in or shuffle the deck). If false, the drawn card stays in the deck and can be drawn again.
If you want to show pictures of the cards that are drawn, you will need to import a picture for each card into your Graphics/Pictures folder. The name of the picture should be Cards_1.png, Cards_2.png, etc., unless you have changed the Pic_prefix or Pic_extension options (see below).
There are some more options in the "Advanced Setup" area. What do they do?
These options can be left alone, or changed to customize the script to your liking:
- Deck Size lets you change the total number of cards in the deck.
- The Suits array lets you change the name of each Suit. The number of suits is not fixed at 4; you may add or remove suits as you please.
- The Values array lets you change the name of each Value (such as "5" or "Ace". The number of values is not fixed at 13; you may add or remove values as you please.
- The Conversion Value arrays allow you to automatically convert the Values of drawn cards before they are passed to your storage variables. For example, in Blackjack, the values for cards from lowest to highest are [2,3,4,5,6,7,8,9,10,10,10,10,11]. You can use these arrays to "autoconvert" a card's value rather than tediously create the logic using event commands.
Picture_id, Default_x, and Default_y can be used to set defaults for display properties when you show the Picture of a drawn card.
- Pic_prefix and Pic_extension can be modified if you want to use a different naming convention or file type for Pictures of cards.
- The Namestring method can be used to change the way that text names for the cards are created. Leave this one alone if you don't have any coding background.
Okay, I've completed the setup. Now how do I use all these nifty tools?
Simply call any one of the following six methods using the "Script..." command in any desired Event or Common Event. (Some methods have additional names by which they may be called; see the "How to Use this Script" documentation within the script for more info.)
- $game_party.draw_card(game) randomly draws a card from the deck, and automatically stores information about the card that was drawn. If the "Removal" option is set to True, the drawn card is removed from the deck.
- "game" is an optional integer that specifies which "Conv_Value" array (if any) will be used to automatically convert the value of the card.
- Once you've used this call, you can immediately use the "Holder" variables (Value_holder, Suit_holder, etc.) and name in subsequent events, which should make your eventing process far easier.
- $game_party.show_card(picture_number, x, y) shows a picture of the last card that was drawn.
- "picture_number", "x", and "y" are all optional integers that specify the Picture Number, x-coordinate, and y-coordinate for the picture (if not provided, the default values will be used).
- To erase the picture of the card, simply use the "Erase Picture" event command and use the picture_number that you chose here.
- $game_party.pullcard(card)removes a card from the deck so that it may not be drawn until added back into the deck.
- The "card" integer is used to specify which card to remove. For example, in a standard deck, $game_party.pullcard(1) will remove the 2 of Spades from the deck, while $game_party.pullcard(52) will remove the Ace of Hearts.
- $game_party.addback(card) adds a card into the deck so that it may once again be drawn.
- The "card" integer is used to specify which card to add.
- $game_party.shuffleadds all cards back into the deck. You'll probably want to use this command at the beginning or end of a hand in most games.
- $game_party.cards_remaining(variable) returns the number of cards remaining in the deck. This could be useful if you need your minigame to shuffle the deck when there are a certain number of cards (or no cards) remaning.
- "variable" is an optional integer that specifies a Variable to which save the number of cards remaining, in case you need to use it later.
- "variable" is an optional integer that specifies a Variable to which save the number of cards remaining, in case you need to use it later.
You mentioned being able to reference a card's Name, Value, etc. in a message box?
Since this information is stored in the Holder variables (and Holder name), you can reference it just like any other variable or name. Booyah!
Use \V[x] where x is the (ID/Value/Suit) Holder Variable that you specified to pull its value into a message box.
Use \N[x] where x is the Actor ID you specified for the Name Holder option to pull the card's name (e.g. "the 7 of Diamonds") into a message box.
Terms of Use
- Free to use for non-commercial projects - just credit me.
- Contact me first before using in commercial projects.
- Further details (as well as a bit of extra help with the setup) are provided in the script itself.
Feedback and suggestions are always appreicated. Hope you guys enjoy using my script to enhance your game!


