Guest User

shopHandler Module Script

a guest
Jun 14th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. ------ Documentation
  2. --[[
  3.     'setShopUI': Sets up player shop UI (Item list, Costs, etc) with Shop Npc Data of Model Name Passed
  4.  
  5. ]]
  6.  
  7. ------ Services
  8. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  9.  
  10. ------ Imports
  11. local BridgeNet = require(ReplicatedStorage.Modules.BridgeNet2)
  12. local shopNPCHandler = require(ReplicatedStorage.Modules.Handlers.shopHandler.shopNPCHandler)
  13. local itemHandler = require(ReplicatedStorage.Modules.Handlers.itemHandler)
  14. local notifHandler = require(ReplicatedStorage.Modules.Handlers.notifHandler)
  15.  
  16.  
  17. ------ Events
  18. local buyItemTrigger = BridgeNet.ServerBridge("buyItemTrigger")
  19.  
  20.  
  21. local shopHandler = {}
  22.  
  23. shopHandler.BuyItem = function(player, ...)
  24.     print("awsd") -- To Test
  25. end
  26.  
  27. shopHandler.setShopItemInfoToUI = function(UI, Id)
  28.    
  29.     local itemBaseInfo = itemHandler.getItemBaseInfoFromId(tonumber(Id))
  30.    
  31.     UI.ItemName.Text = itemBaseInfo.Name
  32.     UI.ItemImage.Image = itemBaseInfo.Image
  33.     UI.MoneyCost.Amount.Text = tostring(itemBaseInfo.buyValue)
  34.  
  35.     -- Set the frame/buttons ItemCategory for easy access in other scripts
  36.     UI:SetAttribute("ItemCategory", itemBaseInfo.Category)
  37.     -- Set the frame/buttons Id Attribute for easy access in other scripts
  38.     UI:SetAttribute("Id", itemBaseInfo.Id)
  39.  
  40.     UI.Visible = true
  41. end
  42.  
  43. shopHandler.setShopUI = function(player: Player, ShopNPCMOdel: Model, ShopNPCId: number) -- Passes Npc Model and Npc Shop Id Number
  44.     local PlayerShopUI: ScreenGui = player.PlayerGui.ShopUI
  45.     local playerShopItemTemplate: GuiButton = PlayerShopUI.ShopItemTemplate
  46.     local playerShopScrollingUIList: ScrollingFrame = PlayerShopUI.ItemList
  47.  
  48.     ---- Loop through the items found in the shop data
  49.     for _, item in shopNPCHandler.getShopItemList(ShopNPCId) do
  50.         task.spawn(function()
  51.  
  52.         local itemUI = playerShopItemTemplate:Clone()
  53.        
  54.         shopHandler.setShopItemInfoToUI(itemUI, item.Id)
  55.         itemUI.Parent = playerShopScrollingUIList
  56.        
  57.         PlayerShopUI:GetPropertyChangedSignal("Enabled"):Connect(function()
  58.             if PlayerShopUI.Enabled == false then
  59.                 itemUI:Destroy()
  60.             end
  61.         end)
  62.        
  63.         end)
  64.        
  65.     end
  66. end
  67.  
  68. buyItemTrigger:Connect(shopHandler.BuyItem)
  69.  
  70. return shopHandler
Advertisement
Add Comment
Please, Sign In to add comment