fix lua added commands breaking after reloadlua
This commit is contained in:
@@ -381,19 +381,49 @@ namespace Barotrauma
|
||||
return enabledPackages;
|
||||
}
|
||||
|
||||
private List<DebugConsole.Command> luaAddedCommand = new List<DebugConsole.Command>();
|
||||
|
||||
public void RemoveCommand(string name)
|
||||
{
|
||||
for (var i = 0; i < DebugConsole.Commands.Count; i++)
|
||||
{
|
||||
foreach (var cmdname in DebugConsole.Commands[i].names)
|
||||
{
|
||||
if (cmdname == name)
|
||||
{
|
||||
luaAddedCommand.Remove(DebugConsole.Commands[i]);
|
||||
DebugConsole.Commands.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 cmd = 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));
|
||||
}, isCheat);
|
||||
|
||||
luaAddedCommand.Add(cmd);
|
||||
DebugConsole.Commands.Add(cmd);
|
||||
}
|
||||
|
||||
public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names, (string[] a) => { env.CallFunction(onExecute, new object[] { a }); });
|
||||
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
foreach(var cmd in luaAddedCommand)
|
||||
{
|
||||
DebugConsole.Commands.Remove(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -311,6 +311,7 @@ namespace Barotrauma
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
game.Stop();
|
||||
hook.Call("stop", new object[] { });
|
||||
|
||||
hook = new LuaHook(null);
|
||||
|
||||
@@ -153,9 +153,9 @@ function serverLog(text, serverLogMessageType) end
|
||||
-- @realm shared
|
||||
-- @usage
|
||||
-- Hook.Add("jobsAssigned", "", function ()
|
||||
-- for key, value in pairs(Client.ClientList) do
|
||||
-- value.AssignedJob = {JobPrefab.Get("assistant"), 0}
|
||||
-- end
|
||||
-- for key, value in pairs(Client.ClientList) do
|
||||
-- value.AssignedJob = {JobPrefab.Get("assistant"), 0}
|
||||
-- end
|
||||
-- end)
|
||||
function jobsAssigned() end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user