added a way for lua to override people's jobs
This commit is contained in:
@@ -2260,7 +2260,10 @@ namespace Barotrauma.Networking
|
||||
|
||||
AssignJobs(teamClients);
|
||||
|
||||
var result = new LuaResult(GameMain.Lua.hook.Call("jobsAssigned"));
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
|
||||
foreach (Client client in teamClients)
|
||||
{
|
||||
client.NeedsMidRoundSync = false;
|
||||
@@ -2340,59 +2343,61 @@ namespace Barotrauma.Networking
|
||||
spawnWaypoints = mainSubWaypoints;
|
||||
}
|
||||
Debug.Assert(spawnWaypoints.Count == mainSubWaypoints.Count);
|
||||
|
||||
for (int i = 0; i < teamClients.Count; i++)
|
||||
if (!result.Bool())
|
||||
{
|
||||
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false);
|
||||
spawnedCharacter.AnimController.Frozen = true;
|
||||
spawnedCharacter.TeamID = teamID;
|
||||
teamClients[i].Character = spawnedCharacter;
|
||||
var characterData = campaign?.GetClientCharacterData(teamClients[i]);
|
||||
if (characterData == null)
|
||||
for (int i = 0; i < teamClients.Count; i++)
|
||||
{
|
||||
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
|
||||
if (campaign != null)
|
||||
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false);
|
||||
spawnedCharacter.AnimController.Frozen = true;
|
||||
spawnedCharacter.TeamID = teamID;
|
||||
teamClients[i].Character = spawnedCharacter;
|
||||
var characterData = campaign?.GetClientCharacterData(teamClients[i]);
|
||||
if (characterData == null)
|
||||
{
|
||||
characterData = campaign.SetClientCharacterData(teamClients[i]);
|
||||
characterData.HasSpawned = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!characterData.HasItemData && !characterData.CharacterInfo.StartItemsGiven)
|
||||
{
|
||||
//clients who've chosen to spawn with the respawn penalty can have CharacterData without inventory data
|
||||
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
|
||||
if (campaign != null)
|
||||
{
|
||||
characterData = campaign.SetClientCharacterData(teamClients[i]);
|
||||
characterData.HasSpawned = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
characterData.SpawnInventoryItems(spawnedCharacter, spawnedCharacter.Inventory);
|
||||
if (!characterData.HasItemData && !characterData.CharacterInfo.StartItemsGiven)
|
||||
{
|
||||
//clients who've chosen to spawn with the respawn penalty can have CharacterData without inventory data
|
||||
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
characterData.SpawnInventoryItems(spawnedCharacter, spawnedCharacter.Inventory);
|
||||
}
|
||||
characterData.ApplyHealthData(spawnedCharacter);
|
||||
characterData.ApplyOrderData(spawnedCharacter);
|
||||
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
|
||||
spawnedCharacter.LoadTalents();
|
||||
|
||||
characterData.HasSpawned = true;
|
||||
}
|
||||
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign && spawnedCharacter.Info != null)
|
||||
{
|
||||
spawnedCharacter.Info.SetExperience(Math.Max(spawnedCharacter.Info.ExperiencePoints, mpCampaign.GetSavedExperiencePoints(teamClients[i])));
|
||||
mpCampaign.ClearSavedExperiencePoints(teamClients[i]);
|
||||
}
|
||||
characterData.ApplyHealthData(spawnedCharacter);
|
||||
characterData.ApplyOrderData(spawnedCharacter);
|
||||
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
|
||||
spawnedCharacter.LoadTalents();
|
||||
|
||||
characterData.HasSpawned = true;
|
||||
spawnedCharacter.OwnerClientEndPoint = teamClients[i].Connection.EndPointString;
|
||||
spawnedCharacter.OwnerClientName = teamClients[i].Name;
|
||||
}
|
||||
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign && spawnedCharacter.Info != null)
|
||||
|
||||
for (int i = teamClients.Count; i < teamClients.Count + bots.Count; i++)
|
||||
{
|
||||
spawnedCharacter.Info.SetExperience(Math.Max(spawnedCharacter.Info.ExperiencePoints, mpCampaign.GetSavedExperiencePoints(teamClients[i])));
|
||||
mpCampaign.ClearSavedExperiencePoints(teamClients[i]);
|
||||
Character spawnedCharacter = Character.Create(characterInfos[i], spawnWaypoints[i].WorldPosition, characterInfos[i].Name, isRemotePlayer: false, hasAi: true);
|
||||
spawnedCharacter.TeamID = teamID;
|
||||
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
|
||||
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
|
||||
// talents are only avilable for players in online sessions, but modders or someone else might want to have them loaded anyway
|
||||
spawnedCharacter.LoadTalents();
|
||||
}
|
||||
|
||||
spawnedCharacter.OwnerClientEndPoint = teamClients[i].Connection.EndPointString;
|
||||
spawnedCharacter.OwnerClientName = teamClients[i].Name;
|
||||
}
|
||||
|
||||
for (int i = teamClients.Count; i < teamClients.Count + bots.Count; i++)
|
||||
{
|
||||
Character spawnedCharacter = Character.Create(characterInfos[i], spawnWaypoints[i].WorldPosition, characterInfos[i].Name, isRemotePlayer: false, hasAi: true);
|
||||
spawnedCharacter.TeamID = teamID;
|
||||
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
|
||||
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
|
||||
// talents are only avilable for players in online sessions, but modders or someone else might want to have them loaded anyway
|
||||
spawnedCharacter.LoadTalents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,12 @@ namespace Barotrauma
|
||||
return (GUITextBox.OnEnterHandler)((GUITextBox a, string b) => new LuaResult(LuaSetup.luaSetup.CallFunction(function, a, b)).Bool());
|
||||
});
|
||||
#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>()
|
||||
|
||||
+7
-1
@@ -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.
|
||||
-- @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.
|
||||
-- @realm shared
|
||||
|
||||
Reference in New Issue
Block a user