Advertisement
waconline

zombies

Feb 11th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.88 KB | None | 0 0
  1. --https://github.com/Mokiros/roblox-FE-compatibility
  2. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  3. local Player,game,owner = owner,game
  4. local RealPlayer = Player
  5. do
  6. print("FE Compatibility code V2 by Mokiros")
  7. local RealPlayer = RealPlayer
  8. script.Parent = RealPlayer.Character
  9.  
  10. --Fake event to make stuff like Mouse.KeyDown work
  11. local Disconnect_Function = function(this)
  12. this[1].Functions[this[2]] = nil
  13. end
  14. local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  15. local FakeEvent_Metatable = {__index={
  16. Connect = function(this,f)
  17. local i = tostring(math.random(0,10000))
  18. while this.Functions[i] do
  19. i = tostring(math.random(0,10000))
  20. end
  21. this.Functions[i] = f
  22. return setmetatable({this,i},Disconnect_Metatable)
  23. end
  24. }}
  25. FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  26. local function fakeEvent()
  27. return setmetatable({Functions={}},FakeEvent_Metatable)
  28. end
  29.  
  30. --Creating fake input objects with fake variables
  31. local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  32. FakeMouse.keyUp = FakeMouse.KeyUp
  33. FakeMouse.keyDown = FakeMouse.KeyDown
  34. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  35. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  36. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  37. end}
  38. --Merged 2 functions into one by checking amount of arguments
  39. CAS.UnbindAction = CAS.BindAction
  40.  
  41. --This function will trigger the events that have been :Connect()'ed
  42. local function TriggerEvent(self,ev,...)
  43. for _,f in pairs(self[ev].Functions) do
  44. f(...)
  45. end
  46. end
  47. FakeMouse.TriggerEvent = TriggerEvent
  48. UIS.TriggerEvent = TriggerEvent
  49.  
  50. --Client communication
  51. local Event = Instance.new("RemoteEvent")
  52. Event.Name = "UserInput_Event"
  53. Event.OnServerEvent:Connect(function(plr,io)
  54. if plr~=RealPlayer then return end
  55. FakeMouse.Target = io.Target
  56. FakeMouse.Hit = io.Hit
  57. if not io.isMouse then
  58. local b = io.UserInputState == Enum.UserInputState.Begin
  59. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  60. return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  61. end
  62. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  63. return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  64. end
  65. for _,t in pairs(CAS.Actions) do
  66. for _,k in pairs(t.Keys) do
  67. if k==io.KeyCode then
  68. t.Function(t.Name,io.UserInputState,io)
  69. end
  70. end
  71. end
  72. FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  73. UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  74. end
  75. end)
  76. Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
  77. local Mouse = owner:GetMouse()
  78. local UIS = game:GetService("UserInputService")
  79. local input = function(io,RobloxHandled)
  80. if RobloxHandled then return end
  81. --Since InputObject is a client-side instance, we create and pass table instead
  82. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  83. end
  84. UIS.InputBegan:Connect(input)
  85. UIS.InputEnded:Connect(input)
  86.  
  87. local h,t
  88. --Give the server mouse data every second frame, but only if the values changed
  89. --If player is not moving their mouse, client won't fire events
  90. local HB = game:GetService("RunService").Heartbeat
  91. while true do
  92. if h~=Mouse.Hit or t~=Mouse.Target then
  93. h,t=Mouse.Hit,Mouse.Target
  94. Event:FireServer({isMouse=true,Target=t,Hit=h})
  95. end
  96. --Wait 2 frames
  97. for i=1,2 do
  98. HB:Wait()
  99. end
  100. end]==],script)
  101.  
  102. ----Sandboxed game object that allows the usage of client-side methods and services
  103. --Real game object
  104. local RealGame = game
  105.  
  106. --Metatable for fake service
  107. local FakeService_Metatable = {
  108. __index = function(self,k)
  109. local s = rawget(self,"_RealService")
  110. if s then
  111. return typeof(s[k])=="function"
  112. and function(_,...)return s[k](s,...)end or s[k]
  113. end
  114. end,
  115. __newindex = function(self,k,v)
  116. local s = rawget(self,"_RealService")
  117. if s then s[k]=v end
  118. end
  119. }
  120. local function FakeService(t,RealService)
  121. t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
  122. return setmetatable(t,FakeService_Metatable)
  123. end
  124.  
  125. --Fake game object
  126. local FakeGame = {
  127. GetService = function(self,s)
  128. return rawget(self,s) or RealGame:GetService(s)
  129. end,
  130. Players = FakeService({
  131. LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
  132. },"Players"),
  133. UserInputService = FakeService(UIS,"UserInputService"),
  134. ContextActionService = FakeService(CAS,"ContextActionService"),
  135. RunService = FakeService({
  136. _btrs = {},
  137. RenderStepped = RealGame:GetService("RunService").Heartbeat,
  138. BindToRenderStep = function(self,name,_,fun)
  139. self._btrs[name] = self.Heartbeat:Connect(fun)
  140. end,
  141. UnbindFromRenderStep = function(self,name)
  142. self._btrs[name]:Disconnect()
  143. end,
  144. },"RunService")
  145. }
  146. rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
  147. FakeGame.service = FakeGame.GetService
  148. FakeService(FakeGame,game)
  149. --Changing owner to fake player object to support owner:GetMouse()
  150. game,owner = FakeGame,FakeGame.Players.LocalPlayer
  151. end
  152. model = script.Parent
  153. backup = model:Clone()
  154. regentime = 1 --5 minutes
  155.  
  156. ------------------
  157. --SPAWNING--
  158. ------------------
  159.  
  160. miked=script.Parent
  161.  
  162. itlh=miked.Torso:findFirstChild("Left Hip")
  163. itlh.Part0=miked.Torso
  164. itlh.Part1=miked:findFirstChild("Left Leg")
  165. itlh.C0=CFrame.new(-1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  166.  
  167. itrh=miked.Torso:findFirstChild("Right Hip")
  168. itrh.Part0=miked.Torso
  169. itrh.Part1=miked:findFirstChild("Right Leg")
  170. itrh.C0=CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  171.  
  172. itls=miked.Torso:findFirstChild("Left Shoulder")
  173. itls.Part1=miked.Torso
  174. itls.C0=CFrame.new(2, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  175. itls.Part0=miked:findFirstChild("Left Arm")
  176.  
  177. itrs=miked.Torso:findFirstChild("Right Shoulder")
  178. itrs.Part1=miked.Torso
  179. itrs.C0=CFrame.new(-2, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  180. itrs.Part0=miked:findFirstChild("Right Arm")
  181.  
  182. miked.Head:makeJoints()
  183. ------------------
  184. ------------------
  185.  
  186.  
  187. function waitForChild(parent, childName)
  188. while true do
  189. local child = parent:findFirstChild(childName)
  190. if child then
  191. return child
  192. end
  193. parent.ChildAdded:wait()
  194. end
  195. end
  196.  
  197. local Figure = script.Parent
  198. local Torso = waitForChild(Figure, "Torso")
  199. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  200. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  201. local RightHip = waitForChild(Torso, "Right Hip")
  202. local LeftHip = waitForChild(Torso, "Left Hip")
  203. local Neck = waitForChild(Torso, "Neck")
  204. local Humanoid = waitForChild(Figure, "Zombie")
  205. local pose = "Standing"
  206.  
  207. local toolAnim = "None"
  208. local toolAnimTime = 0
  209.  
  210. local isSeated = false
  211.  
  212.  
  213. function onRunning(speed)
  214. if isSeated then return end
  215.  
  216. if speed>0 then
  217. pose = "Running"
  218. else
  219. pose = "Standing"
  220. end
  221. end
  222.  
  223. function onDied()
  224. pose = "Dead"
  225. wait(regentime)
  226. wait(1)
  227. model:remove()
  228. model = backup:Clone()
  229. wait(3)
  230. model.Parent = game.Workspace
  231. model:MakeJoints()
  232. end
  233.  
  234. function onJumping()
  235. isSeated = false
  236. pose = "Jumping"
  237. end
  238.  
  239. function onClimbing()
  240. pose = "Climbing"
  241. end
  242.  
  243. function onGettingUp()
  244. pose = "GettingUp"
  245. end
  246.  
  247. function onFreeFall()
  248. pose = "FreeFall"
  249. end
  250.  
  251. function onDancing()
  252. pose = "Dancing"
  253. end
  254.  
  255. function onFallingDown()
  256. pose = "FallingDown"
  257. end
  258.  
  259. function onSeated()
  260. isSeated = true
  261. pose = "Seated"
  262. end
  263.  
  264.  
  265.  
  266. function moveJump()
  267. RightShoulder.MaxVelocity = 0.5
  268. LeftShoulder.MaxVelocity = 0.5
  269. RightShoulder.DesiredAngle = -3.14
  270. LeftShoulder.DesiredAngle = -3.14
  271. RightHip.DesiredAngle = 0
  272. LeftHip.DesiredAngle = 0
  273. end
  274.  
  275. function moveFreeFall()
  276. RightShoulder.MaxVelocity = 0.5
  277. LeftShoulder.MaxVelocity = 0.5
  278. RightShoulder.DesiredAngle = -1
  279. LeftShoulder.DesiredAngle = -1
  280. RightHip.DesiredAngle = 0
  281. LeftHip.DesiredAngle = 0
  282. end
  283.  
  284. function moveFloat()
  285. RightShoulder.MaxVelocity = 0.5
  286. LeftShoulder.MaxVelocity = 0.5
  287. RightShoulder.DesiredAngle = -1.57
  288. LeftShoulder.DesiredAngle = 1.57
  289. RightHip.DesiredAngle = 1.57
  290. LeftHip.DesiredAngle = -1.57
  291. end
  292.  
  293. function moveBoogy()
  294. while pose=="Boogy" do
  295. wait(.5)
  296. RightShoulder.MaxVelocity = 1
  297. LeftShoulder.MaxVelocity = 1
  298. RightShoulder.DesiredAngle = -3.14
  299. LeftShoulder.DesiredAngle = 0
  300. RightHip.DesiredAngle = 1.57
  301. LeftHip.DesiredAngle = 0
  302. wait(.5)
  303. RightShoulder.MaxVelocity = 1
  304. LeftShoulder.MaxVelocity = 1
  305. RightShoulder.DesiredAngle = 0
  306. LeftShoulder.DesiredAngle = -3.14
  307. RightHip.DesiredAngle = 0
  308. LeftHip.DesiredAngle = 1.57
  309. end
  310. end
  311.  
  312. function moveZombie()
  313. RightShoulder.MaxVelocity = 0.5
  314. LeftShoulder.MaxVelocity = 0.5
  315. RightShoulder.DesiredAngle = -1.57
  316. LeftShoulder.DesiredAngle = 1.57
  317. RightHip.DesiredAngle = 0
  318. LeftHip.DesiredAngle = 0
  319. end
  320.  
  321. function movePunch()
  322. script.Parent.Torso.Anchored=true
  323. RightShoulder.MaxVelocity = 60
  324. LeftShoulder.MaxVelocity = 0.5
  325. RightShoulder.DesiredAngle = -1.57
  326. LeftShoulder.DesiredAngle = 0
  327. RightHip.DesiredAngle = 0
  328. LeftHip.DesiredAngle = 0
  329. wait(1)
  330. script.Parent.Torso.Anchored=false
  331. pose="Standing"
  332.  
  333. end
  334.  
  335. function moveKick()
  336. RightShoulder.MaxVelocity = 0.5
  337. LeftShoulder.MaxVelocity = 0.5
  338. RightShoulder.DesiredAngle = 0
  339. LeftShoulder.DesiredAngle = 0
  340. RightHip.MaxVelocity = 40
  341. RightHip.DesiredAngle = 1.57
  342. LeftHip.DesiredAngle = 0
  343. wait(1)
  344. pose="Standing"
  345.  
  346. end
  347.  
  348. function moveFly()
  349. RightShoulder.MaxVelocity = 0.5
  350. LeftShoulder.MaxVelocity = 0.5
  351. RightShoulder.DesiredAngle = 0
  352. LeftShoulder.DesiredAngle = 0
  353. RightHip.MaxVelocity = 40
  354. RightHip.DesiredAngle = 1.57
  355. LeftHip.DesiredAngle = 0
  356. wait(1)
  357. pose="Standing"
  358.  
  359. end
  360.  
  361.  
  362. function moveClimb()
  363. RightShoulder.MaxVelocity = 0.5
  364. LeftShoulder.MaxVelocity = 0.5
  365. RightShoulder.DesiredAngle = -3.14
  366. LeftShoulder.DesiredAngle = 3.14
  367. RightHip.DesiredAngle = 0
  368. LeftHip.DesiredAngle = 0
  369. end
  370.  
  371. function moveSit()
  372. RightShoulder.MaxVelocity = 0.15
  373. LeftShoulder.MaxVelocity = 0.15
  374. RightShoulder.DesiredAngle = -3.14 /2
  375. LeftShoulder.DesiredAngle = -3.14 /2
  376. RightHip.DesiredAngle = 3.14 /2
  377. LeftHip.DesiredAngle = -3.14 /2
  378. end
  379.  
  380. function getTool()
  381.  
  382. kidTable = Figure:children()
  383. if (kidTable ~= nil) then
  384. numKids = #kidTable
  385. for i=1,numKids do
  386. if (kidTable[i].className == "Tool") then return kidTable[i] end
  387. end
  388. end
  389.  
  390. return nil
  391. end
  392.  
  393. function getToolAnim(tool)
  394.  
  395. c = tool:children()
  396. for i=1,#c do
  397. if (c[i].Name == "toolanim" and c[i].className == "StringValue") then
  398. return c[i]
  399. end
  400. end
  401. return nil
  402. end
  403.  
  404. function animateTool()
  405.  
  406. if (toolAnim == "None") then
  407. RightShoulder.DesiredAngle = -1.57
  408. return
  409. end
  410.  
  411. if (toolAnim == "Slash") then
  412. RightShoulder.MaxVelocity = 0.5
  413. RightShoulder.DesiredAngle = 0
  414. return
  415. end
  416.  
  417. if (toolAnim == "Lunge") then
  418. RightShoulder.MaxVelocity = 0.5
  419. LeftShoulder.MaxVelocity = 0.5
  420. RightHip.MaxVelocity = 0.5
  421. LeftHip.MaxVelocity = 0.5
  422. RightShoulder.DesiredAngle = -1.57
  423. LeftShoulder.DesiredAngle = 1.0
  424. RightHip.DesiredAngle = 1.57
  425. LeftHip.DesiredAngle = 1.0
  426. return
  427. end
  428. end
  429.  
  430. function move(time)
  431. local amplitude
  432. local frequency
  433.  
  434. if (pose == "Jumping") then
  435. moveJump()
  436. return
  437. end
  438.  
  439. if (pose == "Zombie") then
  440. moveZombie()
  441. return
  442. end
  443.  
  444. if (pose == "Boogy") then
  445. moveBoogy()
  446. return
  447. end
  448.  
  449. if (pose == "Float") then
  450. moveFloat()
  451. return
  452. end
  453.  
  454. if (pose == "Punch") then
  455. movePunch()
  456. return
  457. end
  458.  
  459. if (pose == "Kick") then
  460. moveKick()
  461. return
  462. end
  463.  
  464. if (pose == "Fly") then
  465. moveFly()
  466. return
  467. end
  468.  
  469. if (pose == "FreeFall") then
  470. moveFreeFall()
  471. return
  472. end
  473.  
  474. if (pose == "Climbing") then
  475. moveClimb()
  476. return
  477. end
  478.  
  479. if (pose == "Seated") then
  480. moveSit()
  481. return
  482. end
  483.  
  484. amplitude = 0.1
  485. frequency = 1
  486.  
  487. RightShoulder.MaxVelocity = 0.15
  488. LeftShoulder.MaxVelocity = 0.15
  489. if (pose == "Running") then
  490. amplitude = 1
  491. frequency = 9
  492. elseif (pose == "Dancing") then
  493. amplitude = 2
  494. frequency = 16
  495. end
  496.  
  497.  
  498. desiredAngle = amplitude * math.sin(time*frequency)
  499. if pose~="Dancing" then
  500. RightShoulder.DesiredAngle = -desiredAngle
  501. LeftShoulder.DesiredAngle = desiredAngle
  502. RightHip.DesiredAngle = -desiredAngle
  503. LeftHip.DesiredAngle = -desiredAngle
  504. else
  505. RightShoulder.DesiredAngle = desiredAngle
  506. LeftShoulder.DesiredAngle = desiredAngle
  507. RightHip.DesiredAngle = -desiredAngle
  508. LeftHip.DesiredAngle = -desiredAngle
  509. end
  510.  
  511.  
  512.  
  513. local tool = getTool()
  514.  
  515. if tool ~= nil then
  516.  
  517. animStringValueObject = getToolAnim(tool)
  518.  
  519. if animStringValueObject ~= nil then
  520. toolAnim = animStringValueObject.Value
  521. -- message recieved, delete StringValue
  522. animStringValueObject.Parent = nil
  523. toolAnimTime = time + .3
  524. end
  525.  
  526. if time > toolAnimTime then
  527. toolAnimTime = 0
  528. toolAnim = "None"
  529. end
  530.  
  531. animateTool()
  532.  
  533.  
  534. else
  535. toolAnim = "None"
  536. toolAnimTime = 0
  537. end
  538. end
  539.  
  540.  
  541. -- connect events
  542. -----------------------------------------------------------------------------------------------------------------------
  543.  
  544. function unequip()
  545. local items=script.Parent:children()
  546. for i=1, #items do
  547. if items[i].className=="Tool" then items[i]:remove() end
  548. end
  549. end
  550.  
  551. function onChatted(msg, recipient)
  552. msg = string.lower(msg)
  553.  
  554. if string.match(msg, string.lower(script.Parent.Name))~=nil or string.match(msg, "everyone") then
  555. if string.match(msg, "equip") then
  556. if game.Workspace:findFirstChild("Hub") then
  557. if string.match(msg, "rocket") then unequip()
  558. game.Workspace.Hub.Rocket:clone().Parent=script.Parent
  559. elseif string.match(msg, "slingshot") then unequip()
  560. game.Workspace.Hub.Slingshot:clone().Parent=script.Parent
  561. elseif string.match(msg, "sword") then unequip()
  562. game.Workspace.Hub.Sword:clone().Parent=script.Parent
  563. elseif string.match(msg, "pbg") then unequip()
  564. game.Workspace.Hub.PBG:clone().Parent=script.Parent
  565. elseif string.match(msg, "superball") then unequip()
  566. game.Workspace.Hub.Superball:clone().Parent=script.Parent
  567. elseif string.match(msg, "trowel") then unequip()
  568. game.Workspace.Hub.Trowel:clone().Parent=script.Parent
  569. elseif string.match(msg, "bomb") then unequip()
  570. game.Workspace.Hub.Bomb:clone().Parent=script.Parent
  571. end
  572. end
  573. end
  574. if string.match(msg, "unequip") then unequip() end
  575. if string.match(msg, "run") then onRunning(1) end
  576. if string.match(msg, "climb") then onClimbing() end
  577. if string.match(msg, "jump") then onJumping() end
  578. if string.match(msg, "zombie") then pose="Zombie" end
  579. if string.match(msg, "disco") then pose="Boogy" end
  580. if string.match(msg, "float") then pose="Float" end
  581. if string.match(msg, "punch") then pose="Punch" end
  582. if string.match(msg, "kick") then pose="Kick" end
  583. if string.match(msg, "fly") then pose="Fly" end
  584. if string.match(msg, "heal") then script.Parent.Humanoid.Health=script.Parent.Humanoid.MaxHealth end
  585. if string.match(msg, "defend") then defence() end
  586. if string.match(msg, "stop") then pose="Standing"; proxkill=false; following=false; stopmoving() end
  587. if string.match(msg, "go home") then following=false; gohome() end
  588. if string.match(msg, "follow") then
  589. if string.match(msg, "all") then
  590. followany()
  591. else
  592. local egg=game.Players:children()
  593. for i=1, #egg do
  594. if string.match(msg, string.lower(egg[i].Name)) then
  595. follow(egg[i].Name)
  596. return
  597. end
  598. end
  599. end
  600. end
  601. if string.match(msg, "kill") then
  602. if string.match(msg, "all") then
  603. attackany()
  604. else
  605. local egg=game.Players:children()
  606. for i=1, #egg do
  607. if string.match(msg, string.lower(egg[i].Name)) then
  608. attack(egg[i].Name)
  609. return
  610. end
  611. end
  612. end
  613. end
  614.  
  615. end
  616. end
  617.  
  618. if game.Players.NumPlayers>1 then
  619. x=game.Players:children()
  620.  
  621. for i=1, #x do
  622. if script.Parent:findFirstChild("Commander")~=nil then
  623. if script.Parent.Commander:children()~=nil or script.Parent.Commander:children()>0 then
  624. local ch=script.Parent.Commander:children()
  625. for i=1, #ch do
  626. if string.lower(ch[i].Name)==string.lower(x[i].Name) then
  627. x[i].Chatted:connect(function(msg, recipient) onChatted(msg, recipient) end)
  628. end
  629. end
  630. elseif string.lower(script.Parent.Commander.Value)==string.lower(x[i].Name) then
  631. x[i].Chatted:connect(function(msg, recipient) onChatted(msg, recipient) end)
  632. end
  633. else
  634. x[i].Chatted:connect(function(msg, recipient) onChatted(msg, recipient) end)
  635. end
  636. end
  637. end
  638.  
  639.  
  640. function onPlayerEntered(Player)
  641. while Player.Name==nil do
  642. wait(2)
  643. end
  644. if script.Parent:findFirstChild("Commander")~=nil then
  645. if script.Parent.Commander:children()~=nil or script.Parent.Commander:children()>0 then
  646. local ch=script.Parent.Commander:children()
  647. for i=1, #ch do
  648. if string.lower(ch[i].Name)==string.lower(Player.Name) then
  649. Player.Chatted:connect(function(msg, recipient) onChatted(msg, recipient) end)
  650. end
  651. end
  652. elseif string.lower(script.Parent.Commander.Value)==string.lower(Player.Name) then
  653. Player.Chatted:connect(function(msg, recipient) onChatted(msg, recipient) end)
  654. end
  655. else
  656. Player.Chatted:connect(function(msg, recipient) onChatted(msg, recipient) end)
  657. end
  658. end
  659.  
  660. game.Players.ChildAdded:connect(onPlayerEntered)
  661.  
  662.  
  663.  
  664. -----------------------------------------------------------------------------------------------------------------------
  665. -----------------------------------------------------------------------------------------------------------------------
  666. -----------------------------------------------------------------------------------------------------------------------
  667. -----------------------------------------------------------------------------------------------------------------------
  668. -----------------------------------------------------------------------------------------------------------------------
  669. -----------------------------------------------------------------------------------------------------------------------
  670. -----------------------------------------------------------------------------------------------------------------------
  671. -----------------------------------------------------------------------------------------------------------------------
  672. -----------------------------------------------------------------------------------------------------------------------
  673. -----------------------------------------------------------------------------------------------------------------------
  674. -----------------------------------------------------------------------------------------------------------------------
  675. -----------------------------------------------------------------------------------------------------------------------
  676. dist=20
  677.  
  678. function followany()
  679. following=true
  680. while following==true do
  681.  
  682. local ch=game.Players:children()
  683. for i=1, #ch do
  684. local l=game.Workspace:findFirstChild(ch[i].Name)
  685. if l~=nil then
  686. local s=l.Torso
  687. local p=l.Torso.Position
  688. local q=script.Parent.Torso.Position
  689. local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
  690. if smallest==nil then
  691. smallest=d
  692. target=s
  693. elseif d<smallest then
  694. smallest=d
  695. target=s
  696. end
  697. end
  698. end
  699.  
  700. if smallest==nil then stopmoving() return end
  701.  
  702. if smallest>6*dist then return end
  703.  
  704. script.Parent.Humanoid:MoveTo(target.Position, target)
  705.  
  706. wait(0.5)
  707. for i=1, 6 do
  708. if target.Parent.Humanoid.Health<1 then stopmoving() else wait(0.5) end
  709. end
  710. end
  711. end
  712.  
  713.  
  714.  
  715. function gohome()
  716. script.Parent.Humanoid:MoveTo(Vector3.new(0,0,0), game.Workspace.Bases.Base)
  717. end
  718. function stopmoving()
  719. script.Parent.Humanoid:MoveTo(script.Parent.Torso.Position, script.Parent.Torso)
  720. end
  721.  
  722. function follow(name)
  723. following=true
  724.  
  725. local p=game.Workspace:findFirstChild(name)
  726. if p==nil then return end
  727. while following==true do
  728. script.Parent.Humanoid:MoveTo(p.Torso.Position, p.Torso)
  729. wait(0.5)
  730. for i=1, 3 do
  731. if p.Humanoid.Health<1 then following=false; stopmoving() return end
  732. wait(0.5)
  733. end
  734. end
  735. end
  736.  
  737. function attack(name)
  738. if script.Parent:findFirstChild("Sword")~=nil then
  739. following=true
  740. local p=game.Workspace:findFirstChild(name)
  741. if p==nil then return end
  742. while following==true do
  743. script.Parent.Humanoid:MoveTo(p.Torso.Position, p.Torso)
  744. wait(0.5)
  745. for i=1, 3 do
  746. if p.Humanoid.Health<1 then following=false; stopmoving() return end
  747. local l=p.Torso.Position
  748. local q=script.Parent.Torso.Position
  749. local d=math.sqrt( ((l.x-q.x)^2)+((l.y-q.y)^2)+((l.z-q.z)^2) )
  750. if d<10 then
  751. script.Parent.Humanoid:MoveTo(p.Torso.Position, p.Torso); slash()
  752. if (q.y-l.y)>3 and (q.y-l.y)<7 then
  753. script.Parent.Humanoid:MoveTo(p.Torso.Position+Vector3.new(math.random(-4,4),0,math.random(-4,4)), p.Torso);
  754. end
  755. end
  756. wait(1)
  757. end
  758. end
  759. end
  760. end
  761.  
  762. function attackany()
  763. if script.Parent:findFirstChild("Sword")~=nil then
  764.  
  765. following=true
  766. while following==true do
  767.  
  768. local ch=game.Players:children()
  769. for i=1, #ch do
  770. local l=game.Workspace:findFirstChild(ch[i].Name)
  771. if l~=nil then
  772. local s=l.Torso
  773. local p=l.Torso.Position
  774. local q=script.Parent.Torso.Position
  775. local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
  776. if smallest==nil then
  777. smallest=d
  778. target=s
  779. elseif d<smallest then
  780. smallest=d
  781. target=s
  782. end
  783. end
  784. end
  785.  
  786. if smallest==nil then stopmoving() return end
  787.  
  788. if smallest>6*dist then return end
  789.  
  790. script.Parent.Humanoid:MoveTo(target.Position, target)
  791.  
  792. if smallest<10 then
  793. slash()
  794. end
  795. if target.Parent==nil then stopmoving() return end
  796. wait(0.5)
  797. for i=1, 3 do
  798. if target.Parent.Humanoid.Health<1 then
  799. stopmoving()
  800. else
  801. local p=target.Position
  802. local q=script.Parent.Torso.Position
  803. local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
  804. if d<10 then
  805. script.Parent.Humanoid:MoveTo(target.Position, target); slash()
  806. if (q.y-p.y)>3 and (q.y-p.y)<7 then
  807. script.Parent.Humanoid:MoveTo(p.Torso.Position+Vector3.new(math.random(-4,4),0,math.random(-4,4)), p.Torso);
  808. end
  809. end
  810. wait(1)
  811. end
  812. end
  813. end
  814. end
  815. end
  816.  
  817.  
  818. function patrol()
  819. if points==nil then
  820. points=0
  821. if game.Workspace:findFirstChild("pp1")~=nil then
  822. pp1=game.Workspace:findFirstChild("pp1")
  823. local points=points+1
  824. if game.Workspace:findFirstChild("pp2")~=nil then
  825. pp2=game.Workspace:findFirstChild("pp2")
  826. local points=points+1
  827. if game.Workspace:findFirstChild("pp3")~=nil then
  828. pp3=game.Workspace:findFirstChild("pp3")
  829. local points=points+1
  830. if game.Workspace:findFirstChild("pp4")~=nil then
  831. pp4=game.Workspace:findFirstChild("pp4")
  832. local points=points+1
  833. if game.Workspace:findFirstChild("pp5")~=nil then
  834. pp5=game.Workspace:findFirstChild("pp5")
  835. local points=points+1
  836. if game.Workspace:findFirstChild("pp6")~=nil then
  837. pp6=game.Workspace:findFirstChild("pp6")
  838. local points=points+1
  839. if game.Workspace:findFirstChild("pp7")~=nil then
  840. pp7=game.Workspace:findFirstChild("pp7")
  841. local points=points+1
  842. if game.Workspace:findFirstChild("pp8")~=nil then
  843. pp8=game.Workspace:findFirstChild("pp8")
  844. local points=points+1
  845. if game.Workspace:findFirstChild("pp9")~=nil then
  846. pp9=game.Workspace:findFirstChild("pp9")
  847. local points=points+1
  848. end
  849. end
  850. end
  851. end
  852. end
  853. end
  854. end
  855. end
  856. end
  857. end
  858.  
  859. if points<1 then return end
  860. patrolling=true
  861. local time=2
  862. if points==1 then return end
  863. if points>1 then
  864. while patrolling==true do
  865. script.Parent.Humanoid:MoveTo(pp1.Position, pp1)
  866. wait(time)
  867. script.Parent.Humanoid:MoveTo(pp2.Position, pp2)
  868. wait(time)
  869. if points>2 then
  870. script.Parent.Humanoid:MoveTo(pp3.Position, pp3)
  871. wait(time)
  872. if points>3 then
  873. script.Parent.Humanoid:MoveTo(pp4.Position, pp4)
  874. wait(time)
  875. if points>4 then
  876. script.Parent.Humanoid:MoveTo(pp5.Position, pp5)
  877. wait(time)
  878. if points>5 then
  879. script.Parent.Humanoid:MoveTo(pp6.Position, pp6)
  880. wait(time)
  881. if points>6 then
  882. script.Parent.Humanoid:MoveTo(pp7.Position, pp7)
  883. wait(time)
  884. if points>7 then
  885. script.Parent.Humanoid:MoveTo(pp8.Position, pp8)
  886. wait(time)
  887. if points>8 then
  888. script.Parent.Humanoid:MoveTo(pp9.Position, pp9)
  889. wait(time)
  890. end
  891. end
  892. end
  893. end
  894. end
  895. end
  896. end
  897. end
  898. end
  899. end
  900.  
  901.  
  902. function goto(pos,part)
  903. while true do
  904. end
  905. end
  906.  
  907.  
  908. function slash()
  909. for i=1, 3 do
  910. wait(.3)
  911. RightShoulder.MaxVelocity = 2
  912. LeftShoulder.MaxVelocity = 1
  913. RightShoulder.DesiredAngle = -2.14
  914. LeftShoulder.DesiredAngle = 0
  915. RightHip.DesiredAngle = 0
  916. LeftHip.DesiredAngle = 0
  917. wait(.2)
  918. RightShoulder.MaxVelocity = 2
  919. LeftShoulder.MaxVelocity = 1
  920. RightShoulder.DesiredAngle = 0
  921. LeftShoulder.DesiredAngle = 0
  922. RightHip.DesiredAngle = 0
  923. LeftHip.DesiredAngle = 0
  924. end
  925. end
  926.  
  927. function defence()
  928. proxkill=true
  929. while proxkill==true do
  930. local ch=game.Players:children()
  931. for i=1, #ch do
  932. local p=game.Workspace:findFirstChild(ch[i].Name)
  933. if p~=nil then
  934. local p=p.Torso.Position
  935. local q=script.Parent.Torso.Position
  936. local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
  937. if d<dist and d>8 then
  938. local ex=Instance.new("Explosion")
  939. ex.Position=p
  940. ex.Parent=game.Workspace
  941. end
  942. end
  943. end
  944. wait(1)
  945. end
  946. end
  947.  
  948.  
  949.  
  950.  
  951. -----------------------------------------------------------------------------------------------------------------------
  952. -----------------------------------------------------------------------------------------------------------------------
  953. -----------------------------------------------------------------------------------------------------------------------
  954. -----------------------------------------------------------------------------------------------------------------------
  955. -----------------------------------------------------------------------------------------------------------------------
  956. -----------------------------------------------------------------------------------------------------------------------
  957. -----------------------------------------------------------------------------------------------------------------------
  958. -----------------------------------------------------------------------------------------------------------------------
  959. -----------------------------------------------------------------------------------------------------------------------
  960. -----------------------------------------------------------------------------------------------------------------------
  961. -----------------------------------------------------------------------------------------------------------------------
  962. -----------------------------------------------------------------------------------------------------------------------
  963.  
  964.  
  965. Humanoid.Died:connect(onDied)
  966. Humanoid.Running:connect(onRunning)
  967. Humanoid.Jumping:connect(onJumping)
  968. Humanoid.Climbing:connect(onClimbing)
  969. Humanoid.GettingUp:connect(onGettingUp)
  970. Humanoid.FreeFalling:connect(onFreeFall)
  971. Humanoid.FallingDown:connect(onFallingDown)
  972. Humanoid.Seated:connect(onSeated)
  973.  
  974.  
  975. --[[
  976.  
  977. function newSound(id)
  978. local sound = Instance.new("Sound")
  979. sound.SoundId = id
  980. sound.Parent = script.Parent.Head
  981. return sound
  982. end
  983.  
  984.  
  985. local sDied = newSound("rbxasset://sounds/uuhhh.wav")
  986. local sFallingDown = newSound("rbxasset://sounds/splat.wav")
  987. local sFreeFalling = newSound("rbxasset://sounds/swoosh.wav")
  988. local sGettingUp = newSound("rbxasset://sounds/hit.wav")
  989. local sJumping = newSound("rbxasset://sounds/button.wav")
  990. local sRunning = newSound("rbxasset://sounds/bfsl-minifigfoots1.mp3")
  991. sRunning.Looped = true
  992.  
  993. local Figure = script.Parent
  994. local Head = waitForChild(Figure, "Head")
  995. local Humanoid = waitForChild(Figure, "Humanoid")
  996.  
  997.  
  998. function onDied()
  999. sDied:play()
  1000. end
  1001.  
  1002. function onState(state, sound)
  1003. if state then
  1004. sound:play()
  1005. else
  1006. sound:pause()
  1007. end
  1008. end
  1009.  
  1010. function onRunning(speed)
  1011. if speed>0 then
  1012. sRunning:play()
  1013. else
  1014. sRunning:pause()
  1015. end
  1016. end
  1017.  
  1018.  
  1019. Humanoid.Died:connect(onDied)
  1020. Humanoid.Running:connect(onRunning)
  1021. Humanoid.Jumping:connect(function(state) onState(state, sJumping) end)
  1022. Humanoid.GettingUp:connect(function(state) onState(state, sGettingUp) end)
  1023. Humanoid.FreeFalling:connect(function(state) onState(state, sFreeFalling) end)
  1024. Humanoid.FallingDown:connect(function(state) onState(state, sFallingDown) end)
  1025. --]]
  1026.  
  1027. local nextTime = 0
  1028. local runService = game:service("RunService");
  1029.  
  1030. while Figure.Parent~=nil do
  1031. time = runService.Stepped:wait()
  1032. if time > nextTime then
  1033. move(time)
  1034. nextTime = time + 0.1
  1035. end
  1036. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement