diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs index 08d5c33cc..337abbe75 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs @@ -689,6 +689,8 @@ namespace Barotrauma return moduleBuilder; } + public void Add(string name, LuaCsFunc func, ACsMod owner = null) => Add(name, name, func, owner); + public void Add(string name, string identifier, LuaCsFunc func, ACsMod owner = null) { if (name == null) throw new ArgumentNullException(nameof(name)); diff --git a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs index b587f0e1d..01b05f328 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs @@ -704,7 +704,7 @@ namespace Barotrauma private readonly List talentTriggers; private readonly List giveExperiences; private readonly List giveSkills; - private readonly List luaHook; + private readonly List<(string, ContentXElement)> luaHook; /// /// How long the effect runs (in seconds). Note that if is true, @@ -1085,8 +1085,9 @@ namespace Barotrauma giveSkills.Add(new GiveSkill(subElement, parentDebugName)); break; case "luahook": - luaHook ??= new List(); - luaHook.Add(subElement.GetAttributeString("name", "")); + case "hook": + luaHook ??= new List<(string, ContentXElement)>(); + luaHook.Add((subElement.GetAttributeString("name", ""), subElement)); break; } } @@ -1571,12 +1572,11 @@ namespace Barotrauma if (luaHook != null) { - foreach (string luaHooks in luaHook) + foreach ((string hookName, ContentXElement element) in luaHook) { - var result = GameMain.LuaCs.Hook.Call(luaHooks, this, deltaTime, entity, targets, worldPosition); + var result = GameMain.LuaCs.Hook.Call(hookName, this, deltaTime, entity, targets, worldPosition, element); - if (result != null && result.Value) - return; + if (result != null && result.Value) { return; } } } diff --git a/luacs-docs/cs/intro.md b/luacs-docs/cs/intro.md index 0c0c6a460..6be88ef89 100644 --- a/luacs-docs/cs/intro.md +++ b/luacs-docs/cs/intro.md @@ -103,21 +103,21 @@ This will give us a debug build of LuaCsForBarotrauma. A debug build gives us ac - MacSolution.sln - LinuxSolution.sln ``` --- NOTE: This tutorial assumes that you are using the `WindowsSolution.sln`. For other platforms, the naming of files may be slightly different (MacXXX, LinuxXXX, where 'XXX' is either "Client" or "Server").\ -\ -3. In the Project Settings for `WindowsClient` and `WindowsServer`, you want to change the `Platform Target` from `Any CPU` to `x64`. This is necessary for OpenAL code to build successfully.\ -\ +-- NOTE: This tutorial assumes that you are using the `WindowsSolution.sln`. For other platforms, the naming of files may be slightly different (MacXXX, LinuxXXX, where 'XXX' is either "Client" or "Server"). + +3. In the Project Settings for `WindowsClient` and `WindowsServer`, you want to change the `Platform Target` from `Any CPU` to `x64`. This is necessary for OpenAL code to build successfully. + 4. Build the whole Solution (`Build -> Build Solution`). This will create the necessary dependencies from libraries and make sure that there are no errors at this point.\ -\ + 5. For both the `WindowsClient` and `WindowsServer` projects, set their output/build type to `DEBUG` (should be in a drop-down menu at the top next to a green play button).\ -\ -6. Select `Build Solution`. This will generate Debug builds for use. This debug build will now exist in `./Barotrauma/bin/DebugXXX/net6.0/` where `XXX` is based on your Solution choice. IE. `./Barotrauma/bin/DebugWindows/net6.0`.\ -\ + +6. Select `Build Solution`. This will generate Debug builds for use. This debug build will now exist in `./Barotrauma/bin/DebugXXX/net6.0/` where `XXX` is based on your Solution choice. IE. `./Barotrauma/bin/DebugWindows/net6.0`. + 7. Make the local folder in Barotrauma/LocalMods/ for your mod: - A. Navigate into the Client Debug Build folder (or game folder if you are coming from Part 3, Step 3) and then into `/LocalMods`. - B. CREATE a folder with the name of your mod. Ideally, it should match the name of your `.sln` file with the extension. -- C. COPY the path to this directory (with your mod) and save it in a sticky note or .txt file. We will be using it shortly.\ -\ +- C. COPY the path to this directory (with your mod) and save it in a sticky note or .txt file. We will be using it shortly. + --- #### Part 3: Setting up MSBuild to Copy Files into Local Mods. diff --git a/luacs-docs/lua/manual/how-to-use-hooks.md b/luacs-docs/lua/manual/how-to-use-hooks.md index b8d871a9f..94d1632ad 100644 --- a/luacs-docs/lua/manual/how-to-use-hooks.md +++ b/luacs-docs/lua/manual/how-to-use-hooks.md @@ -24,17 +24,20 @@ 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: +With Lua, a new XML tags is added, it can be used to call hooks inside status effects: ``` - + ``` ``` -Hook.Add("doSomething", "something", function(effect, deltaTime, item, targets, worldPosition) +Hook.Add("doSomething", function(effect, deltaTime, item, targets, worldPosition, element) print(effect, ' ', item) + + -- You can also access the XML custom parameters + print(element.GetAttributeString("custom", "default value")) end) ```