Skip to content

Commit

Permalink
hnngh
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 7, 2024
1 parent aacacba commit d9104ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heart_Module.Data.Scripts.HeartModule.Definitions.StandardClasses
{
[ProtoContract]
public class ChatCommand
{
public string modName;
public Action<string[]> action;

public ChatCommand(string modName, Action<string[]> action)
{
this.modName = modName;
this.action = action;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Heart_Module.Data.Scripts.HeartModule.ErrorHandler;
using Heart_Module.Data.Scripts.HeartModule.Projectiles;
using RichHudFramework.Internal;
using RichHudFramework.UI;
using Sandbox.Game.GameSystems.Chat;
using Sandbox.Game.Screens.Helpers.RadialMenuActions;
Expand Down Expand Up @@ -76,11 +77,14 @@ private void Command_MessageEnteredSender(ulong sender, string messageText, ref

sendToOthers = false;

string[] parts = messageText.Substring(4).ToLower().Split(' '); // Convert commands to be more parseable
string[] parts = messageText.Substring(4).Split(' '); // Convert commands to be more parseable

// Really basic command handler
if (commands.ContainsKey(parts[0]))
commands[parts[0]].action.Invoke(parts);
if (commands.ContainsKey(parts[0].ToLower()))
commands[parts[0].ToLower()].action.Invoke(parts);
else
MyAPIGateway.Utilities.ShowMessage("[OCF]", $"Unrecognized command " + parts[0]);

}

public void Close()
Expand All @@ -106,7 +110,7 @@ public static void AddCommand(string command, string helpText, Action<string[]>
return;
}

I.commands.Add(modName, new Command(modName, helpText, action));
I.commands.Add(command, new Command(modName, helpText, action));
HeartData.I.Log.Log($"Registered new chat command \"/{command}\" from [{modName}]");
}

Expand Down

0 comments on commit d9104ad

Please sign in to comment.