Advertisement
Terrah

dice

Feb 1st, 2016
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. local function Dice(d)
  2.  
  3. if type(d)~="string" then
  4. return nil;
  5. end
  6.  
  7. local rolls,sides = d:match("(%d+)d(%d+)");
  8.  
  9. if rolls==nil or sides==nil then
  10. return nil;
  11. end
  12.  
  13. local result = 0;
  14.  
  15. rolls = math.max(math.min(rolls,10000),1);
  16. sides = math.max(math.min(sides,10000),1);
  17.  
  18. for n=1, rolls do
  19. result = result + math.random(1,sides);
  20. end
  21.  
  22. return result;
  23. end
  24.  
  25. local func = function(msg,usr,chan)
  26.  
  27. local res = Dice(msg);
  28.  
  29. if res==nil then
  30. print("@"..usr.." enter a valid dice. Example: 1d6");
  31. return
  32. end
  33.  
  34. print("@"..usr.." "..msg.." = "..res);
  35. end
  36.  
  37. return func;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement