Advertisement
Chxp

Untitled

Jul 30th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. --[[
  2. Snake script by popinman322
  3. --]]
  4.  
  5. local Players = game:GetService("Players")
  6. local LocalPlayer = Players.LocalPlayer
  7.  
  8. local PlayerBackpack = LocalPlayer.Backpack
  9.  
  10. local ToolName = "[ Snake ]"
  11. local HopperProps = {
  12. Name = ToolName;
  13. Parent = PlayerBackpack;
  14. }
  15.  
  16. local function new(Class, Parent, Props)
  17. local Inst = Instance.new(Class, Parent)
  18. if Props["FormFactor"] then
  19. Inst["FormFactor"] = Props["FormFactor"]
  20. end
  21. for Prop, Val in pairs(Props) do
  22. Inst[Prop] = Val
  23. end
  24. return Inst
  25. end
  26.  
  27. -- Snake creation and manipulation
  28.  
  29. local NumLinks = 20
  30.  
  31. local Step = CFrame.new(0,0,0.1)
  32. local Steps = {}
  33. local MaxSteps = NumLinks + 1
  34.  
  35. local function RecordStep(Step)
  36. local Out = {}
  37. for i=1, #Steps do
  38. Out[i+1] = Steps[i]
  39. end
  40. Out[#Steps] = nil
  41. Out[1] = Step
  42. Steps = Out
  43. end
  44.  
  45. local function GetStep(Index)
  46. if Steps[Index] == nil then
  47. return Steps[#Steps]
  48. end
  49. return Steps[Index]
  50. end
  51.  
  52. local Snake = new("Model", LocalPlayer.Character,
  53. {
  54. Name = "Snake"
  55. });
  56.  
  57. local Head = new("Seat", Snake,
  58. {
  59. Name = "Head";
  60. FormFactor = "Custom";
  61. BrickColor = BrickColor.Red;
  62. Reflectance = 0.7;
  63. Transparency = 0.25;
  64. Shape = Enum.PartType.Ball;
  65. Size = Vector3.new(5,5,5);
  66. Anchored = true;
  67. TopSurface = "Smooth";
  68. BottomSurface = "Smooth";
  69. });
  70.  
  71. local Links = {}
  72.  
  73. local function NewLink()
  74. return new("Part", Snake, {
  75. Name = "Link";
  76. BrickColor = BrickColor.Blue;
  77. Reflectance = 0.5;
  78. Transparency = 0.4;
  79. FormFactor = "Custom";
  80. Size = Vector3.new(3,3,3);
  81. Anchored = true;
  82. TopSurface = "Smooth";
  83. BottomSurface = "Smooth";
  84. })
  85. end
  86.  
  87. for i=1, NumLinks do
  88. table.insert(Links, NewLink())
  89. end
  90.  
  91. -- Mouse events
  92.  
  93. local IsDown = false
  94.  
  95. local function OnMouseMoved(Mouse)
  96. if IsDown then
  97. RecordStep(CFrame.new(Head.Position, Mouse.Hit.p) * Step)
  98. end
  99.  
  100. Head.CFrame = GetStep(1)
  101. for i=2, NumLinks+1 do
  102. Links[i-1].CFrame = GetStep(i)
  103. end
  104. end
  105.  
  106. local function OnMouseDown()
  107. IsDown = true
  108. end
  109.  
  110. local function OnMouseUp()
  111. IsDown = false
  112. end
  113.  
  114. local function KeyDown(Mouse, Key)
  115.  
  116. end
  117.  
  118. local function KeyUp(Mouse, Key)
  119.  
  120. end
  121.  
  122. -- Tool creation and management
  123.  
  124. local Hop;
  125.  
  126. if not script then -- We're being loadstring'd
  127. Hop = new("HopperBin", PlayerBackpack, HopperProps)
  128. end
  129.  
  130. if not script.Parent:IsA("HopperBin") then
  131. Hop = new("HopperBin", PlayerBackpack, HopperProps)
  132.  
  133. local Scr = script:Clone()
  134. Scr.Parent = Hop
  135.  
  136. script:Destroy()
  137. else
  138. if not Hop then
  139. Hop = script.Parent
  140. end
  141.  
  142. Hop.Selected:connect(function(Mouse)
  143. Mouse.Button1Down:connect(OnMouseDown)
  144. Mouse.Button1Up:connect(OnMouseUp)
  145.  
  146. -- Mouse.Idle and Mouse.Move fire in a continuous loop
  147. Mouse.Move:connect(function()
  148. OnMouseMoved(Mouse)
  149. end)
  150. Mouse.Idle:connect(function()
  151. OnMouseMoved(Mouse)
  152. end)
  153.  
  154. Mouse.KeyDown:connect(function(Key)
  155. KeyDown(Mouse, Key)
  156. end)
  157. Mouse.KeyUp:connect(function(Key)
  158. KeyUp(Mouse, Key)
  159. end)
  160. end)
  161. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement