LawMixer

inventory code

Jun 16th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. local Snapdragon = require(game.ReplicatedStorage:WaitForChild("Snapdragon"))
  2.  
  3. local LocalPlayer = game:GetService("Players").LocalPlayer
  4. local storeTbl = {
  5. true, true, true, true,
  6. true, true, true, true
  7. }
  8.  
  9. local lastClosest = nil
  10.  
  11. local function whichSlotisClosest(itemAbsolutePos)
  12. local objects = script.Parent.Slots:GetChildren()
  13. local minObj, min = objects[1], (objects[1].AbsolutePosition - itemAbsolutePos).Magnitude
  14.  
  15. for i, v in pairs(objects) do
  16. if min > (v.AbsolutePosition - itemAbsolutePos).Magnitude then
  17. min = (v.AbsolutePosition - itemAbsolutePos).Magnitude
  18. minObj = v
  19. end
  20. end
  21.  
  22. return minObj
  23. end
  24.  
  25. local function areFramesOverlapping(myImageLabel)
  26. local guisDetectedAtPosition = LocalPlayer:WaitForChild("PlayerGui"):GetGuiObjectsAtPosition(myImageLabel.AbsolutePosition.X, myImageLabel.AbsolutePosition.Y)
  27.  
  28. for _, v in pairs(guisDetectedAtPosition) do
  29. if v:IsA("GuiObject") and string.find(v.Name, "ItemPlaceholder") then
  30. return true
  31. end
  32. end
  33.  
  34. return false
  35. end
  36.  
  37. local controller = Snapdragon.createDragController(script.Parent.ItemPlaceholder2)
  38. controller:Connect()
  39.  
  40. controller.DragEnded:Connect(function(callback)
  41. print(callback)
  42. local closestObj = whichSlotisClosest(controller.gui.AbsolutePosition)
  43.  
  44. local overlappingUIs = areFramesOverlapping(controller.gui)
  45.  
  46. if overlappingUIs ~= true and storeTbl[closestObj.Name] ~= false then
  47. controller.gui.Position = closestObj.Position
  48. if lastClosest ~= nil then
  49. storeTbl[lastClosest] = true
  50. end
  51.  
  52. storeTbl[closestObj.Name] = false
  53. lastClosest = closestObj.Name
  54. end
  55. end)
  56.  
  57. local controller2 = Snapdragon.createDragController(script.Parent.ItemPlaceholder)
  58. controller2:Connect()
  59.  
  60. controller2.DragEnded:Connect(function(callback)
  61. local closestObj = whichSlotisClosest(controller2.gui.AbsolutePosition)
  62. local overlappingUIs = areFramesOverlapping(controller2.gui)
  63.  
  64. if overlappingUIs ~= true then
  65. controller2.gui.Position = closestObj.Position
  66. if lastClosest ~= nil then
  67. storeTbl[lastClosest] = true
  68. end
  69.  
  70. storeTbl[closestObj.Name] = false
  71. lastClosest = closestObj.Name
  72. end
  73. end)
Add Comment
Please, Sign In to add comment