Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CollectionService = game:GetService("CollectionService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local ServerStorage = game:GetService("ServerStorage")
- local Recipes = require(game:GetService("ReplicatedStorage").Modules.Recipes).Recipes
- local SmeltingRecipes = require(game:GetService("ReplicatedStorage").Modules.SmeltingRecipes).Recipes
- local InventoryHandler = require(ServerStorage.Modules.InventoryHandler)
- local ItemHandler = require(ServerStorage.Modules.ItemHandler)
- local MiningHandler = require(game:GetService("ServerStorage").Modules.MiningHandler)
- local HTTP = game:GetService("HttpService")
- local wires = {}
- ReplicatedStorage.Wiring.Wire.OnServerEvent:Connect(function(player_fired, Type, Input, Output, c, d)
- local wire
- if Type == "Wire" then
- if Input ~= nil and Output ~= nil then
- coroutine.wrap(function()
- local beam1 = Input:FindFirstChild("Beam")
- local beam2 = Output:FindFirstChild("Beam")
- if beam1 then
- if beam1.Attachment0 == Input and beam1.Attachment1 == Output then return end
- end
- if beam2 then
- if beam2.Attachment0 == Input and beam2.Attachment1 == Output then return end
- end
- if Input.Parent == Output.Parent then return end
- if not InventoryHandler.ItemExists(player_fired, "CoiledWire") then return end
- InventoryHandler.AddItem(player_fired, "CoiledWire", -1)
- wire = game:GetService("ReplicatedStorage").Wiring.Beam:Clone()
- wire.Parent = Output
- wire.Attachment0 = Input
- wire.Attachment1 = Output
- wire:SetAttribute("IsPowered", Output:GetAttribute("IsPowered"))
- Input:SetAttribute("IsPowered", Output:GetAttribute("IsPowered"))
- local owner = Instance.new("ObjectValue", wire)
- owner.Name = "WireOwner"
- owner.Value = player_fired
- table.insert(wires, wire)
- if wire:GetAttribute("IsPowered") then
- wire.Color = ColorSequence.new(Color3.fromRGB(0, 170, 255))
- else
- wire.Color = ColorSequence.new(Color3.fromRGB(0, 0, 0))
- end
- local connection = Output:GetAttributeChangedSignal("IsPowered"):Connect(function()
- local IsOutputPowered = Output:GetAttribute("IsPowered")
- wire:SetAttribute("IsPowered", IsOutputPowered)
- Input:SetAttribute("IsPowered", IsOutputPowered)
- if wire:GetAttribute("IsPowered") then
- wire.Color = ColorSequence.new(Color3.fromRGB(0, 170, 255))
- else
- wire.Color = ColorSequence.new(Color3.fromRGB(0, 0, 0))
- end
- end)
- while task.wait() do
- if wire.Parent == nil then
- connection:Disconnect()
- if Input:FindFirstChild("Beam") and Input.Beam:GetAttribute("IsPowered") then
- else
- Input:SetAttribute("IsPowered", false)
- end
- break
- else
- local mag = (wire.Attachment0.WorldPosition - wire.Attachment1.WorldPosition).magnitude
- if mag > 20 then
- local CoiledWireClonePosition
- if math.random(1,2) == 1 then
- CoiledWireClonePosition = wire.Attachment0.WorldPosition
- else
- CoiledWireClonePosition = wire.Attachment1.WorldPosition
- end
- if wire:FindFirstChild("WireOwner") then
- game:GetService("ReplicatedStorage").Wiring.Local:FireClient(wire.WireOwner.Value, "WireBroke_TooLong")
- end
- wire:Destroy()
- local CoiledWireClone = game:GetService("ReplicatedStorage").Items.Electric.CoiledWire:Clone()
- CoiledWireClone.Parent = workspace
- CoiledWireClone.Position = CoiledWireClonePosition
- CoiledWireClone.Anchored = false
- coroutine.wrap(function()
- task.wait(2)
- pcall(function()
- CoiledWireClone.Anchored = true
- end)
- end)
- end
- end
- end
- end)()
- end
- end
- end)
- ReplicatedStorage.Wiring.Delete.OnServerEvent:Connect(function(player_fired, Beam)
- if Beam:IsA("Beam") and Beam.Parent:IsA("Attachment") then
- local CoiledWireClonePosition
- if math.random(1,2) == 1 then
- CoiledWireClonePosition = Beam.Attachment0.WorldPosition
- else
- CoiledWireClonePosition = Beam.Attachment1.WorldPosition
- end
- Beam:Destroy()
- local wire = ReplicatedStorage.Items.Electric.CoiledWire:Clone()
- wire.Position = CoiledWireClonePosition
- wire.Parent = workspace.Drops
- --ItemHandler.SpawnItem("CoiledWire", CoiledWireClonePosition)
- end
- end)
- ReplicatedStorage.Drop.OnServerEvent:Connect(function(player_fired, item, count)
- if not count then
- count = 1
- end
- if not player_fired:GetAttribute("DropDebounce") then
- player_fired:SetAttribute("DropDebounce", true)
- local DecodedInventory = HTTP:JSONDecode(player_fired:GetAttribute("InventoryJSON"))
- if InventoryHandler.ItemCount(player_fired, item) >= count and count > 0 then
- InventoryHandler.DropItem(player_fired, item, count)
- end
- wait(0.1 * count)
- player_fired:SetAttribute("DropDebounce", false)
- end
- end)
- ReplicatedStorage.Equip.OnServerEvent:Connect(function(player_fired, item, count)
- if not count then
- count = 1
- end
- local ItemExample = game:GetService("ReplicatedStorage").Items:FindFirstChild(item, true)
- if ItemExample:IsA("Tool") then
- local DecodedInventory = HTTP:JSONDecode(player_fired:GetAttribute("InventoryJSON"))
- if InventoryHandler.ItemCount(player_fired, item) >= count and count > 0 then
- InventoryHandler.AddItem(player_fired, item, -count)
- local ItemClone = game:GetService("ReplicatedStorage").Items:FindFirstChild(item, true):Clone()
- ItemClone.Parent = player_fired.Backpack
- end
- end
- end)
- ReplicatedStorage.Craft.OnServerEvent:Connect(function(player_fired, item)
- local ItemCraft = Recipes[item].Items
- local AllowedToCraft = true
- for i,v in pairs(ItemCraft) do
- if InventoryHandler.ItemCount(player_fired, i) >= v then
- InventoryHandler.AddItem(player_fired, i, -v)
- else
- AllowedToCraft = false
- end
- end
- if AllowedToCraft then
- InventoryHandler.AddItem(player_fired, item, 1)
- end
- end)
- ReplicatedStorage.Mine.OnServerEvent:Connect(function(player_fired, ore)
- local ToolName = player_fired.Character:FindFirstChildWhichIsA("Tool").Name
- MiningHandler.DamageOre(ToolName, ore)
- end)
- ReplicatedStorage.Chop.OnServerEvent:Connect(function(player_fired, tree)
- local ToolName = player_fired.Character:FindFirstChildWhichIsA("Tool").Name
- MiningHandler.DamageTree(ToolName, tree)
- end)
- ReplicatedStorage.Smelt.OnServerEvent:Connect(function(player_fired, furnace, item)
- if furnace ~= nil then
- local Queue = HTTP:JSONDecode(furnace:GetAttribute("ItemQueue"))
- local CurrentlySmelting = furnace:GetAttribute("Smelting")
- local ItemCraft = SmeltingRecipes[item]
- local AllowedToCraft = true
- local SmeltSuccess = true
- for i,v in pairs(ItemCraft) do
- if InventoryHandler.ItemCount(player_fired, i) >= v then
- InventoryHandler.AddItem(player_fired, i, -v)
- else
- AllowedToCraft = false
- end
- end
- if AllowedToCraft then
- table.insert(Queue, item)
- end
- furnace:SetAttribute("ItemQueue", HTTP:JSONEncode(Queue))
- end
- end)
- ReplicatedStorage.FurnaceTake.OnServerEvent:Connect(function(player_fired, furnace)
- if furnace ~= nil then
- local ItemsInside = HTTP:JSONDecode(furnace:GetAttribute("ItemsInside"))
- for i,v in pairs(ItemsInside) do
- InventoryHandler.AddItem(player_fired, i, v)
- end
- furnace:SetAttribute("ItemsInside", "{}")
- end
- end)
Add Comment
Please, Sign In to add comment