Advertisement
HowToRoblox

PetClient

Mar 9th, 2023
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.88 KB | None | 0 0
  1. local rs = game:GetService("ReplicatedStorage")
  2. local pets = rs:WaitForChild("Pets")
  3. local remotes = rs:WaitForChild("RemoteEvents")
  4. local config = require(rs:WaitForChild("CONFIGURATION"))
  5.  
  6. local plr = game.Players.LocalPlayer
  7.  
  8. local mouse = plr:GetMouse()
  9.  
  10. local char = plr.Character
  11. local equipped = char:WaitForChild("EQUIPPED PETS")
  12.  
  13.  
  14. --Moving Pets
  15. local maxAngle = 120
  16.  
  17. game:GetService("RunService").Heartbeat:Connect(function()
  18.    
  19.     if char and char.Humanoid.Health > 0 then
  20.  
  21.         local numPets = #char["EQUIPPED PETS"]:GetChildren()
  22.         local degreesIncrement = maxAngle / (numPets-1)
  23.  
  24.         for petNum, pet in pairs(char["EQUIPPED PETS"]:GetChildren()) do
  25.  
  26.             local deg = (petNum-1)*degreesIncrement - 90 + (180-maxAngle)/2
  27.             if numPets == 1 then
  28.                 deg = 0
  29.             end
  30.  
  31.             local goalCF = char:FindFirstChild("UpperTorso") and char.UpperTorso.CFrame or char:FindFirstChild("Torso") and char.Torso.CFrame or char.HumanoidRootPart.CFrame
  32.             goalCF = goalCF * CFrame.Angles(0, math.rad(deg), 0)
  33.             goalCF = (goalCF - goalCF.LookVector * 8)
  34.             goalCF = goalCF * CFrame.Angles(0, -math.rad(deg), 0)
  35.  
  36.             pet.PrimaryPart.AlignPosition.Position = goalCF.Position
  37.             pet.PrimaryPart.AlignOrientation.CFrame = goalCF
  38.         end
  39.     end
  40. end)
  41.  
  42.  
  43. --Inventory Gui
  44. local petsInventory = plr:WaitForChild("PetsInventory")
  45. local petsEquipped = plr:WaitForChild("PetsEquipped")
  46.  
  47. local invGui = script.Parent:WaitForChild("PetInventoryGui");invGui.Enabled = true
  48. local invFrame = invGui:WaitForChild("PetInventory");invFrame.Visible = false
  49. local inventoryFrame = invFrame:WaitForChild("InventoryFrame")
  50. local selectFrame = inventoryFrame:WaitForChild("SelectedPetFrame");selectFrame.Visible = false
  51. local equippedFrame = invFrame:WaitForChild("EquippedFrame")
  52. local closeInvButton = invFrame:WaitForChild("CloseButton")
  53. local openInvBtn = invGui:WaitForChild("OpenButton")
  54.  
  55. function setupPetFrame(petFrame:Frame, pet:Model)
  56.     petFrame.PetImage:ClearAllChildren()
  57.    
  58.     petFrame.PetName.Text = pet.Name
  59.     petFrame.PetName.TextColor3 = config.RarityColor[pet.Parent.Name]
  60.    
  61.     local petModel = pet:Clone()
  62.     petModel:PivotTo(CFrame.new())
  63.     petModel.Parent = petFrame.PetImage
  64.    
  65.     local vpfCamera = Instance.new("Camera")
  66.     vpfCamera.CFrame = CFrame.new(petModel:GetExtentsSize()*Vector3.new(0.6, -0.2, -2.1), Vector3.new(-0.25, 0, 0))--0.6, -0.2, -0.9
  67.     petFrame.PetImage.CurrentCamera = vpfCamera
  68.     vpfCamera.Parent = petFrame.PetImage
  69.    
  70.     petFrame.PetName.Visible = true
  71.     petFrame.PetImage.Visible = true   
  72. end
  73.  
  74. function createEquippedFrames()
  75.    
  76.     local equippedValues = petsEquipped:GetChildren()
  77.     table.sort(equippedValues, function(a, b)
  78.         return tonumber(a.Name) < tonumber(b.Name)
  79.     end)
  80.    
  81.     for _, equippedValue in pairs(equippedValues) do
  82.         local newFrame = script:WaitForChild("PetFrameEquipped"):Clone()
  83.        
  84.         if not equippedValue.Value then
  85.             newFrame.PetName.Visible = false
  86.             newFrame.PetImage.Visible = false
  87.            
  88.         else
  89.             setupPetFrame(newFrame, equippedValue.Value)
  90.         end
  91.        
  92.         equippedValue:GetPropertyChangedSignal("Value"):Connect(function()
  93.             if equippedValue.Value then
  94.                 setupPetFrame(newFrame, equippedValue.Value)
  95.             else
  96.                 newFrame.PetName.Visible = false
  97.                 newFrame.PetImage.Visible = false
  98.             end
  99.         end)
  100.        
  101.         newFrame.MouseButton1Click:Connect(function()
  102.             if equippedValue.Value then
  103.                 selectFrame.Visible = false
  104.                 remotes:WaitForChild("UnequipPet"):FireServer(equippedValue.Name)
  105.             end
  106.         end)
  107.        
  108.         newFrame.Parent = equippedFrame.PetsContainer
  109.     end
  110. end
  111.  
  112. function updateInv()
  113.    
  114.     local petFrames = {}
  115.    
  116.     for _, pet in pairs(petsInventory:GetChildren()) do
  117.         local newFrame = script.PetFrameInventory:Clone()
  118.        
  119.         newFrame.MouseButton1Click:Connect(function()
  120.             selectFrame.PetName.Text = pet.Value.Name
  121.             selectFrame.AnchorPoint = Vector2.new(0, 0)
  122.             selectFrame.Position = UDim2.new(0, mouse.X - selectFrame.Parent.AbsolutePosition.X, 0, mouse.Y - selectFrame.Parent.AbsolutePosition.Y)
  123.             selectFrame.Visible = true
  124.         end)
  125.        
  126.         setupPetFrame(newFrame, pet.Value)
  127.        
  128.         table.insert(petFrames, {newFrame, pet.Value})
  129.     end
  130.    
  131.     table.sort(petFrames, function(a, b)
  132.         return
  133.             table.find(config.RarityOrder, a[2].Parent.Name) > table.find(config.RarityOrder, b[2].Parent.Name)
  134.             or table.find(config.RarityOrder, a[2].Parent.Name) == table.find(config.RarityOrder, b[2].Parent.Name)
  135.             and a[2].Name < b[2].Name
  136.     end)
  137.    
  138.     for _, child in pairs(inventoryFrame.PetsContainer:GetChildren()) do
  139.         if child.ClassName == script:WaitForChild("PetFrameInventory").ClassName then
  140.             child:Destroy()
  141.         end
  142.     end
  143.    
  144.     for _, petFrame in pairs(petFrames) do
  145.         petFrame[1].Parent = inventoryFrame.PetsContainer
  146.     end
  147. end
  148.  
  149. openInvBtn.MouseButton1Click:Connect(function()
  150.     invFrame.Visible = not invFrame.Visible
  151. end)
  152. closeInvButton.MouseButton1Click:Connect(function()
  153.     invFrame.Visible = false
  154. end)
  155.  
  156. selectFrame.EquipButton.MouseButton1Click:Connect(function()
  157.     remotes.EquipPet:FireServer(selectFrame.PetName.Text)
  158.     selectFrame.Visible = false
  159. end)
  160. selectFrame.DeleteButton.MouseButton1Click:Connect(function()
  161.     remotes.DeletePet:FireServer(selectFrame.PetName.Text)
  162.     selectFrame.Visible = false
  163. end)
  164.  
  165. mouse.Button1Up:Connect(function()
  166.     selectFrame.Visible = false
  167. end)
  168.  
  169. createEquippedFrames()
  170. updateInv()
  171.  
  172. petsInventory.ChildAdded:Connect(updateInv)
  173. petsInventory.ChildRemoved:Connect(updateInv)
  174.  
  175.  
  176. --Viewing Incubator
  177. local incubatorGui = script.Parent:WaitForChild("PetIncubatorGui");incubatorGui.Enabled = false
  178. local incubatorFrame = incubatorGui:WaitForChild("PetIncubator");incubatorFrame.Visible = false
  179. local incubatorCloseBtn = incubatorFrame:WaitForChild("CloseButton")
  180. local incubatorBuyBtn = incubatorFrame:WaitForChild("BuyButton")
  181.  
  182. local currentIncubator = nil
  183.  
  184. incubatorCloseBtn.MouseButton1Click:Connect(function()
  185.     incubatorFrame.Visible = false
  186.     currentIncubator = nil
  187. end)
  188.  
  189. incubatorBuyBtn.MouseButton1Click:Connect(function()
  190.     if currentIncubator then
  191.         remotes:WaitForChild("HatchPet"):FireServer(currentIncubator)
  192.     end
  193. end)
  194.  
  195. remotes:WaitForChild("ViewIncubator").OnClientEvent:Connect(function(incubator)
  196.    
  197.     currentIncubator = incubator
  198.    
  199.     incubatorFrame.IncubatorName.Text = incubator.Name
  200.  
  201.     local incubatorConfig = require(incubator.Configuration)
  202.     local hatchablePets = incubatorConfig.HatchablePets
  203.    
  204.     local petFrames = {}
  205.    
  206.     for _, pet in pairs(hatchablePets) do
  207.         local foundPet = pets:FindFirstChild(pet, true)
  208.         if foundPet then
  209.            
  210.             local newFrame = script.PetFrameIncubator:Clone()
  211.  
  212.             setupPetFrame(newFrame, foundPet)
  213.  
  214.             table.insert(petFrames, {newFrame, foundPet})
  215.         end
  216.     end
  217.  
  218.     table.sort(petFrames, function(a, b)
  219.         return
  220.             table.find(config.RarityOrder, a[2].Parent.Name) > table.find(config.RarityOrder, b[2].Parent.Name)
  221.             or table.find(config.RarityOrder, a[2].Parent.Name) == table.find(config.RarityOrder, b[2].Parent.Name)
  222.             and a[2].Name < b[2].Name
  223.     end)
  224.  
  225.     for _, child in pairs(incubatorFrame.PetsContainer:GetChildren()) do
  226.         if child.ClassName == script.PetFrameIncubator.ClassName then
  227.             child:Destroy()
  228.         end
  229.     end
  230.  
  231.     for _, petFrame in pairs(petFrames) do
  232.         petFrame[1].Parent = incubatorFrame.PetsContainer
  233.     end
  234.    
  235.     local rarities = {}
  236.     for rarityName, chance in pairs(incubatorConfig.Chances) do
  237.         table.insert(rarities, {rarityName, chance})
  238.     end
  239.     table.sort(rarities, function(a, b)
  240.         return table.find(config.RarityOrder, a[1]) < table.find(config.RarityOrder, b[1])
  241.     end)
  242.    
  243.     local raritiesText = " "
  244.     for _, rarity in pairs(rarities) do
  245.         local color = config.RarityColor[rarity[1]]
  246.         color = {R = math.round(color.R*255); G = math.round(color.G*255); B = math.round(color.B*255)}
  247.         raritiesText = raritiesText .. '<font color="rgb(' .. color.R .. ',' .. color.G .. ',' .. color.B .. ')">' .. rarity[1] .. ': <b>' .. rarity[2] .. '%</b></font><br />'
  248.     end
  249.     incubatorFrame.RaritiesText.RichText = true
  250.     incubatorFrame.RaritiesText.Text = raritiesText
  251.    
  252.     incubatorFrame.BuyButton.TextLabel.Text = "$" .. incubatorConfig.Price
  253.     if incubatorFrame.BuyButton.TextLabel:FindFirstChild("Shadow") then
  254.         incubatorFrame.BuyButton.TextLabel.Shadow.Text = "$" .. incubatorConfig.Price
  255.     end
  256.    
  257.     incubatorFrame.Visible = true
  258.     incubatorGui.Enabled = true
  259. end)
  260.  
  261.  
  262. --Pet Hatched
  263. local hatchedGui = script.Parent:WaitForChild("PetHatchedGui");hatchedGui.Enabled = false
  264. local hatchedFrame = hatchedGui:WaitForChild("PetHatched");hatchedFrame.Visible = false
  265. local continueButton = hatchedFrame:WaitForChild("ContinueButton")
  266.  
  267. continueButton.MouseButton1Click:Connect(function()
  268.     hatchedFrame.Visible = false
  269.     hatchedGui.Enabled = false
  270. end)
  271.  
  272. remotes:WaitForChild("HatchPet").OnClientEvent:Connect(function(petName)
  273.    
  274.     local foundPet = pets:FindFirstChild(petName, true)
  275.    
  276.     if foundPet then
  277.         setupPetFrame(hatchedFrame:WaitForChild("PetFrame"), foundPet)
  278.        
  279.         incubatorFrame.Visible = false
  280.         incubatorGui.Enabled = false
  281.         hatchedFrame.Visible = true
  282.         hatchedGui.Enabled = true
  283.     end
  284. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement