improve docs

This commit is contained in:
Evil Factory
2022-03-26 14:19:39 -03:00
parent fd377454a3
commit 05a65a1207
9 changed files with 124 additions and 198 deletions
+59 -168
View File
@@ -1,190 +1,81 @@
/*
/* Dracula Theme v1.2.5
*
* https://github.com/dracula/highlightjs
*
* Copyright 2016-present, All rights reserved
*
* Code licensed under the MIT license
*
* @author Denis Ciccale <dciccale@gmail.com>
* @author Zeno Rocha <hi@zenorocha.com>
*/
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
*/
.hljs {
.hljs {
display: block;
color: white;
overflow-x: auto;
padding: 0.5em;
background: #282a36;
}
.hljs-built_in,
.hljs-selector-tag,
.hljs-section,
.hljs-link {
color: #8be9fd;
}
.hljs-keyword {
color: #ff79c6;
}
.hljs,
.hljs-subst {
color: #f8f8f2;
}
.hljs-title,
.hljs-attr,
.hljs-meta-keyword {
font-style: italic;
color: #50fa7b;
}
.hljs-string,
.hljs-meta,
.hljs-name,
.hljs-type,
.hljs-symbol,
.hljs-bullet,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #f1fa8c;
}
.hljs-comment,
.hljs-quote {
color: gray;
font-style: italic;
.hljs-quote,
.hljs-deletion {
color: #6272a4;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-subst {
color: #0086b3;
font-weight: bold;
}
.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
color: #008080;
}
.hljs-string,
.hljs-doctag {
color: #d14;
}
.hljs-title,
.hljs-section,
.hljs-selector-id {
color: #900;
font-weight: bold;
}
.hljs-subst {
font-weight: normal;
}
.hljs-doctag,
.hljs-type,
.hljs-class .hljs-title {
color: #458;
font-weight: bold;
}
.hljs-tag,
.hljs-name,
.hljs-attribute {
color: #000080;
font-weight: normal;
}
.hljs-regexp,
.hljs-link {
color: #009926;
}
.hljs-symbol,
.hljs-bullet {
color: #990073;
}
.hljs-built_in,
.hljs-builtin-name {
color: #0086b3;
}
.hljs-meta {
color: #999;
.hljs-strong {
font-weight: bold;
}
.hljs-deletion {
background: #fdd;
}
.hljs-addition {
background: #dfd;
.hljs-literal,
.hljs-number {
color: #bd93f9;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
.comment,
.quote {
color: gray;
font-style: italic;
}
.keyword,
.selector-tag,
.subst {
color: #0086b3;
font-weight: bold;
}
.number,
.literal,
.variable,
.template-variable,
.tag .hljs-attr {
color: #008080;
}
.string,
.doctag {
color: #d14;
}
.title,
.section,
.selector-id {
color: #900;
font-weight: bold;
}
.subst {
font-weight: normal;
}
.type,
.class .hljs-title {
color: #458;
font-weight: bold;
}
.tag,
.name,
.attribute {
color: #000080;
font-weight: normal;
}
.regexp,
.link {
color: #009926;
}
.symbol,
.bullet {
color: #990073;
}
.built_in,
.builtin-name {
color: #0086b3;
}
.meta {
color: #999;
font-weight: bold;
}
.deletion {
background: #fdd;
}
.addition {
background: #dfd;
}
.emphasis {
font-style: italic;
}
.strong {
font-weight: bold;
}
+8 -5
View File
@@ -28,7 +28,7 @@
--color-background-dark: rgb(33, 33, 33);
--color-background-dark-ish: rgb(44, 44, 44);
--color-outline: rgb(149, 34, 160);
--color-good: rgb(204, 34, 34);
--color-good: #5190ff;
}
* {
@@ -94,14 +94,17 @@ code {
white-space: pre;
tab-size: 4;
-moz-tab-size: 4;
padding: 2px 4px;
background-color: rgba(33, 33, 33, 0.1);
padding: 1px 4px;
background-color: #282a36;
outline-style: solid;
outline-color: black;
outline-width: 2px;
}
pre {
background-color: rgb(99, 99, 99, 0.1);
background-color: rgb(0, 0, 0, 1);
margin-top: var(--padding-small);
padding: var(--padding-tiny);
padding: 2px;
overflow: auto;
}
+12
View File
@@ -215,3 +215,15 @@ function statusEffect.apply.YourItemIdentifier(statusEffect, deltaTime, item, ta
--- Called when a client tries to change his name, return false to prevent the name from being changed.
-- @realm shared
function tryChangeClientName(client, newName, newJob, newTeam) end
--- Called after all mods are executed.
-- @realm shared
function loaded() end
--- Called after the CPR skill check succeeds.
-- @realm shared
function human.CPRSuccess(animController) end
--- Called after the CPR skill check fails.
-- @realm shared
function human.CPRFailed(animController) end
+13 -11
View File
@@ -2,7 +2,7 @@
## What does attempt to index a nil value mean!?
It means you tried to access a field of something that doesn't exist, for example:
```lua
```
local thisIsNil = nil
print(thisIsNil.what)
print(thisIsNil.something())
@@ -10,20 +10,22 @@ print(thisIsNil.something())
## Why i'm getting "Cannot access field test of userdata<something>" errors?
Because you are trying to access a field in a C# class that doesn't exist.
```lua
```
print(Item.thisDoesntExist)
```
## What is "Attempt to access instance member "Drop" from a static userdata"
It means you are trying to access a member that requires an instance to accessed, for example:
```lua
Item.Drop() -- there's a static global class called Item, but because it's static, you can't call item specific things on it, this will error.
```
-- there's a static global class called Item, but because it's static, you can't call item specific
-- things on it, this will error.
Item.Drop()
Item.ItemList[1].Drop() -- this won't error, it will drop the first item ever created.
```
## I'm getting a super big error with things related to the C# side
It usually happens when you call something on the C# side and you provide nil inputs, you can get a better idea of it by analyzing the error message and trying to link it your lua code, for example:
```lua
```
Game.SendMessage(nil)
```
This will result in
@@ -36,7 +38,7 @@ Character senderCharacter, PlayerConnectionChangeType changeType)
You can easily tell that the error has something to do with chat messages, and by looking back at your Lua code you can easily see whats causing it.
## How do i list all clients, characters and items?
```lua
```
for _, client in pairs(Client.ClientList) do
end
@@ -52,7 +54,7 @@ end
## Running pairs() on an enumerator doesn't work!
pairs() Returns an enumerator that iterates through the entire table keys, if you already have an enumerator, you can just pass it in directly.
```lua
```
-- get first item ever created and loop through all the items stored inside it.
for item in Item.ItemList[1].OwnInventory.AllItems do
@@ -60,7 +62,7 @@ end
```
## How do i spawn an item?
```lua
```
local prefab = ItemPrefab.GetItemPrefab("screwdriver")
local firstPlayerCharacter = Client.ClientList[1].Character
@@ -77,7 +79,7 @@ end)
## How do i give a character a certain affliction
```lua
```
local burnPrefab = AfflictionPrefab.Prefabs["burn"]
local char = Character.CharacterList[1]
@@ -90,7 +92,7 @@ char.CharacterHealth.ApplyAffliction(limb, burnPrefab.Instantiate(100))
## How do i get the amount of a affliction that a character has?
```lua
```
local char = Character.CharacterList[1]
print(char.CharacterHealth.GetAffliction("burn"))
@@ -100,7 +102,7 @@ print(char.CharacterHealth.GetAffliction("burn", char.AnimController.Limbs[1]))
## How do i send a private chat message?
```lua
```
local chatMessage = ChatMessage.Create("Sender name", "text here", ChatMessageType.MessageBox, nil, nil)
Game.SendDirectChatMessage(chatMessage, ChatMessageType.MessageBox)
```
+6 -6
View File
@@ -6,7 +6,7 @@ Hooks are basically functions that get called when events happen in-game, like c
Hooks can be added like this:
```lua
```
Hook.Add("chatMessage", "test", function(message, client)
print(client.Name .. " has sent " .. message)
end)
@@ -18,7 +18,7 @@ The event name (first argument), is case-insensitive, so you can call it chatMes
You can also call hooks with the following code:
```lua
```
Hook.Call("myCustomEvent", {"some", "arguments", 123})
```
@@ -26,13 +26,13 @@ Hook.Call("myCustomEvent", {"some", "arguments", 123})
With Lua, a new XML tags is added, it can be used to call Lua hooks inside status effects:
```xml
```
<StatusEffect type="OnUse">
<LuaHook name="doSomething">
<LuaHook name="doSomething" />
</StatusEffect>
```
```lua
```
Hook.Add("doSomething", "something", function (effect, deltaTime, item, targets, worldPosition)
print(effect, ' ', item)
end)
@@ -42,7 +42,7 @@ end)
Patching allows you to hook into existing methods in the game code, notice that it can be a little unstable depending on the method that you are patching, so be aware.
```lua
```
Hook.HookMethod("Barotrauma.CharacterInfo", "IncreaseSkillLevel", function (instance, ptable)
print(string.format("%s gained % xp", instance.Character.Name, ptable.increase))
end, Hook.HookMethodType.After)
@@ -1,3 +1,5 @@
# Installing Lua For Barotrauma Manually
## Adding Lua For Barotrauma to an existing server
1 - Download [latest version of LuaForBarotrauma](https://github.com/evilfactory/Barotrauma-lua-attempt/releases/tag/latest), choose the correct platform in the assets drop down.<br>
2 - Extract the zip file<br>
@@ -56,4 +58,10 @@ Same as above, but instead you need to copy/replace the following files:
7 - Done! Now run DedicatedServer.exe to run the modded server or run Barotrauma.exe to run the modded client.<br>
### Linux notice
Sometimes you will get steam initialization errors, most of the time it's because it's missing the linux64/steamclient.so binary, so you can just copy the binary from your steam instalation over to the folder and it should work.
Sometimes you will get steam initialization errors, most of the time it's because it's missing the linux64/steamclient.so binary, so you can just copy the binary from your steam instalation over to the folder and it should work.
## Checking if everything is working
If the commands `reloadlua` or `cl_reloadlua` work, it means you successfully installed the mod.
+15 -5
View File
@@ -1,6 +1,6 @@
# Lua Examples
```lua
```
Hook.Add('chatMessage', 'suicide_mod', function(msg, client)
if msg == '!suicide' and client.Character ~= nil then
client.Character.Kill(CauseOfDeathType.Unknown)
@@ -10,7 +10,9 @@ Hook.Add('chatMessage', 'suicide_mod', function(msg, client)
end)
```
```lua
<br>
```
Hook.Add("itemApplyTreatment", "testItemApplyTreatment", function (item, user, character, targetlimb)
if item.name == "Bandage" then
local pos = character.WorldPosition
@@ -21,7 +23,10 @@ Hook.Add("itemApplyTreatment", "testItemApplyTreatment", function (item, user, c
end)
```
```lua
<br>
```
-- for example: create an item in xml named RandomComponent and add the wiring inputs/outputs trigger_random and random_out
Hook.Add("signalReceived", "signalReceivedTest", function (signal, connection)
if connection.Item.name == "RandomComponent" and connection.Name == "trigger_random" then
@@ -30,7 +35,9 @@ Hook.Add("signalReceived", "signalReceivedTest", function (signal, connection)
end)
```
```lua
<br>
```
local discordWebHook = "your discord webhook here"
local function escapeQuotes(str)
@@ -45,7 +52,10 @@ Hook.Add("chatMessage", "discordIntegration", function (msg, client)
end)
```
```lua
<br>
```
-- by jimmyl
Hook.Add("chatMessage","controlhuskcommand",function(msg, client)
if msg == "!controlhusk" then
+1 -1
View File
@@ -6,7 +6,7 @@
<div class="wrapper">
<p style="text-align: center;"></p>
<h2>Welcome to the Lua For Barotrauma documentation!</h2>
<p>This is a work in progress documentation, not everything is documented here, but because Barotrauma classes are exposed to lua, you can check the Barotrauma source code for functions and fields that you can access.</p>
<p>This is a work in progress documentation, not everything is documented here, but because Barotrauma classes are exposed to Lua, you can check the Barotrauma source code for functions and fields that you can access.</p>
<h2>Installing Lua For Barotrauma</h2>
<p>Downloading and using the Core Content Package from <a href="https://steamcommunity.com/sharedfiles/filedetails/?id=2559634234" target="_blank">Workshop</a> should be enough to have it installed, but if you want to install it manually, you can check out <a href="{* ldoc.url('manual/installing-lua-for-barotrauma-manually') *}">this guide.</a>
+1 -1
View File
@@ -78,7 +78,7 @@ end
var elements = document.querySelectorAll("pre code")
hljs.configure({
languages: ["lua"]
languages: ["lua", ""]
});
for (var i = 0; i < elements.length; i++)