├── AutoUpdater.lua ├── CODEOWNERS ├── CONTRIBUTING.md ├── README.md ├── TTS-Patches.lua └── Tutorials └── TTS-Coroutines.lua /AutoUpdater.lua: -------------------------------------------------------------------------------- 1 | --(written by ThatRobHuman) 2 | ScriptVersion = 4 3 | ScriptClass = 'MyUtility' 4 | 5 | function checkForUpdate() 6 | WebRequest.get('yourgithubfile.json', function(res) 7 | if (not(res.is_error)) then 8 | local response = JSON.decode(res.text) 9 | if (response[ScriptClass] > ScriptVersion) then 10 | print('New Version ('..response[ScriptClass]..') of '..ScriptClass..' is available!') 11 | --install update? 12 | installUpdate(response[ScriptClass]) 13 | end 14 | else 15 | error(res) 16 | end 17 | end) 18 | end 19 | 20 | function installUpdate(newVersion) 21 | print('[33ff33]Installing Upgrade to '..ScriptClass..'['..tostring(newVersion)..']') 22 | WebRequest.get('yourgithubfile.lua', function(res) 23 | if (not(res.is_error)) then 24 | self.setLuaScript(res.text) 25 | self.reload() 26 | print('[33ff33]Installation Successful[-]') 27 | else 28 | error(res) 29 | end 30 | end) 31 | end 32 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | Tutorials/TTS-Coroutines.lua @Andr3wD 2 | 3 | AutoUpdater.lua @RobMayer 4 | 5 | TTS-Patches.lua @TomSputz 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thanks for thinking about contributing!
2 | There aren't many set rules currently for contributing, just please follow what's below:
3 | 4 | # Rules 5 | Feel free to make a pull request with anything that can be helpful for scripters (both new and old).
6 | If it doesn't exist already, then please add enough comments to explain how the script works so others can learn.
7 | Finally, please follow the general code style of the repository (ex: no obfuscated code, must be relatively easy to read).
8 | 9 | # Code Owner 10 | If you make a pull request with a new file that you've made, please edit the CODEOWNERS file with your github name and the new file so that your permission is required for future pushes to the file you own. If you don't care who edits your file, then please say so in your pull request.
11 | 12 | Codeowner info and how it works: https://help.github.com/articles/about-codeowners/
13 | Pattern rule for CODEOWNER file: https://git-scm.com/docs/gitignore#_pattern_format 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TTS-Helpful-Scripts 2 | This is a repository of helpful scripts/tutorials for Table Top Simulator the game.
3 | It is community driven, so not all scripts here are neccessarily made or edited by one person.
4 | When possible, credit will be given inside the scripts or in the commit message.
5 | 6 | All scripts are written in TTSLUA, which is different than regular LUA, so you might see some things done differently than they would be done in regular LUA. 7 | 8 | 9 | ## Communication/Personal Help 10 | 11 | Table Top Simulator official discord: https://discord.gg/tabletopsimulator
12 | Table Top Simulator Club (TTSClub) discord: https://discord.me/ttsclub
13 | Feel free to join and ask any questions in the scripting channel if you need any help with scripting.
14 | 15 | If you choose to get help in these discords, please follow this list to get help effectively: 16 | 1) State the nature of your scripting emergency. What is your end goal? (Consider: http://xyproblem.info/)
17 | 2) Provide context. Why are you trying to do it?
18 | 3) State what you have attempted so far.
19 | 4) Try not to use pseudo-code unless you haven't written the code yet. Try to provide ALL the relevant bits.
20 | 21 | ## Modules 22 | 23 | Lua code can be reused by creating and sharing 'packages'. [LuaRocks](https://luarocks.org/) can be used to package and find modules containing both Lua and C code, which can then be used through the `require` function. 24 | 25 | As Tabletop Simulator does not support any filesystem functions, we are not able to load modules while our script is running, meaning we must put all code we want to make use of in the same file. 26 | 27 | The [Official Atom Package](https://github.com/Berserk-Games/atom-tabletopsimulator-lua/) solves this using the `#include` keyword, which can be used to combine the source of two lua files. However, as it works differently to the `require` method, this cannot be used to import lua packages without issues. 28 | 29 | That said, many lua-only packages can be used with TTS using a simple trick: 30 | 31 | ```lua 32 | local uuid = (function(...) 33 | #include uuid -- (https://github.com/Tieske/uuid) 34 | end)() 35 | 36 | uuid.seed() 37 | local UserObjects = {} 38 | 39 | function onObjectSpawn(obj) 40 | UserObjects[uuid()] = obj.guid 41 | end 42 | ``` 43 | 44 | ### Common Modules for TTS Mods 45 | 46 | * [Orderly](https://github.com/TomSputz/Orderly/releases/) - A Promises/A+ library with support for the async/await model 47 | ## Contributing 48 | 49 | Please read the [Contributing Guideline](/CONTRIBUTING.md) to contribute. 50 | -------------------------------------------------------------------------------- /TTS-Patches.lua: -------------------------------------------------------------------------------- 1 | -- Lua is a lightweight programming language designed to be embedded 2 | -- in many different applications. Tabletop Simulator uses MoonSharp, 3 | -- an interpreter written specifically to be used in Unity. 4 | 5 | -- As a complete rewrite of the language, MoonSharp's interpreter 6 | -- contains bugs which make our scripts unpredictable, making 7 | -- writing scripts and debugging difficult. 8 | 9 | -- These patches fix these issues in the standard library to improve 10 | -- compatability with standard lua code 11 | 12 | -- Unfortunately, there are some language-level issues which we cannot fully solve: 13 | if false then 14 | -- # __newindex fails on tuple assignments 15 | local tool = setmetatable({}, { 16 | __newindex = function(_, key, value) 17 | print(key, value) 18 | if select('#', value) == 0 then 19 | -- If a tuple assignment was performed 20 | end 21 | end 22 | }) 23 | tool.one, tool.two = 1, 2 24 | --> one 1 25 | --> two 26 | -- # vararg length cannot be 0 27 | -- - This affects table.pack 28 | -- This is a minor issue - the difference between nil and the lack of an argument very rarely applies 29 | print((function(...) return select('#', ...) end)()) 30 | --> 1 31 | end 32 | 33 | -- Avoid emitting non-standard error 34 | -- table.remove({}, 1) --> error: position out of bounds 35 | if not pcall(table.remove, {}, 1) then 36 | local remove = table.remove 37 | function table.remove(tab, pos) 38 | if #tab < pos then return end 39 | return remove(tab, pos) 40 | end 41 | end 42 | -- Ensure table.unpack uses .n as a default for j 43 | -- table.pack(nil, 1) --> { 2 = 1, n = 2 } 44 | if select(2, table.unpack { 2 = 1, n = 2 }) == nil then 45 | local unpack = table.unpack 46 | function table.unpack(tab, i, j) 47 | if j == nil then 48 | local n = tab.n 49 | if n then 50 | j = tab[n] == nil and 0 or n 51 | end 52 | end 53 | if j == 0 then return end 54 | return unpack(tab, i, j) 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /Tutorials/TTS-Coroutines.lua: -------------------------------------------------------------------------------- 1 | function onload() --(written by DeathKnight1003, ThatRobHuman, and dzikakulka) 2 | cooutside(params) 3 | startLuaCoroutine(self, "normalcoroutine") --this is calling the regular way people do coroutines 4 | end 5 | 6 | --This is the usual way people do coroutines, does not allow params to be passed through 7 | function normalcoroutine() --no params can be passed 8 | waitTime(1) 9 | print("1") 10 | waitFrames(60) 11 | print("2") 12 | return 1 13 | end 14 | 15 | 16 | --This function will allow params to a coroutine 17 | function cooutside(params) --make coroutine like this so parameters can be passed through cooutside() 18 | function coinside() 19 | --can now use params inside here, as startLuaCoroutine(obj,function) does not take parameters to pass 20 | waitTime(1) 21 | print("1") 22 | waitFrames(60) 23 | print("2") 24 | return 1 --must return 1 at the end because that is how startLuaCoroutine() works, it is in the api. Without, it will error 25 | end 26 | startLuaCoroutine(self, "coinside") --must use this way to make coroutine in order to wait frames 27 | end 28 | 29 | --This function will wait a given number of frames 30 | function waitFrames(frames) --This function can only be used inside a coroutine because it is using coroutine.yield() 31 | while frames > 0 do --loop until frames = 0 32 | coroutine.yield(0) --this will wait 1 frame, reguardless of the number put inside coroutine.yield(#) 33 | frames = frames - 1 --decrement frames every loop 34 | end 35 | end 36 | 37 | --This function will wait a given time in seconds 38 | function waitTime(IN) --This function can only be used inside a coroutine because it is using coroutine.yield() 39 | local finished = false 40 | Wait.time(function() finished = true end, amount) 41 | while not finished do coroutine.yield(0) end 42 | end 43 | --------------------------------------------------------------------------------