Advertisement
Guest User

Legokid Source

a guest
Nov 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. --[[
  2.     Control script for the Legokid
  3. --]]
  4.  
  5. -- Constants --
  6. local RS = game:GetService("RunService")
  7. local Players = game:GetService("Players")
  8. local RepStor = game:GetService("ReplicatedStorage")
  9. local Extras = require(RepStor.Extras)
  10. local Legokid = script.Parent
  11. local Humanoid = Legokid.Humanoid
  12. local Stop = false
  13. local Rad = math.rad
  14. local RNG = Random.new()
  15. local Commands = {
  16.     ["follow"] = function(...)
  17.         local Arguments = {...}
  18.        
  19.         if Arguments[1] then
  20.             -- Make the legokid stop following any preselected player --
  21.             Stop = true
  22.             wait(.1)
  23.             Stop = false
  24.            
  25.             -- Loop through all players --
  26.             for _,player in pairs(Players:GetPlayers()) do
  27.                 if player.Name:lower() == Arguments[1] then
  28.                     local Char = player.Character
  29.                     spawn(function()
  30.                         while Char.Humanoid.Health > 0 and Stop ~= true do
  31.                             Humanoid:MoveTo(Char.HumanoidRootPart.Position)
  32.                             RS.Heartbeat:Wait()
  33.                         end
  34.                     end)
  35.                     break  
  36.                 end
  37.             end
  38.         end
  39.     end,
  40.     ["stop"] = function()
  41.         -- Stops the current action --
  42.         Stop = true
  43.         wait(.1)
  44.         Stop = false
  45.     end,
  46.     ["jump"] = function()
  47.         Humanoid.Jump = true
  48.     end,
  49.     ["unequip"] = function()
  50.         local RiS = Legokid.Torso["Right Shoulder"]
  51.        
  52.         -- If the character has a tool equiped --
  53.         if Legokid:FindFirstChildOfClass("Tool") then
  54.             for i = 1,90,6 do
  55.                 RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
  56.                 RS.Heartbeat:Wait()
  57.             end
  58.         end
  59.  
  60.         -- Unequip any tools already equipped --
  61.         Humanoid:UnequipTools()
  62.     end,
  63.     ["equip"] = function(...)
  64.         local Arguments = {...}
  65.        
  66.         if Arguments[1] then
  67.             local Tool = RepStor:FindFirstChild(Arguments[1]):Clone()
  68.             local RiS = Legokid.Torso["Right Shoulder"]
  69.            
  70.             -- If the character has a tool equiped, move it back to the default arm rotation21 --
  71.             if Legokid:FindFirstChildOfClass("Tool") then
  72.                 -- Unequip any tools already equipped --
  73.                 Humanoid:UnequipTools()
  74.                
  75.                 -- Move the arm --
  76.                 for i = 1,90,6 do
  77.                     RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
  78.                     RS.Heartbeat:Wait()
  79.                 end
  80.             end
  81.                        
  82.             -- Equip the given tool --
  83.             if Tool then
  84.                 for i = 1,90,6 do
  85.                     RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(6))
  86.                     RS.Heartbeat:Wait()
  87.                 end
  88.                 Humanoid:EquipTool(Tool)
  89.                 wait(1)
  90.             end
  91.         end
  92.     end,
  93.     ["attack"] = function(...)
  94.         local Arguments = {...}
  95.         local Tool = Legokid:FindFirstChildOfClass("Tool")
  96.        
  97.         -- If the player supplied a player to follow --
  98.         if Arguments[1] then
  99.             if Tool then
  100.                 -- If the player exists --
  101.                 for _,Player in pairs(Players:GetPlayers()) do
  102.                     if Player.Name:lower() == Arguments[1] then
  103.                         local Char = Player.Character
  104.                    
  105.                         -- Make the legokid stop following any preselected player --
  106.                         Stop = true
  107.                         wait(.1)
  108.                         Stop = false
  109.                        
  110.                         -- Follow the player until conditions are met --
  111.                         spawn(function()
  112.                             while Char.Humanoid.Health > 0 and Stop == false do
  113.                                 Humanoid:MoveTo(Char.HumanoidRootPart.Position)
  114.                                 wait()
  115.                             end
  116.                         end)
  117.                        
  118.                         -- Attack the player until conditions are met --
  119.                         spawn(function()
  120.                             while Char.Humanoid.Health > 0 and Stop == false do
  121.                                
  122.                                 local Dist = Extras:GetDistance(Legokid.HumanoidRootPart,Char.HumanoidRootPart)
  123.                                 if Dist <= Tool.Configuration.AttackRange.Value then
  124.                                     -- Tool specific attacks --
  125.                                     if Tool.Name == "sword" then
  126.                                         local SwordMove = RNG:NextInteger(1,2)
  127.                                         -- Lunge, and swing --
  128.                                         if SwordMove == 1 then
  129.                                             Tool:Activate()
  130.                                         elseif SwordMove == 2 then
  131.                                             Tool:Activate()
  132.                                             wait(.2)
  133.                                             Tool:Activate()
  134.                                         end
  135.                                     else
  136.                                         print("E")
  137.                                     end
  138.                                 end
  139.                                 wait(.3)
  140.                             end
  141.                         end)
  142.                     end
  143.                 end
  144.             end
  145.         end
  146.     end    
  147. }
  148.  
  149. function ParseMessage(msg)
  150.     --[[
  151.         This Function parses any given message for data
  152.         required by the commands. It will only return any
  153.         arguments and the message under certain conditions, these are:
  154.        
  155.         If the legokid isn't dead
  156.             If the parsed message begins with "legokid"
  157.                 If it has an actual command inside of it
  158.     --]]
  159.    
  160.     if Humanoid.Health > 0 then
  161.         local MsgIdentifier = msg:sub(1,7):lower()
  162.         local MsgRemainder = msg:sub(9,-1):lower() -- -1 indicating the ending of the str --
  163.        
  164.         -- Check if the first 7 characters in the string are "legokid" --
  165.         if MsgIdentifier == "legokid" then
  166.             -- Loop through all commands --
  167.             for command,func in pairs(Commands) do
  168.                 local CommandEmbded = MsgRemainder:sub(1,command:len())
  169.                 local FinalRemainder = ((MsgRemainder:gsub(" ","")):sub(command:len()+1,-1))
  170.                
  171.                 -- If the command is in the beginning of MsgRemainder --
  172.                 if CommandEmbded == command then
  173.                     print("Found command", command)
  174.                     print("Remainder of command:",FinalRemainder)
  175.                    
  176.                     -- Extract arguments --
  177.                     local Arguments = FinalRemainder:split(",")
  178.                     func(unpack(Arguments))
  179.                 else
  180.                     print("Command wasn't found on this key")
  181.                 end
  182.             end
  183.         else
  184.             print("'legokid' not in beginning of command")
  185.         end
  186.     end
  187. end
  188.  
  189. game.Players.PlayerAdded:Connect(function(Player)
  190.     Player.Chatted:Connect(function(msg)
  191.         print("Chatted")
  192.         ParseMessage(msg:lower())  
  193.     end)
  194. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement