public void Execute(IRocketPlayer caller, string[] command) { try { var player = (UnturnedPlayer)caller; if (Plugin.NoQuestion) { var noQuestion = Plugin.Inst.Translate("mathquiz_no_question"); ChatManager.serverSendMessage(noQuestion, UnturnedChat.GetColorFromName(Plugin.Conf.UnfavorableMessageColor, Color.red), null, ((UnturnedPlayer)caller).SteamPlayer(), EChatMode.SAY, Plugin.Conf.AnnouncerImageUrl, true); } else { if (command.Length >= 1) { if (command[0] == Plugin.Result.ToString() && !Plugin.NoQuestion) { Plugin.NoQuestion = true; if (Plugin.Inst.CurrentQuizModel.RewardType == ERewardType.Uconomy) { RocketPlugin.ExecuteDependencyCode("Uconomy", (IRocketPlugin plugin) => { var uconomy = (Uconomy)plugin; uconomy.Database.IncreaseBalance(player.CSteamID.ToString(), Plugin.Inst.CurrentQuizModel.RewardAmount); var rightanswer = Plugin.Inst.Translate("mathquiz_true_answer", Plugin.Inst.CurrentQuizModel.RewardAmount.ToString(), uconomy.Configuration.Instance.MoneyName, uconomy.Database.GetBalance(player.CSteamID.ToString())); ChatManager.serverSendMessage(rightanswer, UnturnedChat.GetColorFromName(Plugin.Conf.MessageColor, Color.yellow), null, player.SteamPlayer(), EChatMode.SAY, Plugin.Conf.AnnouncerImageUrl, true); var winner = Plugin.Inst.Translate("mathquiz_broadcast_winner", caller.DisplayName, Plugin.Result.ToString(), Plugin.Inst.CurrentQuizModel.RewardAmount.ToString(), uconomy.Configuration.Instance.MoneyName); ChatManager.serverSendMessage(winner, UnturnedChat.GetColorFromName(Plugin.Conf.MessageColor, Color.yellow), null, null, EChatMode.GLOBAL, Plugin.Conf.AnnouncerImageUrl, true); }); } else { player.Experience += Plugin.Inst.CurrentQuizModel.RewardAmount; var correctAnswer = Plugin.Inst.Translate("mathquiz_true_answer", Plugin.Inst.CurrentQuizModel.RewardAmount.ToString(), "Experience", player.Experience); ChatManager.serverSendMessage(correctAnswer, UnturnedChat.GetColorFromName(Plugin.Conf.MessageColor, Color.yellow), null, player.SteamPlayer(), EChatMode.SAY, Plugin.Conf.AnnouncerImageUrl, true); var winner = Plugin.Inst.Translate("mathquiz_broadcast_winner", caller.DisplayName, Plugin.Result.ToString(), Plugin.Inst.CurrentQuizModel.RewardAmount.ToString(), "Experience"); ChatManager.serverSendMessage(winner, UnturnedChat.GetColorFromName(Plugin.Conf.MessageColor, Color.yellow), null, null, EChatMode.GLOBAL, Plugin.Conf.AnnouncerImageUrl, true); } } if (command[0] != Plugin.Result.ToString() && !Plugin.NoQuestion) { ChatManager.serverSendMessage(Plugin.Inst.Translate("mathquiz_wrong_answer"), UnturnedChat.GetColorFromName(Plugin.Conf.UnfavorableMessageColor, Color.red), null, ((UnturnedPlayer)caller).SteamPlayer(), EChatMode.SAY, Plugin.Conf.AnnouncerImageUrl, true); } } else { ChatManager.serverSendMessage(Plugin.Inst.Translate("mathquiz_invalid_parameter"), UnturnedChat.GetColorFromName(Plugin.Conf.MessageColor, Color.yellow), null, ((UnturnedPlayer)caller).SteamPlayer(), EChatMode.SAY, Plugin.Conf.AnnouncerImageUrl, true); } } } catch (Exception err) { Logger.LogError("[RFMathQuiz] Error: " + err); } }
public static void GiveReward(UnturnedPlayer player, string serviceName) { int sum = Plugin.VoteRewardsPlugin.Instance.Configuration.Instance.Rewards.Sum(p => p.Chance); string selectedElement = null; string value = null; System.Random r = new System.Random(); int i = 0, diceRoll = r.Next(0, sum); foreach (var reward in Plugin.VoteRewardsPlugin.Instance.Configuration.Instance.Rewards) { if (diceRoll > i && diceRoll <= i + reward.Chance) { selectedElement = reward.Type; value = reward.Value; break; } i = i + reward.Chance; } if (selectedElement == null || value == null) { UnturnedChat.Say(player, "The admin hasn't setup rewards yet.", Color.red); return; } // Rewards if (selectedElement == "item" || selectedElement == "i") { List <string> items = value.Split(',').ToList(); foreach (string item in items) { ushort itemID = ushort.Parse(item); player.Inventory.tryAddItem(new Item(itemID, true), true); } UnturnedChat.Say(player, Plugin.VoteRewardsPlugin.Instance.Translate("reward", "some items")); } else if (selectedElement == "xp" || selectedElement == "exp") { player.Experience += uint.Parse(value); UnturnedChat.Say(player, Plugin.VoteRewardsPlugin.Instance.Translate("reward", value + " xp")); } else if (selectedElement == "group" || selectedElement == "permission") { R.Permissions.AddPlayerToGroup(value, player); R.Permissions.Reload(); UnturnedChat.Say(player, Plugin.VoteRewardsPlugin.Instance.Translate("reward", value + " Permission Group")); } else if (selectedElement == "uconomy" || selectedElement == "money") { if (Plugin.VoteRewardsPlugin.Uconomy) { RocketPlugin.ExecuteDependencyCode("Uconomy", (IRocketPlugin plugin) => { Uconomy.Instance.Database.IncreaseBalance(player.CSteamID.ToString(), decimal.Parse(value)); UnturnedChat.Say(player, Plugin.VoteRewardsPlugin.Instance.Translate("reward", value + " Uconomy " + Uconomy.Instance.Configuration.Instance.MoneyName + "s")); }); } } else if (selectedElement == "slot" || selectedElement.Contains("customkit")) { if (Plugin.VoteRewardsPlugin.CustomKits) { RocketPlugin.ExecuteDependencyCode("CustomKits", (IRocketPlugin plugin) => { SlotManager.AddSlot(player, 1, int.Parse(value)); UnturnedChat.Say(player, Plugin.VoteRewardsPlugin.Instance.Translate("reward", "a CustomKits slot with item limit of " + value)); }); } } // Optional global announcement if (Plugin.VoteRewardsPlugin.Instance.Configuration.Instance.GlobalAnnouncement) { foreach (SteamPlayer sP in Provider.clients) { var p = sP.playerID.steamID; if (p != player.CSteamID) { ChatManager.say(p, Plugin.VoteRewardsPlugin.Instance.Translate("reward_announcement", player.CharacterName, serviceName), Color.green, EChatMode.GLOBAL); } } } }