Tabletop Simulator

Tabletop Simulator

View Stats:
Script for counting cards in scripting zone?
Trying to make a script for a card game. Anyone able to help me make a script, that reveals a number based on the number of cards in a scripting zone?
Example: Let´s say I have 3 cards spread out within a scripting zone. I then want the zone to display a custom text saying: "x3 cards in the zone".

I found this mod in the workshop:
https://steamcommunity.com/sharedfiles/filedetails/?id=772912200
- but the problem with this mod, is that it only counts all the individual objects separately, instead of adding them up together. Every card in my script will have a value of [1]. Preferably, I would like the zone to recognise objects within based on the 'Card' item.tag.

Any help is much appreciated, I´m quite new to programming and LUA in general.
Thanks!
Last edited by BlaCk NinJa; Aug 3, 2021 @ 2:50pm
< >
Showing 1-3 of 3 comments
Finaryman Aug 6, 2021 @ 3:14am 
put this in GLOBAL scripts.
remember to edit GUID there.
function onLoad() zone=getObjectFromGUID("YOUR ZONE GUID HERE") end function refreshcount() local count=0 for i, lobj in ipairs(zone.getObjects()) do if lobj.type == "Card" then count=count+1 elseif lobj.type == "Deck" then count=count + #lobj.getObjects() end end printToAll("Zone has " .. count .. " cards in it.") end function onObjectEnterZone(curzone,obj) if zone == curzone then refreshcount() end end function onObjectLeaveZone(curzone,obj) if zone == curzone then refreshcount() end end
Last edited by Finaryman; Aug 6, 2021 @ 3:23am
BlaCk NinJa Aug 6, 2021 @ 4:53am 
Thank you so much, this works like a charm! I had been
struggling with this for so long, this is much appreciated!
Finaryman Aug 6, 2021 @ 5:32am 
don't forget that with strugling you learn.
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Aug 3, 2021 @ 2:46pm
Posts: 3