Barotrauma 潜渊症

Barotrauma 潜渊症

49 个评价
LuaNet 组件 [过时的]
2
2
   
奖励
收藏
已收藏
取消收藏
文件大小
发表于
更新日期
140.381 KB
2023 年 2 月 23 日 上午 12:59
2023 年 3 月 3 日 上午 7:15
2 项改动说明 ( 查看 )

订阅以下载
LuaNet 组件 [过时的]

在 whosyourdaddy 的 1 个合集中
My Mods 我的模组
8 件物品
描述
其他的lua组件模组:
MicroLua
RuyiLuaComponent

模组介绍
该Mod旨在摒弃原版复杂的电路、眼花缭乱的电线以及让cpu0无法忍受的IC压迫
而一个lua组件可以用来替代整个天机工程!
在电路功能同等的基础上,lua占用的计算资源会更少!
Lua非常容易学习,它只需要花你不到十分钟的时间来理解和掌握Lua的基本知识体系以及创建一个程序。点我进入Lua菜鸟教程链接[www.runoob.com]
该mod是完全在Lua Component (By zomgtehderpy)的基础上改进的版本,改进内容主要包括以下几点:
  • 不再实时反复加载编程块,它会在巡回开始时自动完成这件事
  • 可以实时手动加载编程块,提高lua组件功能的开发效率
  • 出现错误时会在控制台中打印调试信息
  • 多人游戏模式下,可以实时同步信号输出(默认启用,在编辑器中选中lua组件可以在自定义接口中禁用同步),避免服务器和客户端间发生异步
  • 信号输出可以继承编号相同的信号输入的来源(发送者),以此做到在操作炮台对敌人造成伤害时吸引其仇恨和获得武器技能
  • lua组件的工作程序由C#编写,效率比lua更高
  • lua组件在独立的脚本中运行并处于硬沙盒下(仅支持string, math, table, bit32 packages, constants and table iterators 和os包下的clock, difftime, date, time函数)

使用说明
内存1中读取lua编程块
inp[]用作接受信号输入
out[]用作产生信号输出
mem[]寄存临时数据(从内存2中读取json格式数据并对其初始化)
警告 目前还无法在战役中永久存储数据


代码示例
你可以在潜艇编辑器中打开Demo.sub文件获得更多lua组件的应用
  • I-1接受到任意信号后,在O-1输出1000~9999的随机数
    if inp[1] then out[1] = math.random(1000, 9999) end
  • I-1接受到数字信号后,在O-1输出其符号
    if inp[1] and type(inp[1]) == "number" then if inp[1] == 0 then out[1] = 0 else out[1] = (inp[1] > 0) and 1 or -1 end end
  • I-1接受到的连续信号转换为脉冲信号并从O-1输出
    if inp[1] then if mem[1] ~= inp[1] then out[1] = inp[1] mem[1] = inp[1] end end
  • 双击检测
    if mem['mouseUp'] == nil then mem['mouseUp'] = true end if mem['timer'] == nil then mem['timer'] = -1 end if mem['count'] == nil then mem['count'] = 0 end if mem['timer'] < 0 then goto next elseif mem['timer'] > 0 then mem['timer'] = mem['timer'] - 1 else mem['timer'] = -1 mem['count'] = 0 end ::next:: if inp[1] then if mem['mouseUp'] then mem['count'] = mem['count'] + 1 if mem['count'] == 2 then mem['count'] = 0 out[1] = 1 end mem['timer'] = 15 mem['mouseUp'] = false end else mem['mouseUp'] = true end
  • 潜望镜控制无人机,假设中性压载平衡水位为0.5000,那么设置目标水位应接受0.0,此时I-1接受位置输出,I-2接受触发输出,于是O-1输出引擎推力,O-2输出垂直速度
    local y_neutral = 0.0 if inp[2] and inp[1] then inp[1] = math.rad(inp[1]) out[1] = math.cos(inp[1]) * 100 local y_ratio = math.sin(inp[1]) if y_ratio ~= 0 then local y_max = y_ratio > 0 and 100 or -100 out[2] = y_neutral + (y_max - y_neutral) * math.abs(y_ratio) end end
  • 短按检测(<0.25秒≈15个滴答),内存2存储{"press":false,"timer":-1}
    if inp[1] then if not mem['press'] then mem['press'] = true mem['timer'] = 0 else local timer = mem['timer'] if timer == -1 then return elseif timer > 15 then mem['timer'] = -1 elseif timer >= 0 then mem['timer'] = timer + 1 end end else if mem['press'] and mem['timer'] >= 0 then out[1] = 1 end mem['press'] = false end
  • 长按检测(>0.25秒),内存2存储{"press":false,"timer":-1}
    if inp[1] then if not mem['press'] then mem['press'] = true mem['timer'] = 0 else local timer = mem['timer'] if timer == -1 then out[1] = 1 return elseif timer > 15 then mem['timer'] = -1 elseif timer >= 0 then mem['timer'] = timer + 1 end end else mem['press'] = false end

