In this lesson, we will be looking at the process of creating custom action cards and using them in Hero Realms Lua games. This process involves two major areas that require you to build some skills by practice to really get the hang of it. The first is about how to design the card’s visual layout and develop a good system for conveying to the player, what the card can do. The second involves writing the code to make the card actually function as desired.

When designing a new card, it is important to think through how it will work. For an action, it is normally played once per turn and then sent to the discard pile at the end of the turn. There are many ways you can make a card function using the available Lua triggers but when you first start learning, you should stick to card effects/abilities that occur on the turn the player uses it. This is because things that want to trigger when your opponent does something (like stun your champion) will take effect on your opponent’s turn instead of yours. You would need to use a buff applied to yourself to trigger on the next turn and though that is not terribly hard it is just not a great place to begin learning. Effects like drawing cards, and gaining gold/combat are great starter effects.

This lesson once again has a premade Lua file you can download and try yourself. All of the comments in the file are trimmed to highlight the areas code was added to make the new action card and put it in a player’s deck.

The Time Consuming Part

As I mentioned previously, creating a layout for a custom card is probably going to take you the most amount of time (it does for me) because you have to rely on some tools that make things easier in some ways but harder in others. You need to decide on a few things such as,

  • The card type (in this case, an action)
  • The card art
  • The card Frame (or border)
  • The card text explains what it does
  • If the card will have a faction

Using this information with the Card Designer really should have its own lesson but you need to know how to use it in order to make a new card so I include all the details in this lesson. This is what it looks like when you open it from the develop page. It always shows the same example card at the start.

When you change the text in the fields on the left side and click “Generate,” it will render the card on the right. The top field is for changing the art (art options are found in the Lua doc), the middle is for the frame/border of the card (frame options also in the Lua doc), and the large bottom box is for the xmlText that makes the card effect language. The idea is to edit the xmlText here until you like how the card looks and then copy and paste the xmlText into the Lua file. This is the tricky part, the card designer is great but it has no “undo” button so if you make a mistake and your card no longer renders (blank white image) you have to start from scratch. It also does not save the text when you close it so make sure to copy what you need before closing it.

To make this process easier, I always start by finding a card layout example in the Lua doc that is close to what I want to make, pasting it into the bottom field, and then tweaking it slowly, making sure to copy it all before making any large changes to have a fallback.

For this lesson, I started with this one.

A quick word about sprites! You can use some built-in images of things like combat/gold/healing/sacrifice/etc. in the layouts for your cards. You just need to format the xmlText to use something like {gold_4}, {wild}, {scrap}, or {combat_4} as seen in the above image to make them appear on the card. You can find the list of sprites in their own section in the Lua doc.

Once you have the card looking the way you want in the card designer, you can copy the xmlText field and paste it into the card layout formatted like this. I know I have not explained what a card layout is yet so save the text you copied somewhere you can go back to it for now and read the next section.

In the lesson #2 Lua file, you will find a declaration for a new action card “Teach Them a Lesson” which as two sections, a layout and the card object data. Here is a snippet of the code that defines the layout. You will see a place to put the art/frame/type and the correct way to format the xmltext.

The layout above looks like this in the game. Don’t judge me for my game balancing, I just made a card that was interesting to play with.

Now to Make it Work

If you were to try and use this card at this point it would have a layout but not do anything when played. We need to make a function that creates the card object which starts like this.

Inside this function, you put the layout generation code and a new createActionDef() with data to create the card object. Below is an example of some of the values that need to be included.

Next, you assign the layout that was created to the card like this so the card will display correctly.

Then you need to create the abilities/effects the card will have. In the above example, the card has two abilities, one that triggers on play and the other triggers when the player sacrifices it.

At this point, the card is fully functioning but there are a few small details that need to be done to actually get the card in a player’s deck. The first thing to do is register the new card because HR doesn’t know about it unless you do. The registration goes inside this setup function.

Lastly, it’s time to put the card in a deck! You do this the same way we did in the last lesson by adding it to a player’s deck when the player data is built.

You can now play the script and see if you can beat the AI with your shiny new action card. As always, feel free to reach out with any questions and I hope to see you back for Lua Lesson #3

One response to “Lua Lesson #2: Custom Action Cards”

  1. […] same process of taking an example card from the Lua doc and reworking it with the card designer (Covered in lesson #2) to fit what you are trying to make. For this lesson, I once again started with this because I […]

    Like

Leave a comment

Trending

A WordPress.com Website.