update docs

This commit is contained in:
Evil Factory
2022-03-05 23:12:56 -03:00
parent 422edc7fa4
commit a2dc2c5ed0
19 changed files with 752 additions and 73 deletions
+51
View File
@@ -0,0 +1,51 @@
# How to use hooks
Hooks are basically functions that get called when events happen in-game, like chat messages. They can be triggered either by Lua itself or the game code.
## Adding hooks
Hooks can be added like this:
```lua
Hook.Add("chatMessage", "test", function(message, client)
print(client.Name .. " has sent " .. message)
end)
```
The event name (first argument), is case-insensitive, so you can call it chatMessage, cHaTmEsSaGe, chatmessage, etc.
## Calling hooks
You can also call hooks with the following code:
```lua
Hook.Call("myCustomEvent", {"some", "arguments", 123})
```
## XML Status Effect Hooks
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">
</StatusEffect>
```
```lua
Hook.Add("doSomething", "something", function (effect, deltaTime, item, targets, worldPosition)
print(effect, ' ', item)
end)
```
## Patching
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)
```
If you return anything other than nil, it will stop the execution of the method, if the method has a return type, it will also return what you returned in the Lua function. (Only in Hook.HookMethodType.After)
+1 -1
View File
@@ -62,7 +62,7 @@ Hook.Add("chatMessage","controlhuskcommand",function(msg, client)
local suitablechars = {}
for i = 1, #chars, 1 do
local charat = chars[i]
if not charat.IsDead and string.match(string.lower(charat.SpeciesName), "husk") and not charat IsRemotelyControlled then
if not charat.IsDead and string.match(string.lower(charat.SpeciesName), "husk") and not charat.IsRemotelyControlled then
table.insert(suitablechars, charat)
end
end