You can now grab the parameters passed into XML status effects and added a variation of the Hook Add method that only takes the event name

This commit is contained in:
EvilFactory
2024-04-20 18:47:07 -03:00
parent 123a212251
commit 71376cfe5f
4 changed files with 25 additions and 20 deletions

View File

@@ -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));

View File

@@ -704,7 +704,7 @@ namespace Barotrauma
private readonly List<Identifier> talentTriggers;
private readonly List<int> giveExperiences;
private readonly List<GiveSkill> giveSkills;
private readonly List<string> luaHook;
private readonly List<(string, ContentXElement)> luaHook;
/// <summary>
/// How long the effect runs (in seconds). Note that if <see cref="Stackable"/> is true,
@@ -1085,8 +1085,9 @@ namespace Barotrauma
giveSkills.Add(new GiveSkill(subElement, parentDebugName));
break;
case "luahook":
luaHook ??= new List<string>();
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<bool?>(luaHooks, this, deltaTime, entity, targets, worldPosition);
var result = GameMain.LuaCs.Hook.Call<bool?>(hookName, this, deltaTime, entity, targets, worldPosition, element);
if (result != null && result.Value)
return;
if (result != null && result.Value) { return; }
}
}

View File

@@ -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.

View File

@@ -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:
```
<StatusEffect type="OnUse">
<LuaHook name="doSomething" />
<Hook name="doSomething" custom="thing" />
</StatusEffect>
```
```
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)
```