Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LeandroTheDev committed May 19, 2024
0 parents commit 62544f5
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin
obj
.vs
.vscode
35 changes: 35 additions & 0 deletions GodModeArea.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net4.8</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>Libs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="com.rlabrecque.steamworks.net">
<HintPath>Libs\com.rlabrecque.steamworks.net.dll</HintPath>
</Reference>
<Reference Include="Rocket.API">
<HintPath>Libs\Rocket.API.dll</HintPath>
</Reference>
<Reference Include="Rocket.Core">
<HintPath>Libs\Rocket.Core.dll</HintPath>
</Reference>
<Reference Include="Rocket.Unturned">
<HintPath>Libs\Rocket.Unturned.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>Libs\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>Libs\UnityEngine.CoreModule.dll</HintPath>
<Aliases>UnityEngineCoreModule</Aliases>
</Reference>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions GodModeArea.sln
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions GodModeAreaConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Rocket.API;

namespace GodModeArea
{
public class GodModeAreaConfiguration : IRocketPluginConfiguration
{
public List<GodModeAreas> 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;
}
}
109 changes: 109 additions & 0 deletions GodModeAreaPlugin.cs
Original file line number Diff line number Diff line change
@@ -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<GodModeAreaConfiguration>
{
public static readonly Dictionary<string, bool> 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!" },
};
}
}
14 changes: 14 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FREE TO MODIFY PUBLIC LICENSE
February 2024

Copyright (C) 2024 Leandro Schmidt <leandro.schmidt.profissional@gmail.com>

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.
Binary file added Libs/Assembly-CSharp.dll
Binary file not shown.
Binary file added Libs/Rocket.API.dll
Binary file not shown.
Binary file added Libs/Rocket.Core.dll
Binary file not shown.
Binary file added Libs/Rocket.Unturned.dll
Binary file not shown.
Binary file added Libs/UnityEngine.CoreModule.dll
Binary file not shown.
Binary file added Libs/UnityEngine.dll
Binary file not shown.
Binary file added Libs/com.rlabrecque.steamworks.net.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 62544f5

Please sign in to comment.