Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Inventory Controller 1
- local Storage = game:GetService("ReplicatedStorage")
- local Events = Storage:WaitForChild("Events")
- local Players = game:GetService("Players")
- local Items = Storage:WaitForChild("CraftableItems")
- local WepItems = Storage:WaitForChild("Weapons")
- local InventoryFunction = Events:WaitForChild('InventoryFunction')
- local Modules = Storage:WaitForChild("Modules")
- local InventoryModule = require(Modules:WaitForChild('Inventory'))
- local Max_Item_Slots = InventoryModule['Max_Item_Slots']
- Players.PlayerAdded:Connect(function(plr)
- local EquippedFolder = Instance.new("Folder", plr)
- EquippedFolder.Name = 'Equipped_Items'
- end)
- InventoryFunction.OnServerInvoke = function(plr, itemChosen, specificName, Type, action)
- if action == 'EquipNewItem' then
- if itemChosen then
- print(itemChosen.. ' has been found from server side. '.. specificName.. " Type is: ".. Type)
- local Equipped_Items = plr:WaitForChild('Equipped_Items')
- -- Max children check.
- for num,child in pairs(plr:WaitForChild('Equipped_Items'):GetChildren()) do
- if num == Max_Item_Slots then
- return "Max slots."
- end
- end
- --
- end
- end
- if action == 'EquipDefaultItem' then
- if Type == 'Food' then
- local Clone = Storage:WaitForChild(itemChosen):Clone()
- Clone.Parent = plr.Character
- Clone['RightHand'].Part1 = plr.Character:WaitForChild('RightHand')
- local newValue = Instance.new("BoolValue", plr:WaitForChild('Equipped_Items'))
- newValue.Name = itemChosen
- newValue.Value = true
- end
- end
- if action == 'UnEquip' then
- if plr:WaitForChild('Equipped_Items'):FindFirstChild(itemChosen) then
- if Type == 'Food' then
- plr.Equipped_Items[itemChosen]:Destroy()
- local find = plr.Character:FindFirstChild(itemChosen)
- find:Destroy()
- end
- end
- end
- end
- ---
- -- Inventory Controller 2
- -- Crafting Core
- -- By Sylvern
- -- 4/29/2020
- local Settings = require(game:GetService("ReplicatedStorage"):WaitForChild('Modules'):WaitForChild('Crafting'))
- local Players = game:GetService("Players")
- local Storage = game:GetService("ReplicatedStorage")
- local CraftableItems = Storage:WaitForChild("CraftableItems")
- local Events = Storage:WaitForChild("Events")
- local Crafting_Event = Events:WaitForChild('CraftingEvent')
- local Get_Description = Events:WaitForChild('GetDescription')
- local Starter_Materials = Settings['Starter_Materials']
- local Craftable_Items = Settings['Craftable_Items']
- Players.PlayerAdded:Connect(function(plr)
- local Materials = Instance.new("Folder", plr)
- Materials.Name = 'Materials'
- local Inventory = Instance.new("Folder", plr)
- Inventory.Name = 'Inventory'
- for name,value in pairs(Starter_Materials) do
- local newValue = Instance.new("NumberValue", Materials)
- newValue.Name = name
- newValue.Value = value
- end
- end)
- Crafting_Event.OnServerEvent:Connect(function(plr, action, itemName)
- if action == 'CraftItem' then
- local checkItem = CraftableItems:FindFirstChild(itemName)
- if not checkItem then
- plr:Kick('Stop exploiting.')
- end
- if checkItem then
- for name, value in pairs(Craftable_Items[itemName].Cost) do
- warn(itemName)
- warn(name, value)
- if plr:WaitForChild('Materials')[name].Value < value then warn"Not enough materials" return end
- plr.Materials[name].Value = plr.Materials[name].Value - value
- warn("Successfully crafted "..itemName)
- local newItem = Instance.new("BoolValue", plr:WaitForChild('Inventory'))
- newItem.Name = Craftable_Items[itemName]['ItemName']
- newItem.Value = true
- end
- end
- end
- end)
- Get_Description.OnServerInvoke = function(plr, action, itemName, bool)
- if action == 'Desc' then
- warn(itemName)
- local getItem = Craftable_Items[itemName].Description
- warn(getItem)
- return getItem
- end
- if action == 'GetType' then
- local getItem = Settings['Items'][itemName].Type
- return getItem
- end
- if action == 'CraftingReturn' then
- if bool == true then
- return true
- elseif bool == false then
- return false
- end
- end
- if action == 'GetStarterMats' then
- return Starter_Materials
- end
- end
- --
- -- Inventory Controller 3
- game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
- local Storage = game:GetService("ReplicatedStorage")
- local Modules = Storage:WaitForChild("Modules")
- local UIS = game:GetService("UserInputService")
- local Inventory = require(Modules:WaitForChild('Inventory'))
- local Max_Backpack_Slots = Inventory['Max_Backpack_Slots']
- local Events = Storage:WaitForChild("Events")
- local InventoryFunction = Events:WaitForChild('InventoryFunction')
- local GetDesc = Events:WaitForChild('GetDescription')
- local Template = script:WaitForChild("Template")
- local ButtonTemplate = script:WaitForChild("TextButton")
- local BackpackFrame = script.Parent:WaitForChild("BackpackFrame")
- local Default_Items = script.Parent:WaitForChild("DefaultItems")
- local ItemEquipped = ""
- local Item_Slots = {
- }
- function update()
- local Children = Default_Items:GetChildren()
- for i = 1, Max_Backpack_Slots do
- local Clone = Template:Clone()
- Clone.Parent = BackpackFrame
- Clone.Name = i
- end
- for i = 1, #Children do
- local Slot = Instance.new("NumberValue", BackpackFrame:FindFirstChild(i))
- Slot.Name = Children[i].Name
- Slot.Value = Children[i].Value
- local Button = ButtonTemplate:Clone()
- Button.Parent = BackpackFrame:FindFirstChild(i)
- Button.Text = Children[i].Name
- table.insert(Item_Slots, i, {Children[i].Name, Children[i].Value, Children[i].Number.Value})
- end
- end
- wait(2)
- update()
- UIS.InputBegan:Connect(function(input, gpe)
- if gpe then return end
- for _,v in pairs(Item_Slots) do
- if input.KeyCode == Enum.KeyCode[v[3]] then
- if ItemEquipped == "" then
- print(v[1])
- ItemEquipped = tostring(v[1])
- InventoryFunction:InvokeServer(tostring(v[1]), "", GetDesc:InvokeServer('GetType', tostring(v[1])), 'EquipDefaultItem')
- elseif ItemEquipped == v[1] then
- ItemEquipped = ""
- InventoryFunction:InvokeServer(tostring(v[1]), "", GetDesc:InvokeServer('GetType', tostring(v[1])), 'UnEquip')
- else
- print"You must unequip your equipped item first."
- end
- end
- end
- end)
- -- Inventory Controller 4
- local Players = game:GetService("Players")
- local Player = Players.LocalPlayer
- local Storage = game:GetService("ReplicatedStorage")
- local Mouse = Player:GetMouse()
- local Events = Storage:WaitForChild("Events")
- local Event = Events:WaitForChild('CraftingEvent')
- local DescEvent = Events:WaitForChild('GetDescription')
- local CraftableItems = Storage:WaitForChild('CraftableItems')
- local UIS = game:GetService("UserInputService")
- local UI = script.Parent
- local MainFrame = UI:WaitForChild("MainFrame")
- local Open = false
- local ItemChosen = ""
- local Debounce = false
- local Items = MainFrame:WaitForChild('Items')
- local Template = script:WaitForChild("Template")
- local ItemInfo = MainFrame:WaitForChild('ItemInfo')
- local CraftItem = ItemInfo:WaitForChild('Craft')
- local StatsTemplate = script:WaitForChild("StatsTemplate")
- function displayInfo(name, description)
- ItemInfo.ItemName.Text = name
- ItemInfo.Description.Text = tostring(description)
- -- Add cost, etc later.
- end
- function updateLeaderstats()
- local Starter_Materials = DescEvent:InvokeServer("GetStarterMats")
- local CurrentYPos = 0.297
- for name,value in pairs(Starter_Materials) do
- warn(name, value)
- local Clone = StatsTemplate:Clone()
- Clone.Name = name
- Clone.Text = name.. ": "..value
- Clone.Position = UDim2.new(0.021,0,CurrentYPos+0.051,0)
- CurrentYPos = CurrentYPos + 0.051
- Clone.Parent = UI:WaitForChild("Stats")
- end
- end
- function update()
- ItemChosen = ""
- ItemInfo.ItemName.Text = "ItemName"
- ItemInfo.Description.Text = "Description of item."
- for _,v in pairs(Items:GetChildren()) do
- if v:IsA("TextButton") then
- v:Destroy()
- else
- warn"Could not destroy GridLayout."
- end
- end
- for _,v in pairs(CraftableItems:GetChildren()) do
- local Clone = Template:Clone()
- Clone.Parent = Items
- Clone.Text = v.Name
- Clone.Name = v.Name
- Clone.MouseButton1Click:Connect(function()
- displayInfo(Clone.Name, DescEvent:InvokeServer('Desc', Clone.Name))
- ItemChosen = Clone.Name
- end)
- end
- end
- CraftItem.MouseButton1Click:Connect(function()
- if ItemChosen == "" then warn"You have not selected an item." return end
- if Debounce then return end
- Event:FireServer('CraftItem', ItemChosen)
- Debounce = true
- wait(1.5)
- Debounce = false
- end)
- Event.OnClientEvent:Connect(function(action, bool)
- if action == 'Check' then
- DescEvent:InvokeServer('CraftingReturn', '', bool)
- end
- end)
- UIS.InputBegan:Connect(function(input, gpe)
- if gpe then return end
- if input.KeyCode == Enum.KeyCode.N then
- if Open == false then
- Open = true
- MainFrame:TweenSizeAndPosition(UDim2.new(0.363,0,0.425,0), UDim2.new(0.248,0,0.286,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, false)
- update()
- elseif Open == true then
- Open = false
- MainFrame:TweenSizeAndPosition(UDim2.new(0,0,0,0), UDim2.new(0.5,0,0.5,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, false)
- update()
- end
- end
- end)
- updateLeaderstats()
- for _,v in pairs(game.Players.LocalPlayer:WaitForChild('Materials'):GetChildren()) do
- v:GetPropertyChangedSignal('Value'):Connect(function()
- for i,value in pairs(UI:WaitForChild("Stats"):GetChildren()) do
- if value.Name == v.Name then
- value.Text = v.Name.. ": "..v.Value
- end
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement