Код:
using System;
using System.Collections.Generic;
using System.Timers;
using Exiled.API.Features;
using Exiled.API.Interfaces;
using Exiled.Events.EventArgs;
namespace DClassInfoDisplay
{
public class DClassInfoDisplayPlugin : Plugin
{
public override string Name => "DClassInfoDisplay";
public override string Author => "NOT_MR";
public override Version Version => new Version(1, 0, 0);
public override string Prefix => "dclassinfodisplay";
code
Assistant
public EventHandlers EventHandlers;
public override void OnEnabled()
{
EventHandlers = new EventHandlers(this);
Exiled.Events.Handlers.Player.Spawning += EventHandlers.OnSpawning;
Exiled.Events.Handlers.Player.Dying += EventHandlers.OnDying;
Exiled.Events.Handlers.Player.Leaving += EventHandlers.OnLeaving;
Exiled.Events.Handlers.Server.RoundEnded += EventHandlers.OnRoundEnded;
base.OnEnabled();
}
public override void OnDisabled()
{
Exiled.Events.Handlers.Player.Spawning -= EventHandlers.OnSpawning;
Exiled.Events.Handlers.Player.Dying -= EventHandlers.OnDying;
Exiled.Events.Handlers.Player.Leaving -= EventHandlers.OnLeaving;
Exiled.Events.Handlers.Server.RoundEnded -= EventHandlers.OnRoundEnded;
EventHandlers.StopAllTimers();
EventHandlers = null;
base.OnDisabled();
}
}
public class EventHandlers
{
private readonly DClassInfoDisplayPlugin plugin;
private Dictionary<Player, System.Timers.Timer> playerTimers = new Dictionary<Player, System.Timers.Timer>();
public EventHandlers(DClassInfoDisplayPlugin plugin) => this.plugin = plugin;
public void OnSpawning(SpawningEventArgs ev)
{
if (ev.Player.Role == PlayerRoles.RoleTypeId.ClassD)
{
StartInfoTimer(ev.Player);
}
}
public void OnDying(DyingEventArgs ev)
{
StopInfoTimer(ev.Player);
}
public void OnLeaving(LeftEventArgs ev)
{
StopInfoTimer(ev.Player);
}
public void OnRoundEnded(RoundEndedEventArgs ev)
{
StopAllTimers();
}
private void StartInfoTimer(Player player)
{
if (playerTimers.ContainsKey(player))
{
StopInfoTimer(player);
}
System.Timers.Timer timer = new System.Timers.Timer(1000); // 1 second interval
timer.Elapsed += (sender, e) => ShowInfo(player);
timer.Start();
playerTimers[player] = timer;
}
private void StopInfoTimer(Player player)
{
if (playerTimers.TryGetValue(player, out System.Timers.Timer timer))
{
timer.Stop();
timer.Dispose();
playerTimers.Remove(player);
}
}
public void StopAllTimers()
{
foreach (var timer in playerTimers.Values)
{
timer.Stop();
timer.Dispose();
}
playerTimers.Clear();
}
private void ShowInfo(Player player)
{
if (player == null || !player.IsAlive || player.Role != PlayerRoles.RoleTypeId.ClassD)
{
StopInfoTimer(player);
return;
}
string name = player.Nickname;
string role = player.Role.ToString();
string enemies = "Охрана, МТФ, SCP";
string location = player.CurrentRoom != null ? player.CurrentRoom.Name : "Неизвестно";
string message = $"<size=20><align=left>\n" +
$"<color=#FFA500><b>Имя:</b></color> {name}\n" +
$"<color=#FFA500><b>Роль:</b></color> {role}\n" +
$"<color=#FFA500><b>Ваши враги:</b></color> {enemies}\n" +
$"<color=#FFA500><b>Местоположение:</b></color> {location}</align></size>";
player.ShowHint(message, 1);
}
}
public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;
}
}
а ошибки снизу
C:\Users\Дом\DClassInfoDisplay\Class1.cs(48,32): error CS0246: Не удалось найти тип или имя пространства имен "Spawning
EventArgs" (возможно, отсутствует директива using или ссылка на сборку). [C:\Users\Дом\DClassInfoDisplay\DClassInfoDisp
lay.csproj]
C:\Users\Дом\DClassInfoDisplay\Class1.cs(56,29): error CS0246: Не удалось найти тип или имя пространства имен "DyingEve
ntArgs" (возможно, отсутствует директива using или ссылка на сборку). [C:\Users\Дом\DClassInfoDisplay\DClassInfoDisplay
.csproj]
C:\Users\Дом\DClassInfoDisplay\Class1.cs(61,31): error CS0246: Не удалось найти тип или имя пространства имен "LeftEven
tArgs" (возможно, отсутствует директива using или ссылка на сборку). [C:\Users\Дом\DClassInfoDisplay\DClassInfoDisplay.
csproj]
C:\Users\Дом\DClassInfoDisplay\Class1.cs(66,34): error CS0246: Не удалось найти тип или имя пространства имен "RoundEnd
edEventArgs" (возможно, отсутствует директива using или ссылка на сборку). [C:\Users\Дом\DClassInfoDisplay\DClassInfoDi
splay.csproj]
The errors you're encountering indicate that the compiler cannot find the SpawningEventArgs, DyingEventArgs, LeftEventArgs, and RoundEndedEventArgs types. This is usually due to one of the following reasons:
Missing Assembly Reference: The assembly that contains these types is not referenced in your project.
Incorrect Using Directives: The namespace containing these types is not included with a using directive.
Version Mismatch: You're using an outdated version of the Exiled API where these types have been renamed or moved.
Given that you're using the Exiled API and the event argument types cannot be found, it's highly likely that you're experiencing a version mismatch. Specifically, in Exiled 6.0 and later, several event argument types have been renamed or replaced. Here's how you can resolve the issue:
1. Update Event Argument Types
Replace the event argument types in your event handlers with the updated types corresponding to your version of the Exiled API. Here's the mapping for the types you've used:
SpawningEventArgs has been replaced by ChangingRoleEventArgs.
DyingEventArgs has been replaced by DiedEventArgs.
LeftEventArgs remains the same, but ensure you're using the correct namespace.
RoundEndedEventArgs remains the same, but ensure you're using the correct namespace.
Here's the updated code for your event handlers:
csharp
public void OnSpawning(ChangingRoleEventArgs ev)
{
if (ev.NewRole == PlayerRoles.RoleTypeId.ClassD)
{
StartInfoTimer(ev.Player);
}
}
public void OnDying(DiedEventArgs ev)
{
StopInfoTimer(ev.Player);
}
Make sure to update the method signatures and any references to the replaced types within these methods.
2. Update Using Directives
Ensure you have the correct using directives at the top of your file:
csharp
using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Server;
If your IDE doesn't recognize these namespaces, you may need to adjust them based on the actual structure in your version of the Exiled API.
3. Verify Assembly References
Ensure that your project references the correct version of the Exiled assemblies. Here's how you can check:
In your project file (.csproj), ensure you have the correct package references:
If you're using a different version, adjust the version numbers accordingly.
4. Rebuild the Project
After making the above changes, rebuild your project to see if the errors are resolved.
Example of Updated Event Handlers
Here's how your EventHandlers class should look after the updates:
csharp
public class EventHandlers
{
private readonly DClassInfoDisplayPlugin plugin;
private Dictionary<Player, System.Timers.Timer> playerTimers = new Dictionary<Player, System.Timers.Timer>();
public EventHandlers(DClassInfoDisplayPlugin plugin) => this.plugin = plugin;
public void OnSpawning(ChangingRoleEventArgs ev)
{
if (ev.NewRole == PlayerRoles.RoleTypeId.ClassD)
{
StartInfoTimer(ev.Player);
}
}
public void OnDying(DiedEventArgs ev)
{
StopInfoTimer(ev.Player);
}
public void OnLeaving(LeftEventArgs ev)
{
StopInfoTimer(ev.Player);
}
public void OnRoundEnded(RoundEndedEventArgs ev)
{
StopAllTimers();
}
// ... rest of your code ...
}
Additional Notes
Check the API Documentation: Refer to the Exiled API documentation corresponding to your version to ensure you're using the correct types and namespaces.
IDE IntelliSense: Use an IDE like Visual Studio or Visual Studio Code with IntelliSense, which can help auto-complete types and namespaces, reducing the likelihood of these errors.
Debugging: If you continue to face issues, try creating a new simple plugin to test if the basic event handlers work, and then incrementally add your code.
Conclusion
The errors occur because the event argument types you're using have been renamed or moved in the version of the Exiled API you're targeting. By updating your code to use the correct types and ensuring all necessary namespaces and references are included, you should be able to resolve the compilation errors.