added a way to create console commands

This commit is contained in:
Evil Factory
2021-09-25 20:33:17 -03:00
parent a058d0a1bc
commit 17ecef8c67
5 changed files with 19 additions and 3 deletions
@@ -288,6 +288,20 @@ namespace Barotrauma
}
return enabledPackages;
}
public void AddCommand(string name, string help, object onExecute, object getValidArgs = null, bool isCheat = false)
{
DebugConsole.Commands.Add(new DebugConsole.Command(name, help, (string[] arg1) => { env.CallFunction(onExecute, new object[] { arg1 }); },
() => {
var result = env.CallFunction(getValidArgs, new object[] { });
if (result == null || !(result is string[][])) { return null; }
return (string[][])result;
}, isCheat = false));
}
public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names, (string[] a) => { env.CallFunction(onExecute, new object[] { a }); });
}
@@ -408,7 +408,7 @@ namespace Barotrauma
lua.Globals["DeliveryMethod"] = UserData.CreateStatic<DeliveryMethod>();
lua.Globals["ClientPacketHeader"] = UserData.CreateStatic<ClientPacketHeader>();
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
#if SERVER
#elif CLIENT