-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntryPoint.cs
More file actions
97 lines (83 loc) · 4.57 KB
/
EntryPoint.cs
File metadata and controls
97 lines (83 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using DeleteThatEntity;
using Rage;
using System.Reflection;
[assembly: Rage.Attributes.Plugin("DeleteThatEntity", Description = "A simple plugin allowing to remove most entity from the world.", Author = "SSStuart", PrefersSingleInstance = true, SupportUrl = "https://ssstuart.net/discord")]
namespace DeleteThatEntityPlugin
{
public static class EntryPoint
{
public static string pluginName = "DeleteThatEntity";
public static string pluginVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public static Localization l10n = new Localization();
private static bool entityMarked = false;
private static Entity selectedEntity = null;
public static void Main()
{
Game.LogTrivial($"{pluginName} plugin v{pluginVersion} has been loaded.");
UpdateChecker.CheckForUpdates();
GameFiber.StartNew(delegate
{
while (true)
{
GameFiber.Yield();
// If the player is aiming and the Delete key is pressed, mark the entity for deletion
if (!entityMarked && ((Game.IsKeyDown(System.Windows.Forms.Keys.Delete) && Game.LocalPlayer.IsFreeAiming) || Game.IsControllerButtonDown(ControllerButtons.A)))
{
selectedEntity = Game.LocalPlayer.GetFreeAimingTarget();
if (selectedEntity != null && selectedEntity.IsValid())
{
selectedEntity.Opacity = 0.5f;
entityMarked = true;
Game.DisplayHelp(l10n.GetString("entitySelected", ("selectedEntity", selectedEntity.Model.Name)) +"~n~"+ l10n.GetString(!Game.IsControllerButtonDownRightNow(ControllerButtons.A) ? "selectionConfirmation" : "selectionConfirmationController"));
Game.LogTrivial($"Entity marked for deletion: {selectedEntity.Model.Name}");
}
else
Game.DisplaySubtitle(l10n.GetString("nothingFound"), 1000);
// Waiting for the key to be released
while ((Game.IsKeyDown(System.Windows.Forms.Keys.Delete) || Game.IsControllerButtonDownRightNow(ControllerButtons.A)))
GameFiber.Yield();
}
// If the entity is marked for deletion and the Delete key is pressed again, try deleting the entity
if (entityMarked && (Game.IsKeyDown(System.Windows.Forms.Keys.Delete) || Game.IsControllerButtonDown(ControllerButtons.A)))
{
if (selectedEntity.Exists())
{
selectedEntity.Delete();
Game.HideHelp();
// If the entity still exist, show a message saying that the deletion as failed
if (selectedEntity.Exists())
{
Game.DisplaySubtitle(l10n.GetString("unableToDelete"), 1000);
selectedEntity.Opacity = 1f;
Game.LogTrivial($"Unable to delete entity: {selectedEntity.Model.Name}");
}
else
{
Game.DisplaySubtitle(l10n.GetString("entityDeleted"), 1000);
Game.LogTrivial($"Entity deleted");
}
}
else
Game.LogTrivial($"Entity marked for deletion does not exist anymore");
entityMarked = false;
}
// If the entity is marked for deletion and the enter key is pressed, cancel the deletion
if (entityMarked && (Game.IsKeyDown(System.Windows.Forms.Keys.Enter) || Game.IsControllerButtonDown(ControllerButtons.B)))
{
entityMarked = false;
selectedEntity.Opacity = 1f;
Game.HideHelp();
Game.LogTrivial($"Entity deletion canceled for: {selectedEntity.Model.Name}");
}
}
});
}
private static void OnUnload(bool variable)
{
Game.LogTrivial("Unloading...");
if (entityMarked || selectedEntity.Exists())
selectedEntity.Opacity = 1f;
Game.LogTrivial("Unloaded");
}
}
}