diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c55b5e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin +obj +.vs +.vscode \ No newline at end of file diff --git a/GodModeArea.csproj b/GodModeArea.csproj new file mode 100644 index 0000000..bb0db96 --- /dev/null +++ b/GodModeArea.csproj @@ -0,0 +1,35 @@ + + + + net4.8 + enable + enable + 10 + + + + + Libs\Assembly-CSharp.dll + + + Libs\com.rlabrecque.steamworks.net.dll + + + Libs\Rocket.API.dll + + + Libs\Rocket.Core.dll + + + Libs\Rocket.Unturned.dll + + + Libs\UnityEngine.dll + + + Libs\UnityEngine.CoreModule.dll + UnityEngineCoreModule + + + + diff --git a/GodModeArea.sln b/GodModeArea.sln new file mode 100644 index 0000000..cd20f79 --- /dev/null +++ b/GodModeArea.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GodModeArea", "GodModeArea.csproj", "{D1823CED-91A4-4A22-8D9A-BB70B78290E9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D1823CED-91A4-4A22-8D9A-BB70B78290E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1823CED-91A4-4A22-8D9A-BB70B78290E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1823CED-91A4-4A22-8D9A-BB70B78290E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1823CED-91A4-4A22-8D9A-BB70B78290E9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8EBB3434-0B21-46CB-96AC-EFD8B1564733} + EndGlobalSection +EndGlobal diff --git a/GodModeAreaConfiguration.cs b/GodModeAreaConfiguration.cs new file mode 100644 index 0000000..75e9d32 --- /dev/null +++ b/GodModeAreaConfiguration.cs @@ -0,0 +1,37 @@ +using Rocket.API; + +namespace GodModeArea +{ + public class GodModeAreaConfiguration : IRocketPluginConfiguration + { + public List GodModeAreas = new(); + public int GodModeTickrate = 100; + public int GodModeMillisecondsExitDelay = 5000; + public bool GodModeDefaultValue = false; + public bool DebugExtended = false; + public void LoadDefaults() + { + GodModeAreas = new() + { + new() + { + X1 = 431.41, + X2 = 440.92, + Y1 = 51.00, + Y2 = 54.00, + Z1 = 437.25, + Z2 = 447.05 + } + }; + } + } + public class GodModeAreas + { + public double X1; + public double Y1; + public double Z1; + public double X2; + public double Y2; + public double Z2; + } +} diff --git a/GodModeAreaPlugin.cs b/GodModeAreaPlugin.cs new file mode 100644 index 0000000..44f7ada --- /dev/null +++ b/GodModeAreaPlugin.cs @@ -0,0 +1,109 @@ +extern alias UnityEngineCoreModule; +using Rocket.API.Collections; +using Rocket.Core.Logging; +using Rocket.Core.Plugins; +using Rocket.Core.Utils; +using Rocket.Unturned.Chat; +using Rocket.Unturned.Player; +using SDG.Unturned; +using UnityCoreModule = UnityEngineCoreModule.UnityEngine; + +namespace GodModeArea +{ + public class GodModeAreaPlugin : RocketPlugin + { + public static readonly Dictionary PlayerOnGodMode = new(); + public override void LoadPlugin() + { + base.LoadPlugin(); + // Instanciating the player events + Rocket.Unturned.U.Events.OnPlayerConnected += OnPlayerConnected; + Rocket.Unturned.U.Events.OnPlayerDisconnected += OnPlayerDisconnected; + Rocket.Unturned.Events.UnturnedPlayerEvents.OnPlayerUpdatePosition += PositionUpdate; + Logger.Log("GodModeArea by LeandroTheDev"); + } + + private void PositionUpdate(UnturnedPlayer player, UnityCoreModule.Vector3 position) + { + // Debug + if (Configuration.Instance.DebugExtended) + Logger.Log($"Player: {player.DisplayName}, Mode: {player.GodMode}, Position {player.Position}"); + // Execute the tickrate for the player only if his exist in god mode context + if (PlayerOnGodMode.TryGetValue(player.Id, out _)) + { + foreach (GodModeAreas area in Configuration.Instance.GodModeAreas) + { + // Verify X position + if (position.x < area.X1 || position.x > area.X2) + { + // Remove the player from godmode + if (PlayerOnGodMode[player.Id]) RemovePlayerFromGodMode(player); + return; + } + // Verify Y position + else if (position.y < area.Y1 || position.y > area.Y2) + { + // Remove the player from godmode + if (PlayerOnGodMode[player.Id]) RemovePlayerFromGodMode(player); + return; + } + // Verifiy Z position + else if (position.z < area.Z1 || position.z > area.Z2) + { + // Remove the player from godmode + if (PlayerOnGodMode[player.Id]) RemovePlayerFromGodMode(player); + return; + } + } + if (!player.GodMode) + { + player.GodMode = true; + PlayerOnGodMode[player.Id] = true; + } + } + } + + + private void OnPlayerConnected(UnturnedPlayer player) + { + // Add the default value for new player + player.GodMode = Configuration.Instance.GodModeDefaultValue; + PlayerOnGodMode.Add(player.Id, Configuration.Instance.GodModeDefaultValue); + } + + private void OnPlayerDisconnected(UnturnedPlayer player) + { + // Clear Variables + PlayerOnGodMode.Remove(player.Id); + } + + private void RemovePlayerFromGodMode(UnturnedPlayer player) + { + // Informate the player the are exiting the zone + UnturnedChat.Say(player, Translate("Exiting_God_Mode", Math.Round(Configuration.Instance.GodModeMillisecondsExitDelay / 1000.0)), Palette.COLOR_R); + + // Remove the player from the list + PlayerOnGodMode[player.Id] = false; + + // After delay disable the god mode + Task.Delay(Configuration.Instance.GodModeMillisecondsExitDelay).ContinueWith((_) => + { + // If player back to the god mode again just cancel + if (PlayerOnGodMode[player.Id]) return; + // Inform the player + TaskDispatcher.QueueOnMainThread(() => + { + UnturnedChat.Say(player, Translate("No_Longer_God_Mode"), Palette.COLOR_R); + // Remove god mod + player.GodMode = false; + }); + }); + } + + public override TranslationList DefaultTranslations => new() + { + { "Exiting_God_Mode", "Exiting zone, you have {0} seconds of invulnerability" }, + { "No_Longer_God_Mode", "You are now vulnerable!" }, + }; + } +} diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2bcf3c4 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,14 @@ + FREE TO MODIFY PUBLIC LICENSE + February 2024 + + Copyright (C) 2024 Leandro Schmidt + + Anyone has free access to the contents to modify or + produce similar content, as long as the name is + different from the original. + + FREE TO MODIFY PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, + DISTRIBUTION AND MODIFICATION + + 0. Free to Modify. \ No newline at end of file diff --git a/Libs/Assembly-CSharp.dll b/Libs/Assembly-CSharp.dll new file mode 100644 index 0000000..30e129d Binary files /dev/null and b/Libs/Assembly-CSharp.dll differ diff --git a/Libs/Rocket.API.dll b/Libs/Rocket.API.dll new file mode 100644 index 0000000..9ea5596 Binary files /dev/null and b/Libs/Rocket.API.dll differ diff --git a/Libs/Rocket.Core.dll b/Libs/Rocket.Core.dll new file mode 100644 index 0000000..616494e Binary files /dev/null and b/Libs/Rocket.Core.dll differ diff --git a/Libs/Rocket.Unturned.dll b/Libs/Rocket.Unturned.dll new file mode 100644 index 0000000..04a8466 Binary files /dev/null and b/Libs/Rocket.Unturned.dll differ diff --git a/Libs/UnityEngine.CoreModule.dll b/Libs/UnityEngine.CoreModule.dll new file mode 100644 index 0000000..51498d2 Binary files /dev/null and b/Libs/UnityEngine.CoreModule.dll differ diff --git a/Libs/UnityEngine.dll b/Libs/UnityEngine.dll new file mode 100644 index 0000000..22de84d Binary files /dev/null and b/Libs/UnityEngine.dll differ diff --git a/Libs/com.rlabrecque.steamworks.net.dll b/Libs/com.rlabrecque.steamworks.net.dll new file mode 100644 index 0000000..a147d9d Binary files /dev/null and b/Libs/com.rlabrecque.steamworks.net.dll differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..b387377 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# God Mode Area +Creates a fully configurable area, players in that area will become god mode, if player exit will lose, configurable timer to lose after exiting area. \ No newline at end of file