From fd21eaa448df3e298a3ba06741948bc193004f03 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sat, 7 Aug 2021 18:23:51 -0500 Subject: [PATCH] Fixed some code, added argument to !roll --- complexCommands.lua | 6 +++++- rng.lua | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/complexCommands.lua b/complexCommands.lua index 0acd591..d559560 100644 --- a/complexCommands.lua +++ b/complexCommands.lua @@ -11,8 +11,12 @@ local commands = { -- Define commands its a table that will contain our commands end }; [prefix..'roll'] = { -- Rolls a d20, check RNG for more info. - exec = function (message) + exec = function (message, arg) + if not arg[2] then message.channel:send(rng.d20()) + else + message.channel:send(rng.roll(arg)) + end end }; [prefix..'figlet'] = { -- Parrots input to figlet, then echos it to the same channel you are in. diff --git a/rng.lua b/rng.lua index 0e8d71f..3dfb580 100644 --- a/rng.lua +++ b/rng.lua @@ -17,4 +17,21 @@ function rng.d20() return message end +function rng.roll(arg) + tools.seed() + local mathArgument = arg[2] + local compareNumber = tonumber(mathArgument) + local dice = math.random(mathArgument) + local messagePart1 = ('You rolled a ' .. dice .. ' out of '..mathArgument) + local messagepart2 = '' + if dice == compareNumber then + messagepart2 = ('Nat '..mathArgument..'! Crititcal Hit') + else if dice==1 then + messagepart2 = ('Nat 1! Critical Shit!') + end + end + local message = messagePart1 .. '\n' .. messagepart2 + return message + end + return rng \ No newline at end of file