Advertisement
Krythic

Dice Roller

Jun 15th, 2024
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. namespace Oxide.Plugins
  5. {
  6.     [Info("DiceRoller", "Krythic", "1.0.0")]
  7.     [Description("Allows players to roll a number between 1 and 100 using /roll")]
  8.  
  9.     public class DiceRoller : RustPlugin
  10.     {
  11.        
  12.         private void Init()
  13.         {
  14.             cmd.AddChatCommand("roll", this, "RollCommand");
  15.             cmd.AddChatCommand("dice", this, "DiceRollerInfoCommand");
  16.         }
  17.        
  18.         private int NextRoll(int min, int max)
  19.         {
  20.             return UnityEngine.Random.Range(min,max + 1);
  21.         }
  22.        
  23.         private void BroadcastResult(string message)
  24.         {
  25.             Puts(message);
  26.             PrintToChat("[Dice Roller] " + message);
  27.            
  28.         }
  29.        
  30.         private void DiceRollerInfoCommand(BasePlayer player, string command, string[] args)
  31.         {
  32.             Puts($"{player.displayName} displayed the DiceRoller info.");
  33.             SendReply(player,
  34.                 "[Dice Roller Info]\n"+
  35.                 "Creator: Krythic\n" +
  36.                 "v1.0.0\n" +
  37.                 "Commands\n" +
  38.                 "/dice (Displays this information)\n" +
  39.                 "/roll (Rolls a D100)\n" +
  40.                 "/roll d4 (Rolls a D4)\n" +
  41.                 "/roll d6 (Rolls a D6)\n" +
  42.                 "/roll d8 (Rolls a D8)\n" +
  43.                 "/roll d10 (Rolls a D10)\n" +
  44.                 "/roll d12 (Rolls a D12)\n" +
  45.                 "/roll d20 (Rolls a D20)\n" +
  46.                 "/roll d100 (Rolls a D100)\n"
  47.             );
  48.         }
  49.        
  50.        
  51.         private void RollCommand(BasePlayer player, string command, string[] args)
  52.         {
  53.             if(args != null && args.Length > 0){
  54.                 if(args[0].Equals("d4"))
  55.                 {
  56.                     int d4Result = NextRoll(1,4);
  57.                     BroadcastResult($"{player.displayName} rolled a d4, and got a {d4Result}!");
  58.                     return;
  59.                 }
  60.                 if(args[0].Equals("d6"))
  61.                 {
  62.                     int d6Result = NextRoll(1,6);
  63.                     BroadcastResult($"{player.displayName} rolled a d6, and got a {d6Result}!");
  64.                     return;
  65.                 }
  66.                 if(args[0].Equals("d8"))
  67.                 {
  68.                     int d8Result = NextRoll(1,8);
  69.                     BroadcastResult($"{player.displayName} rolled a d8, and got a {d8Result}!");
  70.                     return;
  71.                 }
  72.                 if(args[0].Equals("d10"))
  73.                 {
  74.                     int d10Result = NextRoll(1,10);
  75.                     BroadcastResult($"{player.displayName} rolled a d10, and got a {d10Result}!");
  76.                     return;
  77.                 }
  78.                 if(args[0].Equals("d12"))
  79.                 {
  80.                     int d12Result = NextRoll(1,12);
  81.                     BroadcastResult($"{player.displayName} rolled a d12, and got a {d12Result}!");
  82.                     return;
  83.                 }
  84.                 if(args[0].Equals("d20"))
  85.                 {
  86.                     int d20Result = NextRoll(1,20);
  87.                     BroadcastResult($"{player.displayName} rolled a d20, and got a {d20Result}!");
  88.                     return;
  89.                 }
  90.                 if(args[0].Equals("d100"))
  91.                 {
  92.                     int d100Result = NextRoll(1,100);
  93.                     BroadcastResult($"{player.displayName} rolled a d100, and got a {d100Result}!");
  94.                     return;
  95.                 }
  96.                
  97.             }else{
  98.                 // Generate a random number between 1 and 100
  99.                 int roll = NextRoll(1,100);
  100.                 BroadcastResult($"{player.displayName} rolled a d100, and got a {roll}!");
  101.             }
  102.            
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement