added a way for lua to override people's jobs

This commit is contained in:
Evil Factory
2021-11-30 11:36:00 -03:00
parent 1972772fb3
commit 7c8536127c
3 changed files with 59 additions and 42 deletions
@@ -2260,7 +2260,10 @@ namespace Barotrauma.Networking
AssignJobs(teamClients); AssignJobs(teamClients);
var result = new LuaResult(GameMain.Lua.hook.Call("jobsAssigned"));
List<CharacterInfo> characterInfos = new List<CharacterInfo>(); List<CharacterInfo> characterInfos = new List<CharacterInfo>();
foreach (Client client in teamClients) foreach (Client client in teamClients)
{ {
client.NeedsMidRoundSync = false; client.NeedsMidRoundSync = false;
@@ -2340,7 +2343,8 @@ namespace Barotrauma.Networking
spawnWaypoints = mainSubWaypoints; spawnWaypoints = mainSubWaypoints;
} }
Debug.Assert(spawnWaypoints.Count == mainSubWaypoints.Count); Debug.Assert(spawnWaypoints.Count == mainSubWaypoints.Count);
if (!result.Bool())
{
for (int i = 0; i < teamClients.Count; i++) for (int i = 0; i < teamClients.Count; i++)
{ {
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false); Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false);
@@ -2395,6 +2399,7 @@ namespace Barotrauma.Networking
spawnedCharacter.LoadTalents(); spawnedCharacter.LoadTalents();
} }
} }
}
if (crewManager != null && crewManager.HasBots) if (crewManager != null && crewManager.HasBots)
{ {
@@ -45,6 +45,12 @@ namespace Barotrauma
return (GUITextBox.OnEnterHandler)((GUITextBox a, string b) => new LuaResult(LuaSetup.luaSetup.CallFunction(function, a, b)).Bool()); return (GUITextBox.OnEnterHandler)((GUITextBox a, string b) => new LuaResult(LuaSetup.luaSetup.CallFunction(function, a, b)).Bool());
}); });
#endif #endif
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Pair<JobPrefab, int>), v =>
{
return new Pair<JobPrefab, int>((JobPrefab)v.Table.Get(1).ToObject(), (int)v.Table.Get(2).CastToNumber());
});
} }
public static void RegisterAction<T>() public static void RegisterAction<T>()
+7 -1
View File
@@ -151,7 +151,13 @@ function serverLog(text, serverLogMessageType) end
--- Called each time a new round start job has been assigned, this context allows for you to change the role before it's applied in game. --- Called each time a new round start job has been assigned, this context allows for you to change the role before it's applied in game.
-- @realm shared -- @realm shared
function jobAssigned(text, serverLogMessageType) end function jobsAssigned() end
-- @usage
-- Hook.Add("jobsAssigned", "", function ()
-- for key, value in pairs(Client.ClientList) do
-- value.AssignedJob = {JobPrefab.Get("assistant"), 0}
-- end
-- end)
--- Check if a client is allowed to hear radio voice to another client, return true to allow, false to disallow. --- Check if a client is allowed to hear radio voice to another client, return true to allow, false to disallow.
-- @realm shared -- @realm shared