C#:
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
namespace Oxide.Plugins
{
[Info("JuanTime", "MikeHawke", "1.0.3")]
[Description("Give A Kit Juan Time")]
class JuanTime : RustPlugin
{
[PluginReference]
private Plugin Kits;
private ConfigData configData;
class ConfigData
{
[JsonProperty(PropertyName = "KitName")]
public List<string> KitName = new List<string>();
}
void Init()
{
if (!LoadConfigVariables())
{
Puts("Config file issue detected. Please delete file, or check syntax and fix.");
return;
}
}
private bool LoadConfigVariables()
{
try
{
configData = Config.ReadObject<ConfigData>();
}
catch
{
return false;
}
SaveConfig(configData);
return true;
}
protected override void LoadDefaultConfig()
{
Puts("Creating new config file.");
configData = new ConfigData(); SaveConfig(configData);
}
void SaveConfig(ConfigData config)
{
Config.WriteObject(config, true);
}
StoredData storedData;
class StoredData
{
public List<ulong> Awarded = new List<ulong>();
}
void Loaded()
{
if(Kits == null)
{
ReCheck();
}
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("JuanTime");
Interface.Oxide.DataFileSystem.WriteObject("JuanTime", storedData);
}
void ReCheck()
{
timer.Once(5f, () =>
{
if (Kits == null)
{
PrintWarning("Juan No Work, No Kits, No Lemon Pledge");
covalence.Server.Command("o.unload JuanTime");
}
});
}
void SaveData()
{
Interface.Oxide.DataFileSystem.WriteObject("JuanTime", storedData);
}
private void OnNewSave(string filename)
{
storedData.Awarded.Clear();
SaveData();
Puts("New Map Detected Data Cleared.");
}
void OnPlayerSpawn(BasePlayer player)
{
if (storedData.Awarded.Contains(player.userID)) return;
WakeNKit(player);
}
void OnPlayerRespawned(BasePlayer player)
{
if (storedData.Awarded.Contains(player.userID)) return;
WakeNKit(player);
}
private void WakeNKit(BasePlayer player)
{
player.inventory.Strip();
Kits?.Call($"GiveKit", player, configData.KitName[new System.Random().Next(configData.KitName.Count())]);
storedData.Awarded.Add(player.userID);
SaveData();
}
[ConsoleCommand("JuanWipe")]
private void WipeList(ConsoleSystem.Arg arg)
{
if (arg.Player() == null || arg.Player()?.IsAdmin == true)
{
storedData.Awarded.Clear();
SaveData();
Puts("Data Cleared.");
}
}
}
}