C#:
using Newtonsoft.Json;
using Oxide.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Oxide.Plugins {
[Info("GalaxyBonus", "BadMandarin", "1.0.0")]
[Description("GalaxyBonus")]
class GalaxyBonus : RustPlugin {
#region Classes
private class PluginData {
public int LastUpdateDay = 0;
public List<ulong> usersTake = new List<ulong>();
}
private class PluginConfig {
[JsonProperty("1. ID GameStores")]
public string GameStoresID = "";
[JsonProperty("2. Secret GameStores")]
public string GameStoresSecret = "";
[JsonProperty("3. Время обнуления бонуса")]
public string UpdateTime = DateTime.Now.ToShortTimeString();
[JsonProperty("4. Кол-во выдаваемых денег")]
public int MoneyAmount = 5;
[JsonProperty("4. Нужный текст в нике игрока для получения")]
public string TextNick = "#GalaxyRust";
[JsonProperty("5. Сообщение игрокам которые не забрали бонус. (поставьте 0 чтобы отключить)")]
public float timerTime = 600f;
}
#endregion
#region Var
private PluginConfig config;
private PluginData data;
private string DataPath = "GalaxyBonus/Data";
private Timer pluginTimer;
#endregion
#region Oxide
private void Init() {
config = Config.ReadObject<PluginConfig>();
}
void OnServerInitialized() {
data = new PluginData();
if (Interface.Oxide.DataFileSystem.ExistsDatafile(DataPath)) data = Interface.Oxide.DataFileSystem.ReadObject<PluginData>(DataPath);
Interface.Oxide.DataFileSystem.WriteObject(DataPath, data);
if(config.timerTime > 0) pluginTimer = timer.Every(config.timerTime, () => {
BasePlayer.activePlayerList.ToList().ForEach(player => {
if (player.displayName.Contains(config.TextNick, System.Globalization.CompareOptions.IgnoreCase) && !data.usersTake.Contains(player.userID)) SendReply(player, lang.GetMessage("ChatNotice", this));
}
);
}
);
PrintWarning("Plugin loaded! Author: BadMandarin!");
}
void Unload() {
if (pluginTimer != null && !pluginTimer.Destroyed) pluginTimer.Destroy();
Interface.Oxide.DataFileSystem.WriteObject(DataPath, data);
PrintWarning("Plugin unloaded! Author: BadMandarin!");
}
/*
void OnTick()
{
if(data.LastUpdateDay != DateTime.Now.Day)
{
DateTime time = DateTime.Parse(config.UpdateTime);
if (time.Hour <= DateTime.Now.Hour && time.Minute <= DateTime.Now.Minute)
{
data.usersTake.Clear();
data.LastUpdateDay = DateTime.Now.Day;
}
}
}
*/
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["AlreadyTake"]
= "[<color=#A901DB>GalaxyRust</color>] Вы уже забрали свой бонус!", ["OnTake"] = "[<color=#A901DB>GalaxyRust</color>] Вы успешно получили бонус в размере {0}р!", ["NoAccountOrError"] = "[<color=#A901DB>GalaxyRust</color>] Ошибка при получении данных! Проверьте есть ли у вас аккаунт на нашем сайте!", ["ChatNotice"] = "[<color=#A901DB>GalaxyRust</color>] Вы не забрали свой бонус! Напишите /bonus чтобы забрать!", ["NoTextInNick"] = "[<color=#A901DB>GalaxyRust</color>] Чтобы забрать бонус нужно иметь #GalaxyRust в нике!",
}
, this);
}
#endregion
#region Cmd
[ChatCommand("bonus")]
void Chat_Bonus(BasePlayer player, string command, string[] args) {
if (!player.displayName.Contains(config.TextNick, System.Globalization.CompareOptions.IgnoreCase)) {
SendReply(player, lang.GetMessage("NoTextInNick", this));
return;
}
if (data.usersTake.Contains(player.userID)) {
SendReply(player, lang.GetMessage("AlreadyTake", this));
return;
}
GiveBonus(player);
}
#endregion
#region Utils
private void GiveBonus(BasePlayer player) {
string url = $"https://gamestores.ru/api?shop_id={config.GameStoresID}&secret={config.GameStoresSecret}&action=moneys&type=plus&steam_id={player.userID}&amount={config.MoneyAmount}";
webrequest.Enqueue(url, null, (i, s) => {
if (i != 200) {
LogToFile("logError", $"I({DateTime.Now.ToShortTimeString()}): {url}\nCODE {i}: {s}", this);
SendReply(player, lang.GetMessage("NoAccountOrError", this));
}
else {
data.usersTake.Add(player.userID);
SendReply(player, string.Format(lang.GetMessage("OnTake", this), config.MoneyAmount));
LogToFile("logWEB", $"({DateTime.Now.ToShortTimeString()}): {s}", this);
}
}
, this);
return;
}
protected override void LoadDefaultConfig() {
Config.WriteObject(GetDefaultConfig(), true);
}
private PluginConfig GetDefaultConfig() {
return new PluginConfig();
}
#endregion
}
}