Barotrauma

Barotrauma

48 ratings
LuaNet Component [Obsolete]
2
2
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
140.381 KB
Feb 23, 2023 @ 12:59am
Mar 3, 2023 @ 7:15am
2 Change Notes ( view )

Subscribe to download
LuaNet Component [Obsolete]

In 1 collection by whosyourdaddy
My Mods 我的模组
8 items
Description
Another Lua Component Mods:
MicroLua
RuyiLuaComponent

All descriptions are generated by the translator
Introduction
The mod aims to do away with the original's complex circuitry, dazzling wires, and IC pressure that cpu0 can't tolerates
Now just only one lua component can be used to replace the whole celestial engineering!
lua uses less computing resources when the circuit functions are the same!
Lua is very easy to learn, it just needs to takes you less than ten minutes to understand and master the basic body of knowledge of Lua and create an application! Click here to link Lua Novice Tutorial[www.runoob.com]
The mod is a complete copy of Lua Component (By zomgtehderpy), but with some improvements, including the following:
  • Instead of reloading chunk in real time, it does this automatically when the round starts
  • Can manually load chunk in real time, improving the development efficiency of lua component function
  • Debug information is printed in the console when any error occurs
  • In multiplayer game mode, signal output can be synchronized in real time to avoid asynchronism between server and client. (Enabled by default, you can select the lua component in the sub-editor and disable synchronization in custom interface)
  • signal_out can inherit the source (sender) of the signal_in with the same number, so as to attract targets' hatred and gain weapon skills when operating the turret to deal damage to the enemy
  • lua components are programmed in C#, which is more efficient than lua
  • lua components run by separate scripts and are in Hard-Sandbox (only supported string, math, table, bit32, constants and table iterators. The time methods of the "os" package: "clock", "difftime", "date" and "time")

Instructions for use
Read lua chunk in memory 1
inp[] is used to receive signal input
out[] is used to generate signal output
mem[] Stores temporary data (reads and initializes json format data from memory 2)
WARNING It is currently not possible to store data permanently in the campaign


Code Example
You can open the Demo.sub file in the submarine editor to get more applications of lua components
  • I-1 receives any signal and outputs a random number between 1000 and 9999 in O-1
    if inp[1] then out[1] = math.random(1000, 9999) end
  • I-1 receives the digital signal and outputs its symbol in 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
  • Convert the constant signal received by I-1 into a pulse signal and output it from O-1
    if inp[1] then if mem[1] ~= inp[1] then out[1] = inp[1] mem[1] = inp[1] end end
  • Double-click detection
    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
  • The periscope controls the drone. Assuming that the neutral ballast level is 0.5000, then neutral_velocity_y_out should be 0.0. At this time, I-1 receives position_out, I-2 receives trigger_out, so O-1 outputs engine force and O-2 outputs velocity_y_out
    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
  • Short press detection(<0.25s≈15tick), memory 2 stores {"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
  • Long press detection(>0.25s), memory 2 stores {"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

Patches
31 Comments
Matheus Sep 27, 2023 @ 5:48am 
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 Jul 25, 2023 @ 3:40pm 
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 Jul 24, 2023 @ 9:44pm 
What does the RGzTrauma mod actually does? i can't find any new component or anything on it
Mr.x13 Jul 24, 2023 @ 8:00am 
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  [author] May 28, 2023 @ 8:28am 
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  [author] May 28, 2023 @ 8:25am 
@Schrödinger's Cat maybe yes
whosyourdaddy  [author] May 28, 2023 @ 8:23am 
@K 我这边还是正常的,如果问题仍然存在,我会检查一下
whosyourdaddy  [author] May 28, 2023 @ 8:23am 
@天启洪流apocalyptic 按照描述里的标准来,这份报错如果现在还有,我会去检查下
Schrödinger's Cat May 14, 2023 @ 1:03am 
Is there more reliable way to make delay / count time beside counting ticks? Like DateTime.Now or something?
天启洪流apocalyptic May 6, 2023 @ 2:06am 
仅安装前置模组以及该模组后出现控制台报错
[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