补丁
31 条留言
Matheus 2023 年 9 月 27 日 上午 5:48 
Since the author marked both this mod, and it's intended replacement, as Obsolete / Outdated, and since even the intended replacement lacks documentation, I am going to propose a replacement here, for the benefit of the stranded users:

MicroLua

Full disclosure: I am the author of that mod.

Main advantages it has over this mod and it's replacement:
* Multiplayer works better, as it runs the script both on the server and all the clients.
This matches how all in-game logic components work, and means that there are no latency / update frequency issues or knobs to fiddle around.
* The setup is much simpler and more powerful: A single 32 input / 32 output component, and the actual property setup is much cleaner.
* No separate JSON memory thing for storing state to persist across frames, just store state as regular variables.
* There are other advantages, which the documentation will clarify.
Mr.x13 2023 年 7 月 25 日 下午 3:40 
Description just says "RGzXTrauma". It requires Lua/Cs for Barotrauma to be installed, and adds two new components to the editor, one with 8 in and 8 outputs, and one with 16 of each.
Just a shame it comes with zero documentation (if it's identical to this mod, then state that in the description )
DorylPlz 2023 年 7 月 24 日 下午 9:44 
What does the RGzTrauma mod actually does? i can't find any new component or anything on it
Mr.x13 2023 年 7 月 24 日 上午 8:00 
Hi! I tried using rgzxtrauma but found your mod preferable for me, mostly because it comes with actual documentation. I do have a few questions though.
Does 2nd memorycomponent just take a json object to preload the mem[] in editor?
What does the whole "buttonterminal" part seen in the sub editor do, could it be useful to me?
Is there a way to have lua components work when testing out something in the sub editor, or do i have to ask the lua for barotrauma people about this?
Is the implementation of the mod optimised enough that i can just have logic always output a value to every pin, or should i use if-statements and such to only output a toggle signal to a pin when needed?
And lastly if i write a 1 to an output pin, will that pin still have a value of 1 the next time my code gets ran or will it be 0 or nil? (my current code assumes this is not the case)
whosyourdaddy  [作者] 2023 年 5 月 28 日 上午 8:28 
There is a better lua component implementation here: RGzXTrauma , the mod has some new component types.
I tested it with 20+ players in pvp and everything works fine.
whosyourdaddy  [作者] 2023 年 5 月 28 日 上午 8:25 
@Schrödinger's Cat maybe yes
whosyourdaddy  [作者] 2023 年 5 月 28 日 上午 8:23 
@K 我这边还是正常的,如果问题仍然存在,我会检查一下
whosyourdaddy  [作者] 2023 年 5 月 28 日 上午 8:23 
@天启洪流apocalyptic 按照描述里的标准来,这份报错如果现在还有,我会去检查下
Schrödinger's Cat 2023 年 5 月 14 日 上午 1:03 
Is there more reliable way to make delay / count time beside counting ticks? Like DateTime.Now or something?
天启洪流apocalyptic 2023 年 5 月 6 日 上午 2:06 
仅安装前置模组以及该模组后出现控制台报错
[CL CS error] CS MODS loading | compiler error: C: / user/administrator/AppData/local / / pressure trauma/WorkshopMods Daedalic entertainment GmbH/installation / 2937571024 / / CSharp/Shared/LuaNetComponent cs (21, 20) : error CS0104: 'Closure' is an ambiguous references between System.Runtime.CompilerServices. A Closure 'and' MoonSharp. Interpreter. Closure '[CL CS error] system. Exception: Unable to create cs module assembly. B: programming\c#\ barotrauma \ barotrauma \SharedSource\LuaCs\Cs\CsScriptLoader.cs: Line 242: barotrauma Initialization (Boolean forceEnableCs)B: programming \c#\ barometric trauma \ barometric trauma \ shared source \LuaCs\LuaCsSetup.cs: Line 398