Advertisement
drakon-firestone

PatsClient

Apr 1st, 2023
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local runService = game:GetService("RunService")
  2.  
  3. local playersFolder = workspace:WaitForChild("Players")
  4.  
  5. local petsPerRow = 5
  6.  
  7. -- odstępy - X - między kolumnami a Z między rzędami
  8. local offsetX = 4
  9. local offsetZ = 5
  10. local offsetPlayer = 6
  11.  
  12. local function positionPets(character, playerFolder, deltaTime, sin,cos)
  13.    
  14.     local petCount = #playerFolder:GetChildren()
  15.     local rows = math.ceil(petCount / petsPerRow)
  16.    
  17.     for i,pet in pairs(playerFolder:GetChildren()) do
  18.        
  19.         local row = math.floor((i-1) / petsPerRow)
  20.         local col = (i-1) % petsPerRow
  21.        
  22.         local characterSize = character:GetExtentsSize()
  23.         local petSize = pet:GetExtentsSize()
  24.        
  25.         -- ustawiamy ile petów jest w rzędzie tego peta
  26.         local petsInRow = math.min(petCount - row*petsPerRow, petsPerRow)
  27.        
  28.         local x = (col - petsInRow/2 + 0.5) * offsetX
  29.         local y = petSize.Y/2 - characterSize.Y/2
  30.         local z = (row * offsetZ) + offsetPlayer
  31.        
  32.         if character.Humanoid.MoveDirection.Magnitude > 0 then
  33.             -- gracz porusza się
  34.             if pet:FindFirstChild("Walks") then
  35.                 -- pet chodzi
  36.                 -- gracz porusza sie a pet chodzi
  37.                 pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  38.                     character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1))
  39.             elseif pet:FindFirstChild("Flying") then
  40.                 -- pet lata
  41.                 pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  42.                     character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1))
  43.             end
  44.            
  45.         else
  46.             -- gracz nie porusza się  
  47.             if pet:FindFirstChild("Walks") then
  48.                 -- pet chodzi
  49.                 pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  50.                     character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1))
  51.             elseif pet:FindFirstChild("Flying") then
  52.                 -- pet lata
  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.         end
  57.     end
  58. end
  59.  
  60.  
  61. runService.RenderStepped:Connect(function(deltaTime)
  62.     local sin = (math.sin(15 * time() + 1.6)/.5)+1
  63.     local cos = math.cos(7 * time() + 1) / 4
  64.     for i, playerFolder in pairs(playersFolder:GetChildren()) do
  65.         local player = game.Players:FindFirstChild(playerFolder.Name)
  66.         if player ~= nil then
  67.             local character = player.Character or nil
  68.             if character ~= nil then
  69.                 positionPets(character, playerFolder, deltaTime, sin, cos)
  70.             end
  71.         end
  72.     end
  73. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement