Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------ Documentation
- --[[
- 'setShopUI': Sets up player shop UI (Item list, Costs, etc) with Shop Npc Data of Model Name Passed
- ]]
- ------ Services
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- ------ Imports
- local BridgeNet = require(ReplicatedStorage.Modules.BridgeNet2)
- local shopNPCHandler = require(ReplicatedStorage.Modules.Handlers.shopHandler.shopNPCHandler)
- local itemHandler = require(ReplicatedStorage.Modules.Handlers.itemHandler)
- local notifHandler = require(ReplicatedStorage.Modules.Handlers.notifHandler)
- ------ Events
- local buyItemTrigger = BridgeNet.ServerBridge("buyItemTrigger")
- local shopHandler = {}
- shopHandler.BuyItem = function(player, ...)
- print("awsd") -- To Test
- end
- shopHandler.setShopItemInfoToUI = function(UI, Id)
- local itemBaseInfo = itemHandler.getItemBaseInfoFromId(tonumber(Id))
- UI.ItemName.Text = itemBaseInfo.Name
- UI.ItemImage.Image = itemBaseInfo.Image
- UI.MoneyCost.Amount.Text = tostring(itemBaseInfo.buyValue)
- -- Set the frame/buttons ItemCategory for easy access in other scripts
- UI:SetAttribute("ItemCategory", itemBaseInfo.Category)
- -- Set the frame/buttons Id Attribute for easy access in other scripts
- UI:SetAttribute("Id", itemBaseInfo.Id)
- UI.Visible = true
- end
- shopHandler.setShopUI = function(player: Player, ShopNPCMOdel: Model, ShopNPCId: number) -- Passes Npc Model and Npc Shop Id Number
- local PlayerShopUI: ScreenGui = player.PlayerGui.ShopUI
- local playerShopItemTemplate: GuiButton = PlayerShopUI.ShopItemTemplate
- local playerShopScrollingUIList: ScrollingFrame = PlayerShopUI.ItemList
- ---- Loop through the items found in the shop data
- for _, item in shopNPCHandler.getShopItemList(ShopNPCId) do
- task.spawn(function()
- local itemUI = playerShopItemTemplate:Clone()
- shopHandler.setShopItemInfoToUI(itemUI, item.Id)
- itemUI.Parent = playerShopScrollingUIList
- PlayerShopUI:GetPropertyChangedSignal("Enabled"):Connect(function()
- if PlayerShopUI.Enabled == false then
- itemUI:Destroy()
- end
- end)
- end)
- end
- end
- buyItemTrigger:Connect(shopHandler.BuyItem)
- return shopHandler
Advertisement
Add Comment
Please, Sign In to add comment