internal class GambleCommand : Command { public GambleCommand() : base("roll", 3) { } protected override bool Process(Player player, RealmTime time, string[] args) { try { if (args.Length == 1) { int num = int.Parse(args[0]); Random rnd = new Random(); string pl = player.Name; string rand = ""; if (num < 0) rand = rnd.Next(num, 0).ToString(); else rand = rnd.Next(0, num).ToString(); decimal pc = num * rand / 100; foreach (Client i in player.Manager.Clients.Values) { i.SendPacket(new TextPacket { BubbleTime = 0, Stars = -1, Name = pl, Text = "rolled a " + rand + " out of " + num + ". (" + pc + "%)" }); } } } catch { Random rnd = new Random(); string pl = player.Name; string rand = rnd.Next(0, 100).ToString(); foreach (Client i in player.Manager.Clients.Values) { i.SendPacket(new TextPacket { BubbleTime = 0, Stars = -1, Name = pl, Text = "rolled a " + rand + " out of 100." }); } } return true; } }
int rand; ... rand = rnd.Next(num, 0);
int pc = rand * 100 / NUM;
decimal pc = num * decimal.Parse(rand) / 100;
decimal pc = decimal.Parse(rand) / num * 100;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)