Custom Model Card Decks – Tabletop Simulator

admin

TTS doesn’t have an elegant solution for a deck of cards that aren’t in a preset shape. This guide shows how to make your own card deck using custom models, an a*set bundle, and some scripting so that you can make cards whatever shape that you want!

Disclaimer

This guide requires slightly advanced knowledge of Tabletop Simulator, Unity, creating a*set bundles, and some light 3D modeling ability. It is not my intention to explain how to do those things. It also requires a little bit of LUA scripting, but there is a supplied example from the workshop that contains the commented version of the scripts, so modifying it for your needs should hopefully be easy. The intention of this guide is to show how to use those things to create a custom set of objects to mimic the behavior of a set of cards and a deck.

Get the Example Project!

Get this example project from the Workshop. It has a fully commented version of the scripts that need to be added to the Asset Bundle!

https://steamcommunity.com/sharedfiles/filedetails/?id=2784173462 – [steamcommunity.com]

Introduction

Have you ever found yourself making a game with strange shaped cards, and when you go to make them you get some rectangular border around the edges of it? Unseemly. Maybe you imported some custom models only to find out that you can’t stack them neatly, shuffle them, and deal them out to your players. This guide aims to be the remedy for that. In it we will be creating an a*set bundle that has the following features:

  • Appear to be a stack of a custom model
  • When the matching custom model is placed within it or removed, the stack will appear to gain or lose a copy of that model
  • Only accept the matching custom model
  • Only accept a maximum amount of the matching custom model
  • All features of a bag (shuffle, search, deal, etc.)

Essentially we are making a bag that looks like it is a normal deck of TTS cards.

Step 1: The Custom Model

Create a 3D model of your card in Blender. Do it however you wish. I generally create a custom card by importing an image of the card as a plane, creating a new vert, and then extruding it to draw the outline. Then I fill it to create a plane, and then extrude that plane to give it some thickness. There are other ways of doing it too. Then you UV unwrap the model and texture it. Again, there’s more than one way to skin a cat here. You can either create one texture per card, or you can make a single texture atlas for all of the card faces and make multiple versions of the model and move the UV position of the face on the atlas. I think either is fairly valid, but I prefer to do a different texture for each card and only use one model. DO NOT FORGET TO TRIANGULATE FACES.

Step 2: Importing Your Cards

Import the model in TTS. Click on Objects, and then Components > Custom > Model. Select your obj in Model/Mesh, and your first texture in Diffuse/Image, and your obj again in Collider if you wish. Presumably you want these to be playing cards, so change the Material to Cardboard in the Material tab. Then import the model.

Step 3: Creating the Deck Model

Once you’re back in Blender, have the model for your card open, and go to Object Mode. Look at your card from either the X or Y axis. Then right click on it and select Duplicate Objects (Shift+D). Immediately right click to keep the duplicate in the original position.

Step 4: Setting Up the Deck in Unity

Open the TTS Modding project in Unity. Create a folder for your deck model and texture under the Assets folder. Place your .fbx and texture inside of that folder.

Step 5: Adding Components and Building the Asset Bundle

Make sure the parent object of the model is selected and click Add Component > Animation. Drag the animation file you created for a full deck into the Animation field of the component. Under Animations, change the Size to the amount of animations that you have (In my case 6), and then drag each of your animations into the Elements that appear starting from the full deck down to empty.

Step 6: Setting Things Up in TTS

At this point you are ready to import into TTS. Go back in and select Objects > Components > Custom > AssetBundle. Browse to where the Asset Bundle was saved for the Main field. These get saved in the Unity project in a folder called “AssetBundles”.

Select your Asset Bundle, set its Type to Bag, and change its Material to Cardboard.

Custom Model Card Decks - Tabletop Simulator - Step 6: Setting Things Up in TTS - F814E38F5

At this point you can right click on your imported Asset Bundle and flip through the looping effects to make sure your animations are showing up properly

Custom Model Card Decks - Tabletop Simulator - Step 6: Setting Things Up in TTS - FE26B396E

Sometimes the material on your Asset Bundle can appear a little dark, you might need to adjust your material in Unity, or change the color tint in TTS on your cards to match it. Up to you.

Custom Model Card Decks - Tabletop Simulator - Step 6: Setting Things Up in TTS - 73436151B

Step 7: Scripting

Now you have a bag with some animations, but we need to script up all of the features. The example Workshop item has a commented version of the script inside of it, so please refer to that on how to set yours up, but I will cover the functions here briefly.

The script starts with “function onUpdate()”, this makes the game run a check every frame. Below that we have the block of code that dictates which Looping Effect should play for each amount of objects within the a*set bundle.

The line “if self.getQuantity() == 0 then” is stating if there are 0 items in the a*set bundle, then do the following line.

The following line “self.AssetBundle.playLoopingEffect(5)” states to play the 6th Looping Effect if the above Quantity is found within the contents of the Asset Bundle.

The next line “elseif self.getQuantity() == 1 then” states that if there is 1 item in the a*set bundle then do the action in the following line.

The following line “self.AssetBundle.playLoopingEffect(4)” states to play the 5th Looping Effect if the above Quantity is found within the contents of the Asset Bundle.

This continues until you reach a full deck. This would play LoopingEffect(0), or the first Looping Effect.

If you set up your Looping Effects in Unity so that a full deck uses the first Looping Effect, then it will always be LoopingEffect(0) in your script, and the number counts up as the amount of cards is lessened.

The second part of the script runs a check any time a player tries to add something to the a*set bundle.

The first line “ if (obj.getVar(“objectType”) == “ExCard” “ looks to see if the card has a unique identifier in its script. “ExCard” can be whatever you want, but that exact identifier needs to get defined in each of your cards.

The next line “and self.getQuantity() < 5)” checks to see if the a*set bundle has less than the maximum number of cards in it. Change the number 5 to whatever the maximum amount of cards you have in your deck is.

The following line “then return true end” will accept the item into the Asset Bundle if both conditions are met.

The final line “return false” will reject any items that don’t meet both of the defined conditions.

Next open up the scripting editor on one of your cards, and add the following line:

“objectType = “ExCard” “. ExCard is the unique identifier that the Asset Bundle looks for when someone tries to add an object to it. This can be anything you want as long as it matches what was called in the Asset Bundle’s script. This line needs to be applied to all cards in your deck.

At this point you should be able to save your game, save the scripts, and it should all work! Go ahead and save your object and import it into your game!

Custom Model Card Decks - Tabletop Simulator - Step 7: Scripting - 391D60610

Written by Hobbit Head

This is all we can share for Custom Model Card Decks – Tabletop Simulator for today. I hope you enjoy the guide! If you have anything to add to this guide or we forget something please let us know via comment! We check each comment! Don’t forget to check XIXGO.COM for MORE!

Share This Article