《桌游模拟器》高级制作教程(图包制作+脚本编写)
spj233
编辑于 2025年10月07日 14:02

桌游模拟器高级制作教程相关笔记

------------------------------------------------------

目录

  • Steam云资源连接变更导致的问题

  • 游戏tag功能更新调整

  • 资源链接

  • Atom编辑器安装报错解决

  • 图包制作与上传报错解决

  • 利用AI写lua脚本代码

  • 视频提到的脚本代码

------------------------------------------------------

Steam云资源连接变更导致的问题

TTS更新了,将steam云的资源路径更换了。由于旧图包的json文件里记录的还是旧版路径,所以TTS内部应该是把旧路径自动替换为新路径进行加载的。但是tts mod backup工具没有更新,所以旧路径资源就下载不了。

解决方法:

1,把要提取图包的mod的json文件里的路径批量替换成新的,然后再提取。

2,使用TTS Mod Vault工具替代,他会自动替换链接下载资源。

------------------------------------------------------

游戏tag功能更新调整

游戏tag功能已经修改,因此视频介绍的部分tag功能不再有效,详情见官网:https://kb.tabletopsimulator.com/game-tools/object-tags/#tagging

目前默认情况下,tag不会影响物体之间的交互;然而,您可以通过脚本添加此类功能。例如,以下脚本将为进入容器的物体添加标签检查,使用上述描述的标准交互规则。当物体从容器中移除时,它还将所有容器标签添加到该物体上。

------------------------------------------------------

资源链接

Lua语言学习:https://www.w3cschool.cn/lua/

TTS官方文档:https://api.tabletopsimulator.com/

  • TTS官方脚本API文档:https://api.tabletopsimulator.com/intro/

  • TTS官方UI界面API文档:https://api.tabletopsimulator.com/ui/introUI/

Atom代码编辑器:https://github.com/atom/atom/releases/tag/v1.60.0

Atom的TTS插件:https://github.com/Berserk-Games/atom-tabletopsimulator-lua

------------------------------------------------------

Atom编辑器安装报错解决

(只针对win10,其他系统win11或macOS遇到问题请自行搜索)

※ 请注意区分以下三种不同的错误类型!

  • 报错①:Atom报错,提示Cannot find module 'mkdirp'

  • 报错②:Atom报错,提示mkdirp is not a function

  • 报错③:Windows命令行报错:“npm命令找不到...”,或 “无法将“npm”项识别为...”

※ 如果已经按上述三个问题的解决方案操作,但是仍有问题,再参考以下问题:

  • 报错④:按照教程安装mkdir模块后,依然提示找不到该模块

  • 报错⑤:Windows命令行报错:“无法加载文件...,因为在此系统上禁止运行脚本。”

报错①:Atom报错,提示Cannot find module 'mkdirp'

错误提示:

  • Failed to load the tabletopsimulator-lua package

  • Cannot find module 'mkdirp'

开始菜单上右键--Windows PowerShell

输入npm -v,如果出现红字报错,请跳转报错③解决,解决完再继续本步骤;如果看到版本号则可继续。

每次输入一行,然后回车。共5次。

npm install mkdirp

npm install luabundle

npm install space-pen

npm install atom-space-pen-views

npm install q

每次执行命令都是安装一个模块,模块名就是后面的那5个名字。过程中可能出现各种报错导致没有正常安装。检查方法:

npm list xxx

其中xxx为模块名(如mkdirp)。如果看到(empty)这样的内容,就说明没有正常安装。若看到类似@3.0.1这样的版本号,则说明这个模块正常安装。5个模块需要都正常安装完。如果遇到报错,可以自行搜索命令行输出的报错内容来尝试解决,或者直接问问AI,一般能够解决。

报错②:Atom报错,提示mkdirp is not a function

错误提示:

  • Failed to activate the tabletopsimulator-lua package

  • mkdirp is not a function

解决方法:

找到tts-panel-view.coffee文件(下载下来的TTS插件目录下)中的

mkdirp=require("mkdirp")

改成

{mkdirp}=require("mkdirp")

(感谢B站用户 @你才是逗比0 提供该BUG与解决方法)

报错③:Windows命令行报错:“npm命令找不到...”,或者:“无法将“npm”项识别为...”

(可自行搜索“Windows系统安装npm”的教程,网上教程很多)

检查是否安装Node.js,方法:打开Windows命令行(在开始菜单上右键-Windows PowerShell,或者win+R按键,输入cmd,然后回车),输入:

node -v

如果能看到Node.js的版本号(类似v18.14.2这样的),说明Node.js已经成功安装。如果报错则需要安装Node.js,可以从Node.js官方网站(https://nodejs.org/)下载并安装Node.js,可直接下载最新的LTS版本,下载下来是msi文件,双击正常安装即可。

安装完成后需要关掉当前Windows PowerShell,重新开启一个,再尝试。

Node.js安装完成会自带npm,可以按以下方法检查,方法:在命令行输入:

npm -v

如果能看到版本号则npm安装完成。

报错④:按照教程安装mkdir模块后,依然提示找不到该模块

(请注意:请先按照①~③的解决方案操作,还有问题再参考此段。)

问题描述:过程都是按照视频操作进行,但是到启动atom就报错缺包,然后执行npm install命令可以把包下到当前目录。我的命令行的当前目录是System32,而且我也检查了系统环境变量第一个就是System32,按道理讲atom应该可以直接访问到环境变量下的文件和文件夹,但是它始终识别不到。

问题解决:最后没办法直接cd到用户目录下面的.atom的pakage目录下,把依赖包直接安装到pakage目录下就读取到了,正常了。

或者:将安装这五个包的位置(C:\Users\用户名\node_modules)添加到windows环境变量中。(开始菜单上右键-系统-高级系统设置-高级-环境变量...-上方Path双击-新建-粘贴路径-确定)

(感谢B站用户 @无法再萌 提供该BUG与解决方法)

报错⑤:Windows命令行报错:“无法加载文件...,因为在此系统上禁止运行脚本。”

百度的搜索的结果,仅供参考:以管理员身份打开PowerShell,输入 set-executionpolicy remotesigned 选择Y 然后电脑上就可以执行自己编写的脚本文件。

若不行的话,在Node.js 根目录中删去npm.ps1文件后恢复正常。

(感谢B站用户 @混乱善良的二萌子 提供该BUG与解决方法)

------------------------------------------------------

图包制作与上传报错解决

报错①:上传或下载时提示红字报错:WWW Image Error: Failed to receive data at [xxx]

这个就是某个图片素材对应的网址TTS打不开,下载不到该资源,所以报错。可能的原因:

  • 如果一整个图包只有一两个这样的错误,则大概率是这个网址的资源被原上传者删除了,所以访问不了。可以尝试使用确保能访问steam云的浏览器打开,如果提示404NotFound之类的错误,那应该就是被删除了(或者你网址输错了,没输错的话就是被删除了)。这样的话无法解决,只能想办法重新上传替代图片,然后修改某个物体对应的素材资源网址。

  • 如果大量资源都是这个错误,或者这个资源别人可以正常访问,那一般就是你的网络问题:

    • 可能因为steam网络抽风,可以多试几次,或者过几天再试;

    • 或者因为某些国内区域就是无法直连steam云,可以尝试开steam加速器、访问外网相关工具等。

如果错误是WWW Image Error: Request timeout at [xxx],那就是这个xxx网址访问不了。可能因为这个网站本身的问题(如服务器过载,已经关闭等),也有可能是网站国内无法访问。

(如果有类似错误的用户,可以在评论区提供一下这个错误的详细情况和解决方法,我来继续汇总完善)

报错②:上传牌表时报错:Error Steam upload Cloud: k_EResultTooManyPending

解决:可能是steam网络问题,多试试可能可以解决。

(感谢评论区@御坂妹10001号)

报错③:TTS Desk Editor工具制作排表时,在导出这一步显示参数无效

解决:安装jdk

(感谢评论区@大鹅GGN)

报错④:如果图片是中文命名,会显示:Error Steam share thumbnall:k_EResult Fail

解决:改成英文命名上传成功了

(感谢评论区@Haribo13)

报错⑤:自定义卡牌进行切割的时候会卡,然后steam直接闪退

解决:卡图清晰度太高了tts处理不了,降低分辨率就好了

(感谢评论区@九九w)

------------------------------------------------------

利用AI写lua脚本代码

有想写脚本的玩家,建议尝试AI写脚本,非常方便快捷!chatgpt与deepseek均可用。重点:需要把自己需求描述清楚。如果遇到报错,或者AI给出的答案不能实现功能,可以将报错信息,或更详细的需求继续追问,直到AI给出满意的结果。(AI写完脚本后,自己可以尝试学习理解一下)

示例:

桌游模拟器Tabletop Simulator,写lua脚本。按下按钮让指定区域内的卡牌旋转90度

------------------------------------------------------

基础计数器代码

local min = 0

local is_now = true

--Saves the count value into a table (data_to_save) then encodes it into the Tabletop save

function onSave()

  local data_to_save = {saved_count = count}

  saved_data = JSON.encode(data_to_save)

  return saved_data

end

--Loads the saved data then creates the buttons

function onload(saved_data)

  generateButtonParamiters()

  --Checks if there is a saved data. If there is, it gets the saved value for 'count'

  if saved_data != '' then

    local loaded_data = JSON.decode(saved_data)

    count = loaded_data.saved_count

  else

    --If there wasn't saved data, the default value is set to 10.

    count = 10

  end

  --Generates the buttons after putting the count value onto the 'display' button

  b_display.label = tostring(count)

  if count >= 100 then

    b_display.font_size = 800

  else

    b_display.font_size = 2000

  end

  self.createButton(b_display)

  self.createButton(b_plus)

  self.createButton(b_minus)

  self.createButton(b_plus5)

  self.createButton(b_minus5)

end

--Activates when + is hit. Adds 1 to 'count' then updates the display button.

function increase()

  local description = self.getDescription()

  if description != '' and type(tonumber(description)) == 'number' then

    count = tonumber(description)

    updateDisplay(self)

  end

  count = count + 1

  updateDisplay(self)

end

--Activates when - is hit. Subtracts 1 from 'count' then updates the display button.

function decrease()

  local description = self.getDescription()

  if description != '' and type(tonumber(description)) == 'number' then

    count = tonumber(description)

    updateDisplay(self)

  end

  --Prevents count from going below 0

  if count > min then

    count = count - 1

    updateDisplay(self)

  end

end

--Activates when + is hit. Adds 5 to 'count' then updates the display button.

function increase5()

  local description = self.getDescription()

  if description != '' and type(tonumber(description)) == 'number' then

    count = tonumber(description)

    updateDisplay(self)

  end

  count = count + 5

  updateDisplay(self)

end

--Activates when - is hit. Subtracts 5 from 'count' then updates the display button.

function decrease5()

  local description = self.getDescription()

  if description != '' and type(tonumber(description)) == 'number' then

    count = tonumber(description)

    updateDisplay(self)

  end

  --Prevents count from going below 0

  if count > min + 4 then

    count = count - 5

  else 

    if is_now then

      count = 0

    end

  end

  updateDisplay(self)

end

function customSet()

  local description = self.getDescription()

  if description != '' and type(tonumber(description)) == 'number' then

    count = tonumber(description)

    updateDisplay(self)

  end

end

--function that updates the display. I trigger it whenever I change 'count'

function updateDisplay(board)

  --If statement to resize font size if it gets too long

  if count >= 100 then

    b_display.font_size = 800

  else

    b_display.font_size = 2000

  end

  b_display.label = tostring(count)

  self.editButton(b_display)

  board.setDescription(tostring(count))

end

--This is activated when onload runs. This sets all paramiters for our buttons.

--I do not have to put this all into a function, but I prefer to do it this way.

function generateButtonParamiters()

  b_display = {

    index = 0, click_function = 'customSet', function_owner = self, label = '',

    position = {2.7,0.1,0}, width = 1200, height = 1200, font_size = 2000

  }

  b_plus = {

    click_function = 'increase', function_owner = self, label = '+1',

    position = {-2.3,-0.1,1}, width = 800, height = 900, font_size = 700, color = {0.3, 0.3, 0.3}

  }

  b_plus5 = {

    click_function = 'increase5', function_owner = self, label = '+5',

    position = {-2.3,-0.1,-1}, width = 800, height = 900, font_size = 700, color = {0.3, 0.3, 0.3}

  }

  b_minus = {

    click_function = 'decrease', function_owner = self, label = '-1',

    position = {-4.6,-0.1,1}, width = 800, height = 900, font_size = 700, color = {0.3, 0.3, 0.3}

  }

  b_minus5 = {

    click_function = 'decrease5', function_owner = self, label = '-5',

    position = {-4.6,-0.1,-1}, width = 800, height = 900, font_size = 700, color = {0.3, 0.3, 0.3}

  }

end

基础牌堆控制代码

function onLoad()

    params = {

        click_function = "click_func",

        function_owner = self,

        label          = "回合开始",

        position       = {0, 1, 0},

        rotation       = {0, 0, 0},

        width          = 1000,

        height         = 500,

        font_size      = 250,

        color          = {1, 1, 1},

        font_color     = {0, 0, 0},

        tooltip        = "回合开始发牌",

    }

    self.createButton(params)

end

-- 区域ID寻找卡牌

function getDeckfromZoneID(id)

  zone = getObjectFromGUID(id)

  objects = zone.getObjects()

  for i,obj in ipairs(objects) do

    if obj.type== "Deck" or obj.type== "Card" then

      return (obj)

    end

  end

  return(nil)

end

id_zone1 = '15b21d'

id_zone2 = 'a6139f'

function roundStart()

    deck = getDeckfromZoneID(id_zone1)

    deck.shuffle()

    deck.deal(3)

    card = deck.takeObject()

    v = deck.getPosition()

    v = v + Vector(-3,0,0)

    card.setPositionSmooth(v)

    Wait.time(function() card.flip() end, 1)

end

function click_func(obj, color, alt_click)

    -- 获取牌堆

    deck = getDeckfromZoneID(id_zone1)

    -- 判断牌堆数量

    if (deck == nil) or (deck.getQuantity()<10) then

        -- 如果小于10,洗混弃牌堆再发牌

        broadcastToAll("行动牌堆不足", {1, 0, 0})

        -- 获取弃牌堆

        deck2 = getDeckfromZoneID(id_zone2)

        -- 移动弃牌堆到指定位置

        zone = getObjectFromGUID(id_zone1)

        deck2.setPositionSmooth(zone.getPosition())

        -- 再发牌

        Wait.time(function() roundStart() end, 2)

    else

        -- 如果正常,直接发牌

        roundStart()

    end

end