C#:
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("ComTimer", "MikeHawke", "1.0.0")]
[Description("Run a command at random time")]
class ComTimer : RustPlugin
{
private ConfigData configData;
class ConfigData
{
[JsonProperty(PropertyName = "Command List")]
public List<string> ComList = new List<string>();
[JsonProperty(PropertyName = "Upper Time In Seconds")]
public float upper = 500;
[JsonProperty(PropertyName = "Lower Time In Seconds")]
public float lower = 200;
}
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);
}
void Loaded()
{
Timer() ;
}
void Timer()
{
float ComTimer = UnityEngine.Random.Range(configData.lower, configData.upper);
timer.Once(ComTimer, () =>
{
CallCom();
});
}
void CallCom()
{
var command = configData.ComList[new System.Random().Next(configData.ComList.Count())];
covalence.Server.Command(command);
Timer();
}
}
}