C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
using System.Text;
namespace Oxide.Plugins {
[Info("Zone Kit", "Pho3niX90", "0.0.1")]
[Description("Teleports players to a spawnfile when entering a zone.")]
public class ZoneKit : RustPlugin {
[PluginReference] Plugin Spawns;
[PluginReference] Plugin ZoneManager;
private DynamicConfigFile data;
Dictionary<string, string> zoneKit;
#region Lifecycle
void Loaded() {
zoneKit = new Dictionary<string, string>();
LoadData();
}
void Unloaded() {
SaveData();
}
#endregion
#region Command Methods
[ChatCommand("zonekit")]
void cmdSpawns(BasePlayer player, string command, string[] args) {
if (!player.IsAdmin) return;
if (args.Length < 2) return;
if (zoneKit.ContainsKey(args[0])) {
SendReply(player, $"A kit already exists for ZoneID {args[0]}");
} else {
object success = Interface.CallHook("isKit", args[1]);
bool succ = false;
if (success != null) {
succ = (bool) success;
}
if (succ) {
zoneKit.Add(args[0], args[1]);
SendReply(player, "Kit Link saved");
SaveData();
} else {
SendReply(player, $"Kit doesn't exist.");
}
}
}
[ChatCommand("zonekit_remove")]
void cmdSpawns2(BasePlayer player, string command, string[] args) {
if (!player.IsAdmin) return;
if (args.Length < 1) return;
if (!zoneKit.ContainsKey(args[0])) {
SendReply(player, $"No such kit link with ZoneID {args[0]}");
} else {
if (zoneKit.Remove(args[0])) {
SendReply(player, "Kit Link Removed");
SaveData();
} else {
SendReply(player, "An error occured");
}
}
}
[ChatCommand("zonekit_list")]
void cmdSpawns3(BasePlayer player, string command, string[] args) {
if (!player.IsAdmin) return;
StringBuilder str = new StringBuilder();
if (zoneKit.Count == 0) {
SendReply(player, "There are no links");
} else {
foreach (KeyValuePair<string, string> item in zoneKit) {
str.Append($"{item.Key} kit for {item.Value}\n");
}
SendReply(player, str.ToString());
}
}
#endregion
#region Plugin Hooks
void OnEnterZone(string ZoneID, BasePlayer player) {
if (zoneKit.ContainsKey(ZoneID)) {
timer.Once(3f, () =>
Interface.CallHook("GiveKit", player, zoneKit[ZoneID]));
}
}
private void OnExitZone(string ZoneID, BasePlayer player) {
if (zoneKit.ContainsKey(ZoneID)) {
player.inventory.Strip();
player.SendNetworkUpdateImmediate();
}
}
#endregion
#region Helpers
#endregion
#region Data
void SaveData() {
try {
Interface.Oxide.DataFileSystem.WriteObject<Dictionary<string, string>>($"ZoneKit", zoneKit, true);
} catch (Exception e) {
}
}
void LoadData() {
try {
zoneKit = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, string>>($"ZoneKit");
} catch (Exception e) {
}
}
#endregion
}
}