giganciprogramowania

lekcja 5 PetsClient

Mar 16th, 2023 (edited)
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. local runService = game:GetService("RunService")
  2.  
  3.  
  4. local playersFolder = workspace:WaitForChild("Players")
  5.  
  6.  
  7. local petsPerRow = 5
  8.  
  9.  
  10. local offsetX = 4
  11. local offsetZ = 5
  12. local offsetPlayer = 6
  13.  
  14.  
  15.  
  16.  
  17. local function positionPets(character, playerFolder, deltaTime, sin, cos)
  18. local petCount = #playerFolder:GetChildren()
  19. local rows = math.ceil(petCount / petsPerRow)
  20.  
  21.  
  22.  
  23.  
  24. for i, pet in pairs(playerFolder:GetChildren()) do
  25. local row = math.floor( (i - 1) / petsPerRow)
  26. local col = (i - 1) % petsPerRow
  27.  
  28.  
  29. local characterSize = character:GetExtentsSize()
  30. local petSize = pet:GetExtentsSize()
  31. local petsInRow = math.min(petCount - row * petsPerRow, petsPerRow)
  32.  
  33.  
  34. local x = (col - petsInRow/2 + 0.5) * offsetX
  35. local y = petSize.Y/2 - characterSize.Y/2
  36. local z = (row * offsetZ) + offsetPlayer
  37.  
  38.  
  39. if pet:FindFirstChild("Attack").Value ~= nil then
  40. local position = (pet:FindFirstChild("Attack").Value.CFrame * CFrame.new(x, 0, z)).p
  41. local lookAt = pet:FindFirstChild("Attack").Value.Position
  42. if pet:FindFirstChild("Walks") then
  43. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) * CFrame.new(0, 1 + sin, 0) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1))
  44. else
  45. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) * CFrame.new(0, 3 + math.sin(time()*7)/2, 0) * CFrame.fromEulerAnglesXYZ(cos,0,0) ,0.1))
  46. end
  47. else
  48. if character.Humanoid.MoveDirection.Magnitude > 0 then
  49. if pet:FindFirstChild("Walks") then
  50. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  51. character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1))
  52. elseif pet:FindFirstChild("Flying") then
  53. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  54. character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1))
  55. end
  56. else
  57. if pet:FindFirstChild("Walks") then
  58. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  59. character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1))
  60. elseif pet:FindFirstChild("Flying") then
  61. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  62. character.PrimaryPart.CFrame * CFrame.new(x, y / 2 + math.sin(time()*3)+1, z) , 0.1))
  63. end
  64. end
  65. end
  66. end
  67. end
  68.  
  69.  
  70.  
  71.  
  72. runService.RenderStepped:Connect(function(deltaTime)
  73. local sin = (math.sin(15 * time() + 1.6)/.5)+1
  74. local cos = math.cos(7 * time() + 1) / 4
  75.  
  76.  
  77.  
  78.  
  79. for i, playerFolder in pairs(playersFolder:GetChildren()) do
  80. local player = game.Players:FindFirstChild(playerFolder.Name)
  81. if player ~= nil then
  82. local character = player.Character or nil
  83. if character ~= nil then
  84. positionPets(character, playerFolder, deltaTime, sin, cos)
  85. end
  86. end
  87. end
  88. end)
  89.  
Add Comment
Please, Sign In to add comment