C#:
using Newtonsoft.Json;
using UnityEngine;
using Oxide.Core.Plugins;
namespace Oxide.Plugins
{
[Info("CallHeli", "walkinrey", "1.0.2")]
public class CallHeli : RustPlugin
{
[PluginReference] private Plugin PersonalHeli;
#region Конфиг
private Configuration _config;
public class Configuration
{
[JsonProperty("Название предмета")]
public string name = "Вызов патрульного вертолета";
[JsonProperty("Скин предмета (иконка)")]
public ulong skin = 0;
[JsonProperty("Shortname предмета")]
public string shortname = "flare";
}
protected override void SaveConfig() => Config.WriteObject(_config);
protected override void LoadDefaultConfig() => _config = new Configuration();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<Configuration>();
}
catch
{
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
#endregion
#region Хуки
private void OnServerInitialized()
{
if(PersonalHeli == null)
{
PrintError("Не установлен плагин PersonalHeli.");
NextTick(() => Core.Interface.Oxide.UnloadPlugin(Title));
}
}
private void OnExplosiveThrown(BasePlayer player, BaseEntity entity, ThrownWeapon weapon)
{
var item = weapon.GetItem();
if(item != null)
{
if(item.skin == _config.skin && item.info.shortname == _config.shortname)
{
if(!string.IsNullOrEmpty(_config.name))
{
if(_config.name != item.name) return;
}
ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), "personalheli.call", player.userID);
}
}
}
#endregion
#region Методы
[ConsoleCommand("callheli.recive")]
private void cnslCommand(ConsoleSystem.Arg arg)
{
if(arg.Player() == null)
{
if(arg.HasArgs())
{
BasePlayer reciver;
ulong reciverID;
if(ulong.TryParse(arg.Args[0], out reciverID))
{
if(BasePlayer.TryFindByID(reciverID, out reciver))
{
Item thrown = ItemManager.CreateByName(_config.shortname, 1, _config.skin);
if(!string.IsNullOrEmpty(_config.name)) thrown.name = _config.name;
reciver.GiveItem(thrown);
Puts($"Игрок {reciver} успешно получил предмет для вызова вертолёта");
return;
}
}
PrintError("Игрок не найден, возможно он не в сети либо Steam ID указан неверно");
return;
}
PrintError("Не указан Steam ID");
}
else
{
var player = arg.Player();
if(player.IsAdmin)
{
if(arg.HasArgs())
{
BasePlayer reciver;
ulong reciverID;
if(ulong.TryParse(arg.Args[0], out reciverID))
{
if(BasePlayer.TryFindByID(reciverID, out reciver))
{
Item thrown = ItemManager.CreateByName(_config.shortname, 1, _config.skin);
if(!string.IsNullOrEmpty(_config.name)) thrown.name = _config.name;
reciver.GiveItem(thrown);
player.ConsoleMessage($"Игрок {reciver} успешно получил предмет для вызова вертолёта");
return;
}
}
player.ConsoleMessage("Игрок не найден, возможно он не в сети либо Steam ID указан неверно");
return;
}
player.ConsoleMessage("Не указан Steam ID");
}
}
}
#endregion
}
}