Lua (Incomplete) - evilfactory/LuaCsForBarotrauma GitHub Wiki
This wiki is outdated, see the new wiki
If you want to learn how Lua works and the syntax, you can check these websites: https://www.lua.org/manual/5.2/ https://www.tutorialspoint.com/lua/lua_overview.htm
(not everything is documented here, i'm still adding stuff)
When creating a new lua mod, you will need to create a new folder on the Mods folder, then inside this folder you will need to create a folder called Lua, and then inside the Lua folder you create a folder called Autorun, inside this folder you can add your lua scripts that will be executed automatically, it will look something like this Mods/MyMod/Lua/Autorun/test.lua
Now you can open test.lua in your favorite text editor (vscode recommended) and type in print("Hello, world"), now start the server by hosting a game or running the server executable manually, you will see in your console a text appear with the text that you entered in print, you can now type in the server console reloadlua, this will rerun all the lua scripts. You can also type in lua (script) to run a short lua snippet, like this lua print('Hello, world')
, remember to remove double quotes, because barotrauma console automatically formats those.
Hooks are basically functions that get called when events happen in-game, like chat messages.
You can add a new hook like this:
Hook.Add("roundStart", "myRoundStartHook", function()
print("round has started!")
end)
The first argument is the event name, the second is the hook name and the third is the function that will be called. other example:
Hook.Add("chatMessage", "myChatMessageHook", function(message, client)
print(client.name .. " typed in chat " .. message)
end)
- chatMessage - Gets called every time someone sends a message, the function provides message and client as the arguments, if you return true, you will cancel the message.
- think - Gets called every update in-game.
- clientConnected - Gets called every time someone joins the server, provides a client as argument.
- clientDisconnected - Gets called every time someone leaves the server, provides a client as argument.
- roundStart - Gets called every time the a round starts.
- roundEnd - Gets called every time the ends.
- characterCreated - Gets called every time a character is created, provides a Character as argument.
- characterDeath - Gets called every time a character dies, provides a Character and the killing affliction as argument.
- afflictionApplied - Gets called every time an affliction is applied, has 3 arguments, CharacterHealth, Affliction, and Limb (can be nil), you can cancel the affliction by returning true.
- afflictionUpdate - Gets called every time an affliction updates, provides the Affliction, CharacterHealth, Limb (can also be nil) and the deltaTime.
- itemUse - Gets called every time an Item gets "Used", provides the Item,the character using the item, and the targetLimb. You can return true to cancel the usage.
- itemSecondaryUse - Same as itemUse, but theres no targetLimb.
- itemApplyTreatment - Gets called whenever an item is used as a treatment (eg. bandages); Provides the Item,the using Character,and the Character getting treated, and the Limb getting treated.
- itemDrop - Gets called whenever an item is dropped, returns the Item, the Character that dropped the item. You can return true to cancel.
- itemEquip - Gets called whenever an item is equipped, returns the Item,(Character) user. Return true to cancel.
- itemUnequip - Same as itemUnequip, but for unequipping.
- changeFallDamage
- gapOxygenUpdate - Gets called every update when a gap passes oxygen, returns the Gap,First Hull and the Second Hull.
- signalReceived - Gets called everytime an Item receives a wire signal, providing: Signal, Connection
- signalReceived.YourComponentIdentifier - Same as signalReceived, but gets called only when needed by specifying your component, better performance.
- wifiSignalTransmitted - Gets called everytime a WifiComponent starts transmitting a signal; Provides the WifiComponent,the transmitting Signal, and sentFromChat. You can return true to cancel the signal from being transmitted.
- serverLog - Gets called everytime something is logged to the Server Log, returns the text, and the ServerLogMessageType
This class is deprecated.
-
Character[] GetAllCharacters() (use Character.CharacterList instead)
-
Client[] GetAllClients()
(use Client.ClientList instead) -
SetClientCharacter(Client client, Character character) (use client.SetClientCharacter(Character character) instead)
-
Kick(Client client, string reason = "")
(use client.Kick(string reason) instead) -
Ban(Client client, string reason = "", bool range = false, float seconds = -1) (use client.Ban(bool range = false, float seconds = -1) instead)
-
UnbanPlayer(string player, string endpoint) (use Client.Unban(string player, string endpoint instead)
-
bool CheckPermission(Client client, ClientPermissions permissions) (use client.CheckPermission(ClientPermissions permissions)
- bool RoundStarted
- SendMessage(string msg, ChatMessageType messageType, Client sender = null, Character character = null)
- SendTraitorMessage(Client client, string msg, string missionid, TraitorMessageType type)
- SendDirectChatMessage(string sendername, string text, Character sender, ChatMessageType messageType = ChatMessageType.Private, Client client = null, string iconStyle = "")
- Explode(Vector2 pos, float range = 100, float force = 30, float damage = 30, float structureDamage = 30, float itemDamage = 30, float empStrength = 0, float ballastFloraStrength = 0)
- SpawnItem(string name, Vector2 pos, bool inventory = false, Character character = null)
- Log(string message, ServerLogMessageType type)
- Character Spawn(string name, Vector2 worldPos)
- ExecuteCommand(string command)
- OverrideTraitors(bool o)
- OverrideRespawnSub(bool o)
- AllowWifiChat(bool o)
- DispatchRespawnSub()
- RemoveItem(Item item)
- Signal CreateSignal(string value, int stepsTaken = 1, Character sender = null, Item source = null, float power = 0, float strength = 1)
- ItemPrefab GetItemPrefab(string itemNameOrId)
- AddItemPrefabToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, DynValue spawned = null)
- AddItemPrefabToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, DynValue spawned = null)
- ContentPackage[] GetEnabledContentPackages()
- int Range(min, max)
- float RangeFloat(min, max)
- float GetTime()
- Vector2 CreateVector2(x, y)
- Vector3 CreateVector3(x, y, z)
- Vector4 CreateVector4(x, y, z, w)
- https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199660(v=xnagamestudio.35)
- https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199670(v=xnagamestudio.35)
- https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199679(v=xnagamestudio.35)
- Kill(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool isNetworkMessage = false, bool log = true)
- Create(string speciesName, Vector2 Position, string Seed, characterInfo characterInfo = null, ushort id = Entity.NullEntityID, bool IsRemotePlayer = false, bool hasAI = true, bool createNetworkEvent = true, RagdollParams ragdoll = null)
- Bool IsRemotelyControlled
- Bool IsObserving
- Bool IsBot
- Bool IsDead
- Bool IsHuman
- Bool IsMale
- Bool IsFemale
- Bool CanSpeak
- Bool NeedsAir
- Bool NeedsWater
- Bool NeedsOxygen
- Bool IsTraitor
- Bool HideFace
- Bool LockHands
- Bool CanMove
- Bool CanInteract
- Bool ObstructVision
- Bool IsRagdolled
- Bool IsIncapacitated
- Bool IsUnconscious
- Bool IsPet
- Bool UseHullOxygen
- Bool CanBeSelected
- Bool CanBeDragged
- Bool CanInventoryBeAccessed
- Bool GodMode
- Bool IsInFriendlySub
- Vector2 Position
- Vector2 DrawPosition
- Vector2 CursorPosition
- Vector2 SmoothedCursorPosition
- Vector2 CursorWorldPosition
- Float LowPassMultiplier
- Float Oxygen
- Float OxygenAvailable
- Float Stun
- Float Vitality
- Float MaxVitality
- Float Health
- Float HealthPercentage
- Float SpeechImpediment
- Float PressureTimer
- Float CurrentSpeed
- Item FocusedItem
- Item PickingItem
- String Name
- String DisplayName
- String LogName
- CharacterInventory Inventory
- CauseOfDeath CauseOfDeath
Inherits: Entity, IServerSerializable
- Submarine.Direction (Enum): None = 0 Left = 1 Right = 2
- SubmarineInfo Info
- CharacterTeamType TeamID = CharacterTeamType.None
- static bool LockY (applies to all subs,default false)
- static bool LockX (applies to all subs,default false)
- static readonly Vector2 GridSize = Vector2(16.0f, 16.0f)
- static readonly Submarine[2] MainSubs (First sub is always the player sub, Second can be nil or an enemy sub(?))
- static Submarine MainSub (Player Sub)
- readonly Dictionary<Submarine, DockingPort> ConnectedDockingPorts
- IEnumerable DockedTo (Submarines this sub is docked to)
- bool ShowSonarMarker = true
- GodMode = false
- SubmarineBody SubBody
- PhysicsBody PhysicsBody
- Vector2 Position
- Vector2 WorldPosition
- float RealWorldCrushDepth (How deep down the sub gets crushed from the surface of Europa in meters (affected by level type, does not correspond to "actual" coordinate systems)
- float RealWorldDepth (How deep down the sub is from the surface of Europa in meters (affected by level type, does not correspond to "actual" coordinate systems))
- Vector2 Velocity (SUB GO BRRRRRRRRRRRRRRRRRRRRRR)
- List HullVertices
- bool AtDamageDepth (If the sub is getting crushed)
- string ToString()
- bool ImmuneToBallastFlora = false
- void AttemptBallastFloraInfection(string identifier, float deltaTime, float probability) (Infect a ballast with ballast flora)
- void MakeWreck() (Seems to replace all door restriction and IDs, and turns off the sonar marker. Also turns it into a static body.
- WreckAI WreckAI (variable for the WreckAI)
- bool CreateWreckAI()
- void DisableWreckAI()
- List GetConnectedSubs()
- Vector2 FindSpawnPos(Vector2 spawnPos, Point? submarineSize = null, float subDockingPortOffset = 0.0f, int verticalMoveDir = 0) - Attempt to find a spawn position close to the specified position where the sub doesn't collide with walls/ruins
- const float NeutralBallastPercentage = 0.07f;
- const float HorizontalDrag = 0.01f;
- const float VerticalDrag = 0.05f;
- const float MaxDrag = 0.1f;
- List HullVertices
- struct Impact
- Vector2 Velocity
- public Vector2 Position
- Submarine Submarine (The submarine this SubmarineBody is attached to)
- void ApplyForce(Vector2 force)
- void SetPosition(Vector2 position)
- void FlipX() (Flips the submarine, finally!)
- void Remove() (Probably dont do this!)
- enum SubmarineTag { Shuttle = 1, HideInMenus = 2 } (Flags)
- enum SubmarineType { Player, Outpost, OutpostModule, Wreck, BeaconStation, EnemySubmarine }
- enum SubmarineClass { Undefined, Scout, Attack, Transport, DeepDiver }
Heres where the actual SubmarineInfo begins Inherits: IDisposable
- SubmarineTag Tags
- readonly DateTime LastModifiedTime;
- int RecommendedCrewSizeMin = 1
- int RecommendedCrewSizeMax = 2
- string Name
- string DisplayName
- string Description
- int Price
- bool InitialSuppliesSpawned (If the items placed in the sub editor such as flares in supply cabinets have already been given)
- Version GameVersion
- SubmarineType Type
- SubmarineClass SubmarineClass;
- OutpostModuleInfo OutpostModuleInfo
- OutpostGenerationParams OutpostGenerationParams;
- bool RequiredContentPackagesInstalled
- readonly bool IsOutpost
- readonly bool IsWreck
- readonly bool IsBeacon
- readonly bool IsPlayer
- readonly bool IsCampaignCompatible
- readonly bool IsCampaignCompatibleIgnoreClass (same as above but allows subs with Undefined class)
- bool HasTag(SubmarineTag tag)
- void AddTag(SubmarineTag tag)
- void RemoveTag(SubmarineTag tag)
- bool IsVanillaSubmarine()
- void Dispose()
- void Reload()
- Vector2 Dimensions
- int CargoCapacity
- string FilePath
- Md5Hash MD5Hash