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:
@@ -689,6 +689,8 @@ namespace Barotrauma
|
|||||||
return moduleBuilder;
|
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)
|
public void Add(string name, string identifier, LuaCsFunc func, ACsMod owner = null)
|
||||||
{
|
{
|
||||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||||
|
|||||||
@@ -704,7 +704,7 @@ namespace Barotrauma
|
|||||||
private readonly List<Identifier> talentTriggers;
|
private readonly List<Identifier> talentTriggers;
|
||||||
private readonly List<int> giveExperiences;
|
private readonly List<int> giveExperiences;
|
||||||
private readonly List<GiveSkill> giveSkills;
|
private readonly List<GiveSkill> giveSkills;
|
||||||
private readonly List<string> luaHook;
|
private readonly List<(string, ContentXElement)> luaHook;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long the effect runs (in seconds). Note that if <see cref="Stackable"/> is true,
|
/// 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));
|
giveSkills.Add(new GiveSkill(subElement, parentDebugName));
|
||||||
break;
|
break;
|
||||||
case "luahook":
|
case "luahook":
|
||||||
luaHook ??= new List<string>();
|
case "hook":
|
||||||
luaHook.Add(subElement.GetAttributeString("name", ""));
|
luaHook ??= new List<(string, ContentXElement)>();
|
||||||
|
luaHook.Add((subElement.GetAttributeString("name", ""), subElement));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1571,12 +1572,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (luaHook != null)
|
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)
|
if (result != null && result.Value) { return; }
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -103,21 +103,21 @@ This will give us a debug build of LuaCsForBarotrauma. A debug build gives us ac
|
|||||||
- MacSolution.sln
|
- MacSolution.sln
|
||||||
- LinuxSolution.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").\
|
-- 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.\
|
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.\
|
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).\
|
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:
|
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`.
|
- 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.
|
- 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.
|
#### Part 3: Setting up MSBuild to Copy Files into Local Mods.
|
||||||
|
|
||||||
|
|||||||
@@ -24,17 +24,20 @@ Hook.Call("myCustomEvent", {"some", "arguments", 123})
|
|||||||
|
|
||||||
## XML Status Effect Hooks
|
## 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">
|
<StatusEffect type="OnUse">
|
||||||
<LuaHook name="doSomething" />
|
<Hook name="doSomething" custom="thing" />
|
||||||
</StatusEffect>
|
</StatusEffect>
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
Hook.Add("doSomething", "something", function(effect, deltaTime, item, targets, worldPosition)
|
Hook.Add("doSomething", function(effect, deltaTime, item, targets, worldPosition, element)
|
||||||
print(effect, ' ', item)
|
print(effect, ' ', item)
|
||||||
|
|
||||||
|
-- You can also access the XML custom parameters
|
||||||
|
print(element.GetAttributeString("custom", "default value"))
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user