Advertisement
BendyAndInk

Dummy

Aug 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1. --say thank you to bot :c
  2.  
  3. local HiveMind = {}
  4. function HiveMind:new(owner)
  5. self.__index = self
  6. local o = {mind = {}, mindState = "FOLLOW", victimObject = nil}
  7. o.owner = owner
  8. setmetatable(o, self)
  9. return o
  10. end
  11.  
  12. function HiveMind:add(model, humanoid, torso)
  13. if model and humanoid and torso then
  14. table.insert(self.mind, {model = model, humanoid = humanoid,
  15. torso = torso})
  16. local hiv = self
  17. local lastJump = 0
  18. torso.Touched:connect(function(object)
  19. local hive = false
  20. if hiv.owner.Character
  21. and object:IsDescendantOf(hiv.owner.Character) == false
  22. then
  23. for i = 1, #hiv.mind do
  24. if object:IsDescendantOf(hiv.mind[i].model) then
  25. hive = true
  26. break
  27. end
  28. end
  29. if not hive then
  30. local hum = object.Parent
  31. and object.Parent:FindFirstChild("Humanoid")
  32. if hum then
  33. hum:TakeDamage(5)
  34. end
  35. elseif time() - lastJump > 9 then
  36. lastJump = time() + math.random()*2
  37. humanoid.Jump = true
  38. end
  39. end
  40. end)
  41. end
  42. end
  43.  
  44. function HiveMind:cleanupHive()
  45. local i = 1
  46. while i <= #self.mind do
  47. if self.mind[i].model:IsDescendantOf(game) == false
  48. or self.mind[i].humanoid.Health == 0 then
  49. table.remove(self.mind, i)
  50. else
  51. i = i + 1
  52. end
  53. end
  54. end
  55.  
  56. function HiveMind:getOrbitNumberFromUnitNumber(i)
  57. local circleNumber = 0
  58. while self:getUnitsInOrbit(circleNumber) < i do
  59. i = i - self:getUnitsInOrbit(circleNumber)
  60. circleNumber = circleNumber + 1
  61. end
  62. return circleNumber, i
  63. end
  64.  
  65. function HiveMind:getOrbitDiameter(orbitNumber)
  66. return math.pi*(orbitNumber*14)
  67. end
  68.  
  69. function HiveMind:getUnitsInOrbit(orbitNumber)
  70. return math.floor(self:getOrbitDiameter(orbitNumber)/5)
  71. end
  72.  
  73. function HiveMind:circle(location)
  74. local timeOffset = time()*0.3
  75. for i = 1, #self.mind do
  76. local orbit, offset = self:getOrbitNumberFromUnitNumber(i)
  77. local units = self:getUnitsInOrbit(orbit)
  78. local angle = math.pi*2*(offset/units) + timeOffset
  79. local radius = orbit*7
  80. local pos = Vector3.new(math.sin(angle)*radius, 0,
  81. math.cos(angle)*radius)
  82. self.mind[i].humanoid:MoveTo(pos + location, workspace.Base)
  83. end
  84. end
  85.  
  86. function HiveMind:lineup(location)
  87. for i = 1, #self.mind do
  88. local row = (i - 1) % 3
  89. local column = math.floor((i - 1) / 3)
  90. local xOffset, yOffset
  91. if row == 0 then
  92. xOffset = -7
  93. elseif row == 1 then
  94. xOffset = 0
  95. else
  96. xOffset = 7
  97. end
  98. yOffset = column * 7
  99. local position = location * CFrame.new(xOffset, 0, yOffset)
  100. self.mind[i].humanoid:MoveTo(position.p, workspace.Base)
  101. end
  102. end
  103.  
  104. function HiveMind:crowdAttack()
  105. if self.victimObject and self.victimObject:IsDescendantOf(workspace) then
  106. local position = self.victimObject.Position
  107. for i = 1, #self.mind do
  108. if (self.mind[i].torso.Position - position).magnitude < 1
  109. and math.random() < 0.1 then
  110. self.mind[i].humanoid:MoveTo(position + Vector3.new(
  111. math.random(), math.random(), math.random()),
  112. workspace.Base)
  113. else
  114. self.mind[i].humanoid:MoveTo(position, workspace.Base)
  115. end
  116. end
  117. end
  118. end
  119.  
  120. function HiveMind:shield()
  121. local factor = math.pi*2/(#self.mind)
  122. local rad = math.max(#self.mind/9, 3)
  123. local angle = 0
  124. local torso = self.owner.Character
  125. and self.owner.Character:FindFirstChild("Torso")
  126. if not torso then
  127. return
  128. end
  129. local off = torso.Position
  130. for i = 1, #self.mind do
  131. self.mind[i].humanoid:MoveTo(Vector3.new(math.sin(angle)*14, 0,
  132. math.cos(angle)*14) + off, Workspace.Base)
  133. angle = angle + factor
  134. end
  135. end
  136.  
  137. function HiveMind:ownerTorso()
  138. return self.owner.Character
  139. and self.owner.Character:FindFirstChild("Torso")
  140. end
  141.  
  142. function HiveMind:pushToTarget()
  143. if self.victimObject and self:ownerTorso() then
  144. local victimPosition = self.victimObject.Position
  145. local ownerPosition = self:ownerTorso().Position
  146. for i = 1, #self.mind do
  147. local memberPosition = self.mind[i].torso.Position
  148. local differenceFromOwner = (ownerPosition - memberPosition)
  149. local directionToOwner = differenceFromOwner.unit
  150. local distanceToOwner = differenceFromOwner.magnitude
  151. local directionToVictim = (victimPosition - memberPosition).unit
  152. if directionToOwner:Dot(directionToVictim) > 0.95
  153. and distanceToOwner < 19 then
  154. self.mind[i].humanoid:MoveTo(victimPosition, workspace.Base)
  155. else
  156. local ownerVictimDiff = (ownerPosition - victimPosition)
  157. local ownerVictimDist = ownerVictimDiff.magnitude
  158. local properLocation = ownerVictimDiff.unit
  159. *(ownerVictimDist + 7) + victimPosition
  160. local ang = math.atan2(ownerVictimDiff.z, ownerVictimDiff.x)
  161. if directionToOwner:Dot(directionToVictim) < 0.4 then
  162. if i % 2 == 0 then
  163. ang = ang + math.pi/2
  164. else
  165. ang = ang - math.pi/2
  166. end
  167. local sideOff = Vector3.new(math.cos(ang)*18, 0,
  168. math.sin(ang)*18)
  169. properLocation = properLocation + sideOff
  170. end
  171. self.mind[i].humanoid:MoveTo(properLocation, workspace.Base)
  172. end
  173. end
  174. end
  175. end
  176.  
  177. function HiveMind:update()
  178. self:cleanupHive()
  179. if self.owner.Character then
  180. local ownerTorso = self.owner.Character:FindFirstChild("Torso")
  181. if ownerTorso then
  182. if (self.mindState == "FOLLOW") then
  183. local hiveSpawn = ownerTorso.CFrame * CFrame.new(0, 0, 9)
  184. self:lineup(hiveSpawn)
  185. elseif (self.mindState == "CIRCLE") then
  186. self:circle(ownerTorso.Position)
  187. elseif (self.mindState == "ATTACK") then
  188. self:crowdAttack()
  189. elseif (self.mindState == "SHIELD") then
  190. self:shield()
  191. elseif (self.mindState == "GOTO") then
  192. self:pushToTarget()
  193. end
  194. end
  195. end
  196. end
  197.  
  198. -------------------------------------------------------------------------------
  199.  
  200. local me = game:GetService("Players").PPATTA
  201. local hiveMind = HiveMind:new(me)
  202.  
  203. me.Chatted:connect(function(msg)
  204. if msg:lower():find("circle") == 1 then
  205. hiveMind.mindState = "CIRCLE"
  206. elseif msg:lower():find("follow") == 1 then
  207. hiveMind.mindState = "FOLLOW"
  208. elseif msg:lower():find("attack") == 1 then
  209. for i, v in ipairs(game:GetService("Players"):GetPlayers()) do
  210. if v.Name:lower():find(msg:sub(8):lower()) == 1 then
  211. hiveMind.victimObject = v.Character.Torso
  212. hiveMind.mindState = "ATTACK"
  213. break
  214. end
  215. end
  216. elseif msg:lower():find("goto") == 1 then
  217. for i, v in ipairs(game:GetService("Players"):GetPlayers()) do
  218. if v.Name:lower():find(msg:sub(6):lower()) == 1 then
  219. hiveMind.victimObject = v.Character.Torso
  220. hiveMind.mindState = "GOTO"
  221. break
  222. end
  223. end
  224. elseif msg:lower():find("hive") == 1 then
  225. for i, v in ipairs(game:GetService("Players"):GetPlayers()) do
  226. if v.Name:lower():find(msg:sub(6):lower()) == 1
  227. and v ~= hiveMind.owner then
  228. if v.Character and v.Character:FindFirstChild("Torso")
  229. and v.Character:FindFirstChild("Humanoid") then
  230. hiveMind:add(v.Character, v.Character.Humanoid,
  231. v.Character.Torso)
  232. end
  233. end
  234. end
  235. elseif msg:lower():find("shield") == 1 then
  236. hiveMind.mindState = "SHIELD"
  237. end
  238. end)
  239.  
  240. workspace.ChildAdded:connect(function(object)
  241. if object.Name == "Dummy" then
  242. hiveMind:add(object, object:WaitForChild("Humanoid"),
  243. object:WaitForChild("Torso"))
  244. end
  245. end)
  246.  
  247. game:GetService("RunService").Stepped:connect(function()
  248. hiveMind:update()
  249. end)
  250. --[[
  251. g/dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum dum
  252. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement