Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- namespace Oxide.Plugins
- {
- [Info("DiceRoller", "Krythic", "1.0.0")]
- [Description("Allows players to roll a number between 1 and 100 using /roll")]
- public class DiceRoller : RustPlugin
- {
- private void Init()
- {
- cmd.AddChatCommand("roll", this, "RollCommand");
- cmd.AddChatCommand("dice", this, "DiceRollerInfoCommand");
- }
- private int NextRoll(int min, int max)
- {
- return UnityEngine.Random.Range(min,max + 1);
- }
- private void BroadcastResult(string message)
- {
- Puts(message);
- PrintToChat("[Dice Roller] " + message);
- }
- private void DiceRollerInfoCommand(BasePlayer player, string command, string[] args)
- {
- Puts($"{player.displayName} displayed the DiceRoller info.");
- SendReply(player,
- "[Dice Roller Info]\n"+
- "Creator: Krythic\n" +
- "v1.0.0\n" +
- "Commands\n" +
- "/dice (Displays this information)\n" +
- "/roll (Rolls a D100)\n" +
- "/roll d4 (Rolls a D4)\n" +
- "/roll d6 (Rolls a D6)\n" +
- "/roll d8 (Rolls a D8)\n" +
- "/roll d10 (Rolls a D10)\n" +
- "/roll d12 (Rolls a D12)\n" +
- "/roll d20 (Rolls a D20)\n" +
- "/roll d100 (Rolls a D100)\n"
- );
- }
- private void RollCommand(BasePlayer player, string command, string[] args)
- {
- if(args != null && args.Length > 0){
- if(args[0].Equals("d4"))
- {
- int d4Result = NextRoll(1,4);
- BroadcastResult($"{player.displayName} rolled a d4, and got a {d4Result}!");
- return;
- }
- if(args[0].Equals("d6"))
- {
- int d6Result = NextRoll(1,6);
- BroadcastResult($"{player.displayName} rolled a d6, and got a {d6Result}!");
- return;
- }
- if(args[0].Equals("d8"))
- {
- int d8Result = NextRoll(1,8);
- BroadcastResult($"{player.displayName} rolled a d8, and got a {d8Result}!");
- return;
- }
- if(args[0].Equals("d10"))
- {
- int d10Result = NextRoll(1,10);
- BroadcastResult($"{player.displayName} rolled a d10, and got a {d10Result}!");
- return;
- }
- if(args[0].Equals("d12"))
- {
- int d12Result = NextRoll(1,12);
- BroadcastResult($"{player.displayName} rolled a d12, and got a {d12Result}!");
- return;
- }
- if(args[0].Equals("d20"))
- {
- int d20Result = NextRoll(1,20);
- BroadcastResult($"{player.displayName} rolled a d20, and got a {d20Result}!");
- return;
- }
- if(args[0].Equals("d100"))
- {
- int d100Result = NextRoll(1,100);
- BroadcastResult($"{player.displayName} rolled a d100, and got a {d100Result}!");
- return;
- }
- }else{
- // Generate a random number between 1 and 100
- int roll = NextRoll(1,100);
- BroadcastResult($"{player.displayName} rolled a d100, and got a {roll}!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement