C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
/*
* The MIT License (MIT)
* Copyright (c) 2015 feramor@computer.org
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.*/
//Microsoft
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Linq;
//Oxide
using Oxide.Core;
using Oxide.Core.Logging;
using Oxide.Core.Plugins;
using Oxide.Game.Rust;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Libraries;
//UnityEngine
using UnityEngine;
//Others
using Newtonsoft.Json;
// Do NOT edit this file, instead edit Polling.json in server/<identity>/oxide/config
namespace Oxide.Plugins {
[Info("Polling Plugin", "Feramor", "1.2.1", ResourceId = 793)]
[Description("Allows players with permission to run polls.")]
public class Polling : RustPlugin {
#region Custom Classes
static class Constants {
public const string ConfigVersion = "1.2.2";
}
public class Poll {
public string Command {
set;
get;
}
public string Question {
set;
get;
}
public string Permission {
set;
get;
}
public bool Custom {
set;
get;
}
public Dictionary<int, PollChoice> PollChoices {
set;
get;
}
}
public class PollChoice {
public string ChoiceText {
set;
get;
}
public string ChoiceConsoleCommand {
set;
get;
}
}
public class PollData {
public string Command {
set;
get;
}
public bool isActive {
set;
get;
}
public int ID {
set;
get;
}
public uint StartTime {
set;
get;
}
public uint EndTime {
set;
get;
}
public string Question {
set;
get;
}
public string Target {
set;
get;
}
public List<PollChoiceData> PollChoices {
set;
get;
}
public List<string> VotedUserList {
set;
get;
}
public string Owner {
set;
get;
}
}
public class PollChoiceData {
public string ChoiceText {
set;
get;
}
public int VoteCount {
set;
get;
}
}
public class PollSchedule {
public string PollType {
get;
set;
}
public string Cron {
get;
set;
}
public uint Duration {
get;
set;
}
}
#endregion
#region Veriables
[PluginReference]
private Plugin CronLibrary;
private static Core.Logging.Logger RootLogger = Interface.GetMod().RootLogger;
private Dictionary<string, object> MainSettings;
private Dictionary<string, object> PluginSetting;
private Dictionary<string, object> CustomPolls;
private List<PollSchedule> PollSchedules;
private Dictionary<string, Poll> PollTypes;
private PollData Current;
private SortedList<int, PollData> History;
private Dictionary<ulong, string> Active_GUI_CurrentPoll;
private Dictionary<ulong, string> Active_GUI_Help;
private Dictionary<ulong, string> Active_GUI_History;
private Dictionary<ulong, Timer> CurrentPollUpdater;
private Timer CurrentPollTimer = null;
private Timer CurrentPollReminder = null;
#endregion
#region Localization
void LoadDefaultMessages() {
var messages = new Dictionary<string, string> {
{
"ButtonCurrent", "Current Poll"
}
, {
"ButtonHistory", "Poll History"
}
, {
"ButtonHelp", "Help"
}
, {
"ButtonClose", "Close"
}
, {
"ButtonResults", "Results"
}
, {
"ErrorNoActivePoll", "There is <color=#ce422b>no</color> active poll right now!\n\nCheck back later or keep an eye on chat for an announcement."
}
, {
"CanCreatePoll", "<color=#ce422b>Admin</color> Menu\n You have permission to create given types of polls.\n\n"
}
, {
"CantCreatePoll", "You <color=#ce422b>don't</color> have permission to create polls."
}
, {
"AutoRefresh", "This menu refresh automatically every <color=#ce422b>10</color> seconds."
}
, {
"HelpUserKickPoll", "<color=#ce422b> * </color>You can use following command to create a poll to kick a player."
}
, {
"HelpUserKickPollUsage", "<color=#ce422b> /{0}</color> 'Kick' 'Timer' 'Name|SteamID'"
}
, {
"HelpUserBanPoll", "<color=#ce422b> * </color>You can use following command to create a poll to ban a player."
}
, {
"HelpUserBanPollUsage", "<color=#ce422b> /{0}</color> 'Ban' 'Timer' 'Name|SteamID'"
}
, {
"HelpAirdropPoll", "<color=#ce422b> * </color>You can use following command to create a poll to call an airdrop."
}
, {
"HelpAirdropPollUsage", "<color=#ce422b> /{0}</color> 'Airdrop' 'Timer'"
}
, {
"HelpHeliPoll", "<color=#ce422b> * </color>You can use following command to create a poll to call an patrol helicopter."
}
, {
"HelpHeliPollUsage", "<color=#ce422b> /{0}</color> 'Heli' 'Timer'"
}
, {
"HelpTimePoll", "<color=#ce422b> * </color>You can use following command to create a poll to call to change time."
}
, {
"HelpTimePollUsage", "<color=#ce422b> /{0}</color> 'Time' 'Timer' 'Day|Night'"
}
, {
"HelpCustomPoll", "<color=#ce422b> * </color>You can use following command to create a custom poll to ask anything."
}
, {
"HelpCustomPollUsage", "<color=#ce422b> /{0}</color> 'Custom' 'Timer' 'Question' 'Choice1' 'Choice2' 'Choice3'...'ChoiceN'"
}
, {
"CustomPollCount", "Currently there is/are {0} custom polls"
}
, {
"QuestionKick", "Do you want to kick {0} ?"
}
, {
"QuestionBan", "Do you want to ban {0} ?"
}
, {
"QuestionHeli", "Do you want to call a Patrol Helicopter ?"
}
, {
"QuestionCustom", "Don't edit this"
}
, {
"QuestionAirdrop", "Do you want to call an Airdrop ?"
}
, {
"QuestionTime", "Do you want to change time to {0} ?"
}
, {
"Yes", "Yes"
}
, {
"No", "No"
}
, {
"ErrorPermission", "You <color=#ce422b>don't</color> have permission to create {0} polls."
}
, {
"ErrorAlreadyPoll", "There is already a poll running."
}
, {
"ErrorSyntax", "There has been an syntax error in command.\nCorrect form is\n"
}
, {
"ErrorTime", "You have entered an invalid time.Time limits Min:30 Max:3600"
}
, {
"PollStarted", "Poll Started\n <color=red>*</color> {0}"
}
, {
"PollNotVoted", "You haven't voted.Please vote now!\n <color=red>*</color> {0}"
}
, {
"VoteFinish", "Vote Finished\n <color=red>*</color> {0}"
}
, {
"VoteResult", "{0} people gave vote for {1}"
}
, {
"HowToVote", "You can use /{0} to vote."
}
, {
"AlreadyVoted", "You have already <color=#ce422b>voted</color> for current poll!\n\nCheck back later or keep an eye on chat for an announcement for new poll."
}
, {
"CurrenQuestion", "<color=#ce422b>Current</color> Poll Question"
}
, {
"CurrenStarted", "<color=#ce422b>Current</color> Poll Started"
}
, {
"CurrenOwner", "<color=#ce422b>Current</color> Poll By"
}
, {
"CurrenTimeleft", "<color=#ce422b>Current</color> Poll Will End in {0} Second(s)"
}
, {
"NoPoll", "There is <color=#ce422b>no</color> active poll right now!"
}
, {
"Voted", "You have voted <color=#ce422b>{0}</color> for {1}."
}
, {
"HistoryCount", "Currently there is/are <color=#ce422b>{0}</color> poll(s) in history."
}
, {
"Page", "Page {0}"
}
, {
"ButtonNextPage", "Next Page"
}
, {
"ButtonPreviousPage", "Previous Page"
}
, {
"Day", "Day"
}
, {
"Night", "Night"
}
, {
"NoUser", "There is no user found with search with Name/SteamID ({0})"
}
, {
"KickReason", "You have been kicked by poll results."
}
, {
"BanReason", "You have been banned by poll results."
}
, {
"ButtonReRunPoll", "Re-run Poll"
}
, {
"ErrorEndVote", "You <color=#ce422b>don't</color> have permission to end polls."
}
, {
"ButtonEndVote", "End Poll"
}
, {
"ScheduledPollCount", "Currently there is/are {0} scheduled polls"
}
,
}
;
SortedDictionary<string, string> sortedMessages = new SortedDictionary<string, string>(messages);
messages.Clear();
foreach (KeyValuePair<string, string> Current in sortedMessages) messages.Add(Current.Key, Current.Value);
lang.RegisterMessages(messages, this);
SaveConfig();
}
#endregion
#region Configration
protected override void LoadDefaultConfig() {
var NewSettings = new Dictionary<string, object> {
{
"Main Settings", new Dictionary<string, object> {
{
"ChatCommand", "poll"
}
, {
"ChatTag", "Polling"
}
, {
"ChatProfile", "76561198286931766"
}
, {
"CountNonVoters", true
}
, {
"ConfigVersion", Constants.ConfigVersion
}
, {
"ReminderTimer", 20
}
}
}
, {
"Plugin Settings", new Dictionary<string, object> {
{
"CargoPlane", new Dictionary<string, object> {
{
"Enabled", false
}
, {
"PluginConsoleCommand", ""
}
}
}
, {
"PatrolHelicopter", new Dictionary<string, object> {
{
"Enabled", false
}
, {
"PluginConsoleCommand", ""
}
}
}
, {
"AutoSkipNights", new Dictionary<string, object> {
{
"Enabled", true
}
, {
"TimeOfSkip", "18:00"
}
}
}
}
}
, {
"Polls", new Dictionary<string, object> {
}
}
, {
"Poll Schedules", new List<PollSchedule> {
}
}
}
;
if ((Config["Settings"] == null) || ((Config["Settings"] as Dictionary<string, object>)["Main Settings"] as Dictionary<string, object>)["ConfigVersion"] as string != Constants.ConfigVersion) {
RootLogger.Write(Core.Logging.LogType.Warning, "[Polling] Configration file (Polling.json) not found or config version mismatch with new plugin version.Replacing with new one.Please modify your config file.");
Config.Clear();
Config["Settings"] = NewSettings;
SaveConfig();
}
}
#endregion
#region Hooks
void Loaded() {
LoadDefaultConfig();
LoadDefaultMessages();
MainSettings = (Config["Settings"] as Dictionary<string, object>)["Main Settings"] as Dictionary<string, object>;
PluginSetting = (Config["Settings"] as Dictionary<string, object>)["Plugin Settings"] as Dictionary<string, object>;
CustomPolls = (Config["Settings"] as Dictionary<string, object>)["Polls"] as Dictionary<string, object>;
PollSchedules = JsonConvert.DeserializeObject<List<PollSchedule>>(JsonConvert.SerializeObject((Config["Settings"] as Dictionary<string, object>)["Poll Schedules"]));
PollTypes = new Dictionary<string, Poll>();
permission.RegisterPermission("Polling.Can.CleanHistory", this);
permission.RegisterPermission("Polling.Can.EndPolls", this);
RegisterPoll("Airdrop", GetMessage("QuestionAirdrop"), "Polling.Create.Airdrop", new List<Dictionary<string, string>> {
new Dictionary<string, string> {
{
"ChoiceText", GetMessage("Yes")
}
, {
"ChoiceConsoleCommand", ""
}
}
, new Dictionary<string, string> {
{
"ChoiceText", GetMessage("No")
}
, {
"ChoiceConsoleCommand", ""
}
}
}
, false, 0);
RegisterPoll("Ban", GetMessage("QuestionBan"), "Polling.Create.Ban", new List<Dictionary<string, string>> {
new Dictionary<string, string> {
{
"ChoiceText", GetMessage("Yes")
}
, {
"ChoiceConsoleCommand", ""
}
}
, new Dictionary<string, string> {
{
"ChoiceText", GetMessage("No")
}
, {
"ChoiceConsoleCommand", ""
}
}
}
, false, 1);
RegisterPoll("Custom", GetMessage("QuestionCustom"), "Polling.Create.Custom", new List<Dictionary<string, string>> {
}
, false, 2);
RegisterPoll("Heli", GetMessage("QuestionHeli"), "Polling.Create.Heli", new List<Dictionary<string, string>> {
new Dictionary<string, string> {
{
"ChoiceText", GetMessage("Yes")
}
, {
"ChoiceConsoleCommand", ""
}
}
, new Dictionary<string, string> {
{
"ChoiceText", GetMessage("No")
}
, {
"ChoiceConsoleCommand", ""
}
}
}
, false, 3);
RegisterPoll("Kick", GetMessage("QuestionKick"), "Polling.Create.Kick", new List<Dictionary<string, string>> {
new Dictionary<string, string> {
{
"ChoiceText", GetMessage("Yes")
}
, {
"ChoiceConsoleCommand", ""
}
}
, new Dictionary<string, string> {
{
"ChoiceText", GetMessage("No")
}
, {
"ChoiceConsoleCommand", ""
}
}
}
, false, 4);
RegisterPoll("Time", GetMessage("QuestionTime"), "Polling.Create.Time", new List<Dictionary<string, string>> {
new Dictionary<string, string> {
{
"ChoiceText", GetMessage("Yes")
}
, {
"ChoiceConsoleCommand", ""
}
}
, new Dictionary<string, string> {
{
"ChoiceText", GetMessage("No")
}
, {
"ChoiceConsoleCommand", ""
}
}
}
, false, 5);
//Register Custom Plugins
RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Registering {0} custom poll(s).", CustomPolls.Count);
foreach (KeyValuePair<string, object> CurrentCustomPoll in CustomPolls) {
Dictionary<string, object> currentCustomPoll = CurrentCustomPoll.Value as Dictionary<string, object>;
Dictionary<string, object> CustomPollChoices = currentCustomPoll["PollChoices"] as Dictionary<string, object>;
List<Dictionary<string, string>> currentCustomPollChoices = new List<Dictionary<string, string>>();
foreach (KeyValuePair<string, object> CurrentCustomPollChoices in CustomPollChoices) {
Dictionary<string, string> newCustomPollChoice = new Dictionary<string, string>();
newCustomPollChoice.Add("ChoiceText", (CurrentCustomPollChoices.Value as Dictionary<string, object>)["ChoiceText"] as string);
newCustomPollChoice.Add("ChoiceConsoleCommand", (CurrentCustomPollChoices.Value as Dictionary<string, object>)["ChoiceConsoleCommand"] as string);
currentCustomPollChoices.Add(newCustomPollChoice);
}
RegisterPoll(CurrentCustomPoll.Key, currentCustomPoll["AskQuestion"] as string, string.Format("Polling.Create.{0}", CurrentCustomPoll.Key), currentCustomPollChoices);
}
//Register Custom Plugins
cmd.AddChatCommand(MainSettings["ChatCommand"] as string, this, "Chat_Polling_GUI_CurrentPoll");
try {
History = Interface.Oxide.DataFileSystem.ReadObject<SortedList<int, PollData>>("Polling");
}
catch {
History = new SortedList<int, PollData>();
Interface.Oxide.DataFileSystem.WriteObject<SortedList<int, PollData>>("Polling", History);
RootLogger.Write(Core.Logging.LogType.Error, "[Polling] There has been an error occured while loading history.Reseting history file.", History.Count);
}
RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Currently {0} poll(s) loaded to History.", History.Count);
Active_GUI_CurrentPoll = new Dictionary<ulong, string>();
Active_GUI_Help = new Dictionary<ulong, string>();
Active_GUI_History = new Dictionary<ulong, string>();
CurrentPollUpdater = new Dictionary<ulong, Timer>();
#region Register Poll Schedules
RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Registering {0} scheduled polls.", PollSchedules.Count);
if (PollSchedules.Count > 0) {
if ((CronLibrary != null) && (CronLibrary.IsLoaded)) {
foreach (PollSchedule CurrentPollSchedule in PollSchedules) {
CronLibrary?.CallHook("RegisterCron", this, true, CurrentPollSchedule.Cron, new Action(() => {
if (Current == null) {
Poll CurrentPollType;
if (PollTypes.TryGetValue(CurrentPollSchedule.PollType, out CurrentPollType)) {
PollData NewPoll = new PollData();
NewPoll.ID = History.Count + 1;
NewPoll.Command = CurrentPollType.Command;
NewPoll.Question = CurrentPollType.Question;
NewPoll.Target = "";
NewPoll.VotedUserList = new List<string>();
NewPoll.PollChoices = new List<PollChoiceData>();
foreach (PollChoice CurrentChoice in CurrentPollType.PollChoices.Values) {
NewPoll.PollChoices.Add(new PollChoiceData {
ChoiceText = CurrentChoice.ChoiceText, VoteCount = 0
}
);
}
NewPoll.isActive = true;
NewPoll.Owner = "Scheduled Poll";
NewPoll.StartTime = GetLibrary<Core.Libraries.Time>().GetUnixTimestamp();
NewPoll.EndTime = NewPoll.StartTime + CurrentPollSchedule.Duration;
this.Current = NewPoll;
History.Add(NewPoll.ID, NewPoll);
}
else RootLogger.Write(Core.Logging.LogType.Error, "[Polling] There is no poll type with [{0}].", CurrentPollSchedule.PollType);
}
else RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Since there is already running poll, skipped a schedule poll [{0}] for {1}.", CurrentPollSchedule.PollType, CurrentPollSchedule.Cron);
}
));
RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Added new schedule poll [{0}] for {1}.", CurrentPollSchedule.PollType, CurrentPollSchedule.Cron);
}
}
else RootLogger.Write(Core.Logging.LogType.Error, "[Polling] You need Cron Library plugin to schedule polls.");
}
#endregion
}
void Unload() {
foreach (var player in BasePlayer.activePlayerList) {
Polling_GUI_Close(player);
}
if (CurrentPollTimer != null) {
if (!CurrentPollTimer.Destroyed) CurrentPollTimer.Destroy();
CurrentPollTimer = null;
}
if (CurrentPollReminder != null) {
if (!CurrentPollReminder.Destroyed) CurrentPollReminder.Destroy();
CurrentPollReminder = null;
}
Interface.Oxide.DataFileSystem.WriteObject<SortedList<int, PollData>>("Polling", History);
}
void OnServerInitialized() {
if (History.TryGetValue(History.Count, out Current)) {
if (Current.isActive) {
RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Restarting last poll timer due to server restart.", History.Count);
uint timer = Current.EndTime - Current.StartTime;
Current.StartTime = GetLibrary<Core.Libraries.Time>().GetUnixTimestamp();
Current.EndTime = Current.StartTime + timer;
}
}
}
void OnTick() {
if (this.Current != null) {
if (CurrentPollTimer == null) {
if (Current.isActive) {
if ((int)MainSettings["ReminderTimer"] < 15) MainSettings["ReminderTimer"] = 15;
if ((int)MainSettings["ReminderTimer"] > 60) MainSettings["ReminderTimer"] = 60;
CurrentPollTimer = timer.Once(Current.EndTime - Current.StartTime, () => EndVote());
CurrentPollReminder = timer.Repeat(Convert.ToInt32(MainSettings["ReminderTimer"]), 0, () => RemindPoll());
RootLogger.Write(Core.Logging.LogType.Info, "[Polling] Poll started {0} for {1} seconds.", Current.Question, Current.EndTime - Current.StartTime);
foreach (BasePlayer ActiveUser in BasePlayer.activePlayerList) {
SendReply(ActiveUser, string.Format(GetMessage("PollStarted"), Current.Question));
SendReply(ActiveUser, string.Format(GetMessage("HowToVote"), MainSettings["ChatCommand"]));
}
}
else {
Current = null;
if (CurrentPollTimer != null) {
if (!CurrentPollTimer.Destroyed) CurrentPollTimer.Destroy();
CurrentPollTimer = null;
}
if (CurrentPollReminder != null) {
if (!CurrentPollReminder.Destroyed) CurrentPollReminder.Destroy();
CurrentPollReminder = null;
}
}
}
else {
if (!Current.isActive) {
Current = null;
if (CurrentPollTimer != null) {
if (!CurrentPollTimer.Destroyed) CurrentPollTimer.Destroy();
CurrentPollTimer = null;
}
if (CurrentPollReminder != null) {
if (!CurrentPollReminder.Destroyed) CurrentPollReminder.Destroy();
CurrentPollReminder = null;
}
}
}
}
else if ((bool)(PluginSetting["AutoSkipNights"] as Dictionary<string, object>)["Enabled"]) {
TOD_Sky Sky = TOD_Sky.Instance;
if (Sky.Cycle.DateTime.ToString("HH:mm") == ((PluginSetting["AutoSkipNights"] as Dictionary<string, object>)["TimeOfSkip"] as string)) {
Poll Current;
if (PollTypes.TryGetValue("Time", out Current)) {
PollData NewPoll = new PollData();
NewPoll.ID = History.Count + 1;
NewPoll.Command = Current.Command;
NewPoll.Question = string.Format(Current.Question, GetMessage("Day"));
NewPoll.Target = "Day";
NewPoll.VotedUserList = new List<string>();
NewPoll.PollChoices = new List<PollChoiceData>();
foreach (PollChoice CurrentChoice in Current.PollChoices.Values) {
NewPoll.PollChoices.Add(new PollChoiceData {
ChoiceText = CurrentChoice.ChoiceText, VoteCount = 0
}
);
}
NewPoll.isActive = true;
NewPoll.Owner = "Auto Skip Nights";
NewPoll.StartTime = GetLibrary<Core.Libraries.Time>().GetUnixTimestamp();
NewPoll.EndTime = NewPoll.StartTime + 60;
this.Current = NewPoll;
History.Add(NewPoll.ID, NewPoll);
}
}
}
}
[HookMethod("SendHelpText")]
private void SendHelpText(BasePlayer player) {
var sb = new StringBuilder().Append("<size=18>Polling</size> by <color=#ce422b>Feramor</color>\n").Append(" ").Append("<color=\"#ffd479\">/poll</color> - Displays polling GUI.");
player.ChatMessage(sb.ToString());
}
void OnServerSave() {
Interface.Oxide.DataFileSystem.WriteObject<SortedList<int, PollData>>("Polling", History);
}
void OnServerShutdown() {
Interface.Oxide.DataFileSystem.WriteObject<SortedList<int, PollData>>("Polling", History);
}
#endregion
#region Polling.GUI.Help
[ConsoleCommand("Polling.GUI.Help")]
void Polling_GUI_Help(ConsoleSystem.Arg arg) {
if (arg == null || arg.connection == null || arg.connection.player == null) return;
var player = arg.connection.player as BasePlayer;
if (player == null) return;
Polling_GUI_Close(arg);
var elements = new CuiElementContainer();
Active_GUI_Help[player.userID] = CuiHelper.GetGuid();
var MainElement = elements.Add(new CuiPanel {
CursorEnabled = true, Image = {
Color = "0 0 0 0.85"
}
, RectTransform = {
AnchorMin = "0.0 0.1", AnchorMax = "0.32 0.8"
}
}
, "HUD/Overlay", Active_GUI_Help[player.userID]);
elements.Add(new CuiPanel {
Image = {
Color = "0 0 0 0.90"
}
, RectTransform = {
AnchorMin = "0.01 0.93", AnchorMax = "0.99 0.99"
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 0.93", AnchorMax = "0.99 0.99"
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 12, Text = "<color=#ce422b>Polling</color> Menu"
}
}
, MainElement);
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.CurrentPoll", Color = "192 192 192 0.90"
}
, RectTransform = {
AnchorMin = "0.20 0.94", AnchorMax = "0.40 0.98"
}
, Text = {
Text = GetMessage("ButtonCurrent"), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.History", Color = "192 192 192 0.90"
}
, RectTransform = {
AnchorMin = "0.41 0.94", AnchorMax = "0.61 0.98"
}
, Text = {
Text = GetMessage("ButtonHistory"), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.Help", Color = "0 255 255 0.90"
}
, RectTransform = {
AnchorMin = "0.62 0.94", AnchorMax = "0.82 0.98"
}
, Text = {
Text = GetMessage("ButtonHelp"), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.Close", Close = MainElement, Color = "255 0 0 0.90"
}
, RectTransform = {
AnchorMin = "0.83 0.94", AnchorMax = "0.98 0.98"
}
, Text = {
Text = GetMessage("ButtonClose"), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
elements.Add(new CuiPanel {
Image = {
Color = "0 0 0 0.90"
}
, RectTransform = {
AnchorMin = "0.01 0.01", AnchorMax = "0.99 0.07"
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 0.01", AnchorMax = "0.98 0.07"
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 12, Text = "By <color=#ce422b>Feramor</color>"
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 0.01", AnchorMax = "0.98 0.07"
}
, Text = {
Align = TextAnchor.MiddleRight, FontSize = 12, Text = string.Format("Version <color=#ce422b>{0}</color>", Version.ToString())
}
}
, MainElement);
#region PreDefined Polls
if ((arg.Args == null || arg.Args.Length == 0)) {
if (PollSchedules.Count == 0) {
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.Help Scheduled", Color = "255 0 0 0.90"
}
, RectTransform = {
AnchorMin = "0.02 0.08", AnchorMax = "0.99 0.12"
}
, Text = {
Text = string.Format(GetMessage("ScheduledPollCount"), PollSchedules.Count), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
}
else {
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.Help Scheduled", Color = "0 255 255 0.90"
}
, RectTransform = {
AnchorMin = "0.02 0.08", AnchorMax = "0.99 0.12"
}
, Text = {
Text = string.Format(GetMessage("ScheduledPollCount"), PollSchedules.Count), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
}
if (HasPermission(player)) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 0.81", AnchorMax = "0.99 0.93"
}
, Text = {
Align = TextAnchor.MiddleCenter, FontSize = 14, Text = GetMessage("CanCreatePoll")
}
}
, MainElement);
int Number = 0;
if (HasPermission(player, "Polling.Create.Airdrop")) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.76 - (Number * 0.08)), AnchorMax = "0.99 " + (0.80 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = GetMessage("HelpAirdropPoll")
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.72 - (Number * 0.08)), AnchorMax = "0.99 " + (0.76 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = string.Format(GetMessage("HelpAirdropPollUsage").Replace("'", "''"), MainSettings["ChatCommand"] as string)
}
}
, MainElement);
Number++;
}
if (HasPermission(player, "Polling.Create.Ban")) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.76 - (Number * 0.08)), AnchorMax = "0.99 " + (0.80 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = GetMessage("HelpUserBanPoll")
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.72 - (Number * 0.08)), AnchorMax = "0.99 " + (0.76 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = string.Format(GetMessage("HelpUserBanPollUsage").Replace("'", "''"), MainSettings["ChatCommand"] as string)
}
}
, MainElement);
Number++;
}
if (HasPermission(player, "Polling.Create.Custom")) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.76 - (Number * 0.08)), AnchorMax = "0.99 " + (0.80 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = GetMessage("HelpCustomPoll")
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.72 - (Number * 0.08)), AnchorMax = "0.99 " + (0.76 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = string.Format(GetMessage("HelpCustomPollUsage").Replace("'", "''"), MainSettings["ChatCommand"] as string)
}
}
, MainElement);
Number++;
}
if (HasPermission(player, "Polling.Create.Heli")) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.76 - (Number * 0.08)), AnchorMax = "0.99 " + (0.80 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = GetMessage("HelpHeliPoll")
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.72 - (Number * 0.08)), AnchorMax = "0.99 " + (0.76 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = string.Format(GetMessage("HelpHeliPollUsage").Replace("'", "''"), MainSettings["ChatCommand"] as string)
}
}
, MainElement);
Number++;
}
if (HasPermission(player, "Polling.Create.Kick")) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.76 - (Number * 0.08)), AnchorMax = "0.99 " + (0.80 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = GetMessage("HelpUserKickPoll")
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.72 - (Number * 0.08)), AnchorMax = "0.99 " + (0.76 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = string.Format(GetMessage("HelpUserKickPollUsage").Replace("'", "''"), MainSettings["ChatCommand"] as string)
}
}
, MainElement);
Number++;
}
if (HasPermission(player, "Polling.Create.Time")) {
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.76 - (Number * 0.08)), AnchorMax = "0.99 " + (0.80 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = GetMessage("HelpTimePoll")
}
}
, MainElement);
elements.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.02 " + (0.72 - (Number * 0.08)), AnchorMax = "0.99 " + (0.76 - (Number * 0.08))
}
, Text = {
Align = TextAnchor.MiddleLeft, FontSize = 14, Text = string.Format(GetMessage("HelpTimePollUsage").Replace("'", "''"), MainSettings["ChatCommand"] as string)
}
}
, MainElement);
Number++;
}
if (CustomPolls.Count == 0) {
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.Help Custom", Color = "255 0 0 0.90"
}
, RectTransform = {
AnchorMin = "0.02 0.15", AnchorMax = "0.99 0.19"
}
, Text = {
Text = string.Format(GetMessage("CustomPollCount"), CustomPolls.Count), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
}
else {
elements.Add(new CuiButton {
Button = {
Command = "Polling.GUI.Help Custom", Color = "0 255 255 0.90"
}
, RectTransform = {
AnchorMin = "0.02 0.15", AnchorMax = "0.99 0.19"
}
, Text = {
Text = string.Format(GetMessage("CustomPollCount"), CustomPolls.Count), Align = TextAnchor.MiddleCenter, FontSize = 12
}
}
, MainElement);
// ... [Code preview truncated due to length. Full source in attached file] ...