diff --git a/DeltaVFactionQuestLog/Data/Scripts/DeltaVQuestLog/PersistentFactionObjectives.cs b/DeltaVFactionQuestLog/Data/Scripts/DeltaVQuestLog/PersistentFactionObjectives.cs index 203f841..2208294 100644 --- a/DeltaVFactionQuestLog/Data/Scripts/DeltaVQuestLog/PersistentFactionObjectives.cs +++ b/DeltaVFactionQuestLog/Data/Scripts/DeltaVQuestLog/PersistentFactionObjectives.cs @@ -5,6 +5,7 @@ using Sandbox.ModAPI; using VRage.Game; using VRage.Game.Components; +using VRage.Game.ModAPI; using VRage.Utils; namespace Invalid.DeltaVQuestLog @@ -38,6 +39,7 @@ public override void LoadData() if (isServer) { + MyAPIGateway.Session.Factions.FactionStateChanged += FactionsOnFactionStateChanged; MyVisualScriptLogicProvider.PlayerConnected += OnPlayerConnected; } @@ -45,6 +47,18 @@ public override void LoadData() Networking = new QuestLogNetworking(); } + private void FactionsOnFactionStateChanged(MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId) + { + if (action == MyFactionStateChange.FactionMemberAcceptJoin) + { + GetFactionManger(fromFactionId)?.SendNetworkUpdate(); + } + if (action == MyFactionStateChange.FactionMemberLeave || action == MyFactionStateChange.FactionMemberKick) + { + MyVisualScriptLogicProvider.SetQuestlog(false, "", playerId); + } + } + protected override void UnloadData() { Networking.Close(); @@ -54,6 +68,7 @@ protected override void UnloadData() { SaveObjectives(); MyVisualScriptLogicProvider.PlayerConnected -= OnPlayerConnected; + MyAPIGateway.Session.Factions.FactionStateChanged -= FactionsOnFactionStateChanged; } I = null; @@ -70,15 +85,6 @@ public override void UpdateAfterSimulation() manager.Update10(); } - public override void BeforeStart() - { - if (MyAPIGateway.Session.Player == null) - return; - - if (MyAPIGateway.Session.Factions.TryGetPlayerFaction(MyAPIGateway.Session.Player.IdentityId) == null) - MyVisualScriptLogicProvider.RemoveQuestlogDetails(MyAPIGateway.Session.Player.IdentityId); - } - private void OnPlayerConnected(long playerId) { if (!isServer) return; @@ -87,6 +93,7 @@ private void OnPlayerConnected(long playerId) if (playerFaction == null) return; var factionId = playerFaction.FactionId; + MyVisualScriptLogicProvider.SetQuestlog(false, "", playerId); GetFactionManger(factionId)?.SendNetworkUpdate(); }