Skip to content

Commit

Permalink
Update PersistentFactionObjectives.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Dec 2, 2024
1 parent d319066 commit 920aec3
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ private void OnMessageEntered(string messageText, ref bool sendToOthers)
{
if (!messageText.StartsWith("/obj") && !messageText.StartsWith("/objective")) return;

// Only process commands on the client side
if (isServer && !MyAPIGateway.Multiplayer.IsServer) return;

sendToOthers = false;

var args = messageText.Split(' ');
Expand Down Expand Up @@ -214,9 +217,19 @@ private void HandleAddObjective(string[] args, long factionId, long playerId)
SaveObjectives();

string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown";
string title = $"Faction Objectives [Added by {playerName}: {objectiveText}]";

// Update to show quest log immediately after adding
ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Added by {playerName}: {objectiveText}]");
// In singleplayer or on client, show directly
if (!MyAPIGateway.Utilities.IsDedicated)
{
DisplayQuestLog(factionObjectives[factionId], title, playerId);
}

// If server, broadcast to all faction members
if (isServer)
{
ShowQuestLogToFaction(factionId, 30, title);
}

MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} added objective: {objectiveText}");
}
Expand Down Expand Up @@ -292,9 +305,19 @@ private void HandleRemoveObjective(string[] args, long factionId, long playerId)
SaveObjectives();

string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown";
string title = $"Faction Objectives [Removed by {playerName}: {removedObjective}]";

// Update to show quest log immediately after removing
ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Removed by {playerName}: {removedObjective}]");
// In singleplayer or on client, show directly
if (!MyAPIGateway.Utilities.IsDedicated)
{
DisplayQuestLog(factionObjectives[factionId], title, playerId);
}

// If server, broadcast to all faction members
if (isServer)
{
ShowQuestLogToFaction(factionId, 30, title);
}

MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} removed objective: {removedObjective}");
}
Expand All @@ -317,8 +340,17 @@ private void HandleBroadcast(string[] args, long factionId)
var playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown";
string customTitle = $"Faction Objectives [Broadcasted by {playerName}, {duration}s]";

// Broadcast to faction members
ShowQuestLogToFaction(factionId, duration, customTitle);
// In singleplayer or on client, show directly
if (!MyAPIGateway.Utilities.IsDedicated)
{
DisplayQuestLog(factionObjectives[factionId], customTitle, MyAPIGateway.Session.Player.IdentityId);
}

// If server, broadcast to all faction members
if (isServer)
{
ShowQuestLogToFaction(factionId, duration, customTitle);
}

MyAPIGateway.Utilities.ShowMessage("Objectives", $"Broadcasting objectives for {duration} seconds by {playerName}.");
}
Expand Down

0 comments on commit 920aec3

Please sign in to comment.