Tabletop Simulator

Tabletop Simulator

Scripted Hold'em Poker Table
This topic has been locked
Skor  [developer] 28 Apr, 2016 @ 7:58am
Update 04-28-2016
I pretty much completely rewrote the findDealer function, and changed how the game keeps track of players. The players table is now used throughout the game to keep track of players still in, and removes players who have folded. This functionality was implemented for the new Action button (detailed below)

I also made some changes to the layout. I moved the White hand back to the default position, and moved the sample chests behind the side pot. I also changed the pot trays to custom model trays, and added counters which display the pot value (usually). I added a credits tab to the notebook in which I give credit to the people who made the custom models that I used.

I added an "Action" button. During the game, an "Action" 3dtext will pulsate in front of the player whose turn it is to act. The Action button advances it to the next player. It also prints "Action on [Color]" in the chat window. It will also print in the chat window the current pot value and current bet in the event that either of those are increased when the action text moves. Note that the action function was written to assume that afk players still pay blinds and act as dealer, so if you skip blinds over afk players, it will start the action text on the wrong player, and this is not a bug.

If you do not wish to use the Action button, you can flip it over and click the "Toggle" button on the bottom of the reversi chip. This will hide the text and prevent it from popping up again until you toggle it back on. Additionally, if you want to disable the action text by default, simply find the global variable "actiontoggle" near the top of the script, change "true" to "false", and save the game.

The digital counters will display the total pot value (including current bets, chips in the main pot, and chips in the side pot). It updates any time the Action button is clicked (even if toggled off), bets are collected with the button, and the Deal button is used to deal the next stage of the game. However, the counters are not perfect in their display. Because they only have 4 digits, and bets can easily exceed $10,000, I had to use two counters. Unfortunately, it's not possible to display leading zeroes, so if, for example, the pot is $10,100, the counters together will display "1 100"; or if the pot is $10,000 exactly, they will display "1 0".

The deck now moves to the center of the table while it deals players' hands. This was done to prevent cards from being intercepted if they happen to get close to another player's hand zone while flying through the air.

Another potential issue that you may run into (if you have high FPS) is premature folding of player(s). In a three-player game, when dealing the hands, it would think the dealer had folded and remove him from the players list because the cards had not yet reached his hand before the action function was called. I fixed this by adding a delay of 40 frames in the function holeCoroutine. If you run into this problem because you have high FPS, just go into the script and increase that frame delay.
Last edited by Skor; 29 Apr, 2016 @ 7:51am
< >
Showing 1-6 of 6 comments
Kowgan 28 Apr, 2016 @ 4:07pm 
What a big update. Thank you for your effort, I love the new features, especially the pulsing action 3D text.

Would it be too hard to set a toggleable option for the Action button to skip players holding the AFK button? IMHO it doesn't make much sense that you expect AFK players to pay the blinds, since by default, the Deal button already skips AFK players when dealing cards.

I also noticed you haven't scripted the Sidepot yet. As I understand scripting this can become too complicated very easily, I have some ideas that may be worth of discussion. Poke me if you're interested. :)
Skor  [developer] 28 Apr, 2016 @ 5:12pm 
Thanks for your comment Kowgan.

I'm not sure if I want to add yet another button; I'm not really sure where I'd put it. Maybe I'll make a whole set of "Options" buttons in the future. But for now, if you want the blinds to skip afk players, you can make one simple change to the script. Find the following loop in the function getOrderedListOfPlayers:
for i, v in ipairs(afk) do for j, w in ipairs (playersx) do if w == v then if actionoffset == 0 and j <= 2 then actionoffset = actionoffset + 1 elseif actionoffset == 1 and j == 1 then actionoffset = actionoffset + 1 end --print ('Removing afk player: '..playersx[j]) table.remove(playersx, j) break end end end
Then simply comment out the if statements that change the variable actionoffset, so it looks like this:
for i, v in ipairs(afk) do for j, w in ipairs (playersx) do if w == v then --[[if actionoffset == 0 and j <= 2 then actionoffset = actionoffset + 1 elseif actionoffset == 1 and j == 1 then actionoffset = actionoffset + 1 end--]] --print ('Removing afk player: '..playersx[j]) table.remove(playersx, j) break end end end Alternatively, you could simply add the line actionoffset = 0 after that loop to achieve the same effect. Regarding the side pot, as you said, that could be really complicated, and what if there is a second, or third, or more side pots? The calculatePots function does count the chips in each section separately, and includes chunks of code that print each one which I've commented out. If you want it to print the side pot value when pots are calculated, you can uncomment that chunk of code. It's set up to only print that information only if chips exist in the sidepot tray, but it's not set up to print only when it changes like the total pot does, so it would print every time the function is called as long as its value is greater than 0. Edit: looks like lua comment brackets break the bbcode formating haha
Last edited by Skor; 28 Apr, 2016 @ 5:20pm
Kowgan 28 Apr, 2016 @ 5:27pm 
Thanks for the quick answer, Skor.
When I mentioned a toggleable function, I didn't think of a button, but rather, a bool option on the script. But your solution works just as good as that. :)

As for the sidepots, what I had in mind would be simple enough to support about 3 sidepots (but easily expandable if needed), and I guess the possibly hard part would be deleting chips and replacing them with smaller value ones, if necessary, to correctly split a bet to match the sidepot.
I'll study a bit of LUA and your code to see if I can come up with something tangible.

--- Edit:
Oh, didn't notice it would break the code. What about the actionoffset = 0 line?

Also, is it just me or the deck is being moved to the center of the table while dealing cards to players? It moves back to place after done.

One last thing: I noticed the default deck has a script inserted on it. I like to use a custom deck by default. Should I insert that code into my custom deck?
Last edited by Kowgan; 28 Apr, 2016 @ 5:43pm
Skor  [developer] 28 Apr, 2016 @ 6:17pm 
Originally posted by Kowgan:
As for the sidepots, what I had in mind would be simple enough to support about 3 sidepots (but easily expandable if needed), and I guess the possibly hard part would be deleting chips and replacing them with smaller value ones, if necessary, to correctly split a bet to match the sidepot.
I'll study a bit of LUA and your code to see if I can come up with something tangible.
Oh, so you wanted it to determine if a side pot is needed based on whether or not a player has chips on the table, and then automatically separate chips and split them? That's more than I was thinking, and yes it could become very complicated. It could totally be done, though. I might consider it in the future.

--- Edit:
Oh, didn't notice it would break the code. What about the actionoffset = 0 line?
Oh no, none of those things would break the script. bbcode is the formatting code for forum posts. That's why the rest of my post was in the code box.

Also, is it just me or the deck is being moved to the center of the table while dealing cards to players? It moves back to place after done.
Oh yes! This is something I forgot to mention. I did this to hopefully prevent the rare occasion of a player ending up with three cards (the card for another player would get too close to their hand and be intercepted).

One last thing: I noticed the default deck has a script inserted on it. I like to use a custom deck by default. Should I insert that code into my custom deck?
Oh, I completely forgot about this. It's just a test code that I used to get the position of the deck when it's dropped (used to get the position of the center of the table for dealing). It's perfectly fine to delete this.
Kowgan 28 Apr, 2016 @ 6:53pm 
Originally posted by Skorなので:
Oh, so you wanted it to determine if a side pot is needed based on whether or not a player has chips on the table, and then automatically separate chips and split them?
Yep, that's what I had in mind.

Oh no, none of those things would break the script.
Ah, bbcode. I misinterpreted your original statement, my bad!

Thank you once again.
Skor  [developer] 29 Apr, 2016 @ 8:05am 
Just made a small update, not worth making a new post over.

- Rewrote getPotPos function. It still functions exactly the same; I just made the code nicer.
- Removed the test script that I forgot was on the deck.
- Fixed a potential issue with it displaying the incorrect current bet when it deals players' hands in the event that there is leftover money in the pot from the previous hand (a leftover 100 from a split pot, for example).
< >
Showing 1-6 of 6 comments
Per page: 1530 50