diff --git a/Barotrauma/BarotraumaClient/WindowsClient.csproj b/Barotrauma/BarotraumaClient/WindowsClient.csproj
index 635305e76..bbe507a0a 100644
--- a/Barotrauma/BarotraumaClient/WindowsClient.csproj
+++ b/Barotrauma/BarotraumaClient/WindowsClient.csproj
@@ -124,6 +124,7 @@
+
diff --git a/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs b/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs
index 80515d9bb..c775031ec 100644
--- a/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs
+++ b/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs
@@ -12,6 +12,7 @@ using System.Reflection;
using System.Threading;
using System.Xml.Linq;
using MoonSharp.Interpreter;
+using MoonSharp.VsCodeDebugger;
namespace Barotrauma
{
@@ -135,6 +136,7 @@ namespace Barotrauma
CheckContentPackage();
Lua = new LuaSetup();
+
}
@@ -361,7 +363,7 @@ namespace Barotrauma
TaskPool.Update();
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
- GameMain.Lua.hook.Call("think", new DynValue[] { DynValue.NewNumber(elapsedTime) });
+ GameMain.Lua.hook.Call("think", new DynValue[] { DynValue.NewNumber(elapsedTime), DynValue.NewNumber(Timing.TotalTime) });
Timing.Accumulator -= Timing.Step;
}
diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaScriptLoader.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaScriptLoader.cs
index eb3aa669f..73e984458 100644
--- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaScriptLoader.cs
+++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaScriptLoader.cs
@@ -29,7 +29,22 @@ namespace Barotrauma
{
Console.WriteLine(s);
- script.DoFile(s); // i hate windows
+ try
+ {
+ script.DoFile(s); // i hate windows
+ }
+ catch (Exception e)
+ {
+ if (e is InterpreterException)
+ {
+
+ Console.WriteLine(((InterpreterException)e).DecoratedMessage);
+ }
+ else
+ {
+ Console.WriteLine(e.ToString());
+ }
+ }
}
}
diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs
index 0201b5908..f1bb62a0b 100644
--- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs
+++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs
@@ -6,6 +6,7 @@ using Barotrauma.Networking;
using MoonSharp.Interpreter;
using Microsoft.Xna.Framework;
using System.Threading.Tasks;
+using MoonSharp.VsCodeDebugger;
namespace Barotrauma
{
@@ -15,6 +16,7 @@ namespace Barotrauma
public Script lua;
public Hook hook;
+ public bool overrideTraitors = false;
public void DoString(string code)
{
@@ -24,7 +26,36 @@ namespace Barotrauma
}
catch (Exception e)
{
- Console.WriteLine(e.ToString());
+ if (e is InterpreterException)
+ {
+
+ Console.WriteLine(((InterpreterException)e).DecoratedMessage);
+ }
+ else
+ {
+ Console.WriteLine(e.ToString());
+ }
+ }
+ }
+
+
+ public void RunFunction(DynValue func)
+ {
+ try
+ {
+ lua.Call(func);
+ }
+ catch (Exception e)
+ {
+ if (e is InterpreterException)
+ {
+
+ Console.WriteLine(((InterpreterException)e).DecoratedMessage);
+ }
+ else
+ {
+ Console.WriteLine(e.ToString());
+ }
}
}
@@ -86,11 +117,23 @@ namespace Barotrauma
private class Game
{
+ LuaSetup env;
+
+ public Game(LuaSetup e)
+ {
+ env = e;
+ }
+
public static void SendMessage(string msg, int messageType = 0, Client sender = null, Character character = null)
{
GameMain.Server.SendChatMessage(msg, (ChatMessageType)messageType, sender, character);
}
+ public static void SendTraitorMessage(Client client, string msg, int type)
+ {
+ GameMain.Server.SendTraitorMessage(client, msg, "", (TraitorMessageType)type);
+ }
+
public static void SendDirectChatMessage(string sendername, string text, Character sender, int messageType = 0, Client client = null)
{
@@ -100,6 +143,11 @@ namespace Barotrauma
}
+ public void OverrideTraitors(bool o)
+ {
+ env.overrideTraitors = o;
+ }
+
public static void Log(string message, int type)
{
GameServer.Log(message, (ServerLog.MessageType)type);
@@ -128,16 +176,22 @@ namespace Barotrauma
private class LuaTimer
{
- public Script env;
+ public LuaSetup env;
- public LuaTimer(Script e)
+ public LuaTimer(LuaSetup e)
{
env = e;
}
public void Simple(int time, DynValue function)
{
- Task.Delay(new TimeSpan(0, 0, 0, 0, time)).ContinueWith(o => { env.Call(function); });
+
+ Task.Delay(time).ContinueWith(o => { env.RunFunction(function); });
+ }
+
+ public static double GetTime()
+ {
+ return Timing.TotalTime;
}
@@ -207,7 +261,7 @@ namespace Barotrauma
hookFunctions.Add(new HookFunction(name, hookName, function));
}
- public void Call(string name, DynValue[] args)
+ public DynValue Call(string name, DynValue[] args)
{
foreach(HookFunction hf in hookFunctions)
{
@@ -215,22 +269,31 @@ namespace Barotrauma
{
try
{
- env.Call(hf.function, args);
- }catch(Exception e)
+ return env.Call(hf.function, args);
+ }
+ catch (Exception e)
{
- Console.WriteLine(e.ToString());
+ if (e is InterpreterException)
+ {
+
+ Console.WriteLine(((InterpreterException)e).DecoratedMessage);
+ }
+ else
+ {
+ Console.WriteLine(e.ToString());
+ }
}
}
}
+
+ return null;
}
}
public LuaSetup()
{
-
Console.WriteLine("Lua!");
- LuaCustomConverters.RegisterAll();
LuaScriptLoader luaScriptLoader = new LuaScriptLoader();
@@ -253,10 +316,10 @@ namespace Barotrauma
hook = new Hook(lua);
lua.Globals["Player"] = new Player();
- lua.Globals["Game"] = new Game();
+ lua.Globals["Game"] = new Game(this);
lua.Globals["Hook"] = hook;
lua.Globals["Random"] = new LuaRandom();
- lua.Globals["Timer"] = new LuaTimer(lua);
+ lua.Globals["Timer"] = new LuaTimer(this);
luaScriptLoader.RunFolder("Lua/autorun", lua);
diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs
index 3bf2746d7..3011c6f5e 100644
--- a/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs
+++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs
@@ -127,6 +127,21 @@ namespace Barotrauma.Networking
return;
}
+ var should = GameMain.Lua.hook.Call("chatMessage", new DynValue[] { DynValue.NewString(txt), UserData.Create(c) });
+
+
+ if(should != null)
+ {
+ if (should.CastToBool())
+ {
+ return;
+ }
+ else
+ {
+
+ }
+ }
+
if (type == ChatMessageType.Order)
{
if (c.Character == null || c.Character.SpeechImpediment >= 100.0f || c.Character.IsDead) { return; }
@@ -178,9 +193,6 @@ namespace Barotrauma.Networking
}
- GameMain.Lua.hook.Call("chatMessage", new DynValue[] { DynValue.NewString(txt), UserData.Create(c) });
-
-
}
public int EstimateLengthBytesServer(Client c)
diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs
index a0ed09782..940bb8f23 100644
--- a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs
+++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs
@@ -2345,8 +2345,11 @@ namespace Barotrauma.Networking
{
if (!(GameMain.GameSession?.GameMode is CampaignMode))
{
- TraitorManager = new TraitorManager();
- TraitorManager.Start(this);
+ if (!GameMain.Lua.overrideTraitors)
+ {
+ TraitorManager = new TraitorManager();
+ TraitorManager.Start(this);
+ }
}
}
diff --git a/Barotrauma/BarotraumaServer/WindowsServer.csproj b/Barotrauma/BarotraumaServer/WindowsServer.csproj
index 31c73c5ca..2a10082bc 100644
--- a/Barotrauma/BarotraumaServer/WindowsServer.csproj
+++ b/Barotrauma/BarotraumaServer/WindowsServer.csproj
@@ -82,6 +82,7 @@
+