Advertisement
Grillkol

RandomizerMain

Mar 31st, 2024 (edited)
3,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. -- Server backend for random wheel commission
  2. -- Author: grillkol (discord)
  3. -- Copying or distributing this script is not permitted without explicit permission from the author.
  4.  
  5. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  6. local HttpService = game:GetService("HttpService")
  7.  
  8. local RandomizerMap = require(ReplicatedStorage.Modules.RandomizerMap)
  9. local RNG = require(ReplicatedStorage.Modules.RNG)
  10.  
  11. local rewardCache = {}
  12.  
  13. local RandomizerHandler = {}
  14.  
  15. function RandomizerHandler.Initialize()
  16.     ReplicatedStorage.Remotes.RandomizerNetworker.OnServerEvent:Connect(function(player, topic, data)
  17.         if topic == "requestSpin" then
  18.             RandomizerHandler.InitiateSpin(player, "shogun")
  19.         elseif topic == "completedSpin" then
  20.             RandomizerHandler.CompletedSpin(player, data)
  21.         end
  22.     end)
  23. end
  24.  
  25. function RandomizerHandler.CompletedSpin(player, data)
  26.     if data.id then
  27.         local rewardData = rewardCache[data.id]
  28.        
  29.         if rewardData then
  30.             rewardCache[data.id] = nil
  31.             print(rewardData)
  32.             -- Here you can run any needed functions such as giving player the item
  33.         end
  34.     end
  35. end
  36.  
  37. function RandomizerHandler.TimeoutReward(data)
  38.     task.delay(60, function()
  39.         rewardCache[data.id] = nil
  40.     end)
  41. end
  42.  
  43. function RandomizerHandler.InitiateSpin(player, randomizerType) -- randomizerType = "shogun"
  44.     local data = {}
  45.    
  46.     data.randomizerType = randomizerType
  47.     data.item, data.rarity = RandomizerMap[data.randomizerType]()
  48.     data.id = HttpService:GenerateGUID()
  49.     rewardCache[data.id] = data
  50.     ReplicatedStorage.Remotes.RandomizerNetworker:FireClient(player, "startSpin", data)
  51. end
  52.  
  53. return RandomizerHandler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement