Advertisement
Guest User

Random Case Mechanics ServerSide

a guest
Apr 4th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. local debounce = {}
  2.  
  3. local function rand(tbl)
  4.     local rn = Random.new()
  5.     local sum = 0
  6.     for i = 1, #tbl do
  7.         sum = sum + tbl[i].Weight
  8.     end
  9.     local num = rn:NextNumber(0, sum)
  10.     for i = 1, #tbl do
  11.         if num <= tbl[i].Weight then
  12.             return tbl[i]
  13.         end
  14.         num = num - tbl[i].Weight
  15.     end
  16. end
  17.  
  18. local tabl = {
  19.     {Obj = "Common", Weight = 44},
  20.     {Obj = "Uncommon", Weight = 32},
  21.     {Obj = "Rare", Weight = 21},
  22.     {Obj = "Epik", Weight = 10},
  23.     {Obj = "Legendary", Weight = 2},
  24.     {Obj = "Mythic", Weight = 0.1},
  25.     {Obj = "The Unobtainable", Weight = 0.0001},    
  26. }
  27.  
  28. local tabl2 = {
  29.  
  30. ["Common"] = {
  31.  
  32. {Obj = "Gun", Weight = 30},
  33. {Obj = "Sword", Weight = 20},
  34. {Obj = "Pie", Weight = 10},
  35. {Obj = "Corn", Weight = 5},
  36.  
  37. },
  38. ["Uncommon"] = {
  39.  
  40. {Obj = "Green greene gun", Weight = 20},
  41. {Obj = "Sock", Weight = 20},
  42. {Obj = "Big bone", Weight = 20},
  43. {Obj = "Hello", Weight = 20},
  44.  
  45. },
  46. ["Rare"] = {
  47.  
  48. {Obj = "Gobstopper", Weight = 10},
  49. {Obj = "Melodic Rifle", Weight = 20},
  50. {Obj = "Annoyingly Common Coin", Weight = 50},
  51. {Obj = "Severed Leg", Weight = 20},
  52.  
  53. },
  54. ["Epik"] = {
  55.  
  56. {Obj = "Tom's mini cannon", Weight = 30},
  57. {Obj = "Golden Plate", Weight = 10},
  58. {Obj = "Killer bean", Weight = 20},
  59. {Obj = "Gross Hankerchief", Weight = 30},
  60.  
  61. },
  62. ["Legendary"] = {
  63.  
  64. {Obj = "Bazooka", Weight = 20},
  65. {Obj = "Thanos guantlet", Weight = 10},
  66. {Obj = "Echoer", Weight = 30},
  67. {Obj = "Platinum Plate", Weight = 8},
  68.  
  69. },
  70. ["Mythic"] = {
  71.  
  72. {Obj = "Reality Rifle", Weight = 10},
  73. {Obj = "Sword Requiem", Weight = 20},
  74. {Obj = "Headhunter", Weight = 30},
  75.  
  76. },
  77. ["The Unobtainable"] = {
  78.  
  79.  
  80. {Obj = "The One and Only.", Weight = 100}
  81.  
  82. },
  83. }
  84.  
  85. game.ReplicatedStorage.CaseEvent.OnServerInvoke = function(player)
  86.     if not debounce[player] then
  87.         debounce[player] = true
  88.         coroutine.resume(coroutine.create(function()
  89.             wait(0.1)
  90.             debounce[player] = false
  91.         end))
  92.         local i = rand(tabl)
  93.         local i2 = rand(tabl2[i.Obj])
  94.         return {i,i2}
  95.     end
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement