Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Control script for the Legokid
- --]]
- -- Constants --
- local RS = game:GetService("RunService")
- local Players = game:GetService("Players")
- local ChatService = game:GetService("Chat")
- local RepStor = game:GetService("ReplicatedStorage")
- local IS = game:GetService("InsertService")
- local Legokid = script.Parent
- local Humanoid = Legokid.Humanoid
- local StopAction = false
- local Rad = math.rad
- local RNG = Random.new()
- local PlayersHooked = {}
- -- Important functions --
- function FindInTable(Tbl,Element)
- for i = 1,#Tbl do
- if Tbl[i] == Element then
- return true
- end
- end
- return false
- end
- function GetDistance(X,Y)
- return (X.Position-Y.Position).Magnitude
- end
- function Stop(Dequip)
- -- Stops the Legokid's actions --
- local Torso = Legokid.Torso
- local LS,RiS = Torso:FindFirstChild("Left Shoulder"),Torso:FindFirstChild("Right Shoulder")
- local LH,RH = Torso:FindFirstChild("Left Hip"),Torso:FindFirstChild("Right Hip") StopAction = true
- -- This could put a small pause on any action that happens after this is called --
- -- If the character has a tool equiped, put their arm down --
- spawn(function()
- if Dequip and Legokid:FindFirstChildOfClass("Tool") then
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
- RS.Heartbeat:Wait()
- end
- Humanoid:UnequipTools()
- end
- end)
- StopAction = true
- -- Set the DesiredAngles --
- LS.DesiredAngle = 0
- RiS.DesiredAngle = 0
- LH.DesiredAngle = 0
- RH.DesiredAngle = 0
- wait(.1)
- StopAction = false
- end
- -- Legokid commands --
- local Commands = {
- ["follow"] = function(...)
- local Arguments = {...}
- if Arguments[1] then
- -- Make the legokid stop following any preselected player --
- Stop(true)
- -- Loop through all players --
- for _,player in pairs(Players:GetPlayers()) do
- if player.Name:lower() == Arguments[1] then
- local Char = player.Character
- spawn(function()
- while Char.Humanoid.Health > 0 and StopAction ~= true do
- Humanoid:MoveTo(Char.HumanoidRootPart.Position)
- RS.Heartbeat:Wait()
- end
- end)
- break
- end
- end
- end
- end,
- ["stop"] = function(...)
- -- Stops the current action --
- Stop(true)
- end,
- ["jump"] = function()
- Humanoid.Jump = true
- end,
- ["unequip"] = function()
- local RiS = Legokid.Torso["Right Shoulder"]
- -- If the character has a tool equiped --
- if Legokid:FindFirstChildOfClass("Tool") then
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
- RS.Heartbeat:Wait()
- end
- end
- -- Unequip any tools already equipped --
- Humanoid:UnequipTools()
- end,
- ["equip"] = function(...)
- local Arguments = {...}
- if Arguments[1] and RepStor:FindFirstChild(Arguments[1]) then
- local Tool = RepStor:FindFirstChild(Arguments[1]):Clone()
- local RiS = Legokid.Torso["Right Shoulder"]
- -- If the character has a tool equiped, move it back to the default arm rotation21 --
- if Legokid:FindFirstChildOfClass("Tool") then
- -- Unequip any tools already equipped --
- Humanoid:UnequipTools()
- -- Move the arm --
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
- RS.Heartbeat:Wait()
- end
- end
- -- Equip the given tool --
- if Tool then
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(6))
- RS.Heartbeat:Wait()
- end
- Humanoid:EquipTool(Tool)
- wait(1)
- end
- end
- end,
- ["attack"] = function(...)
- local Arguments = {...}
- local Tool = Legokid:FindFirstChildOfClass("Tool")
- -- Did the player supply a player to follow? --
- if Arguments[1] then
- if Tool then
- -- Does the player exist? --
- for _,Player in pairs(Players:GetPlayers()) do
- if Player.Name:lower() == Arguments[1] then
- local Char = Player.Character
- -- Make the legokid stop following any preselected player --
- Stop(false)
- -- Follow the player till conditions met --
- spawn(function()
- while Char.Humanoid.Health > 0 and StopAction == false do
- Humanoid:MoveTo(Char.HumanoidRootPart.Position)
- wait()
- end
- end)
- -- Attack the player till conditions are met --
- spawn(function()
- while Char.Humanoid.Health > 0 and StopAction == false do
- local Dist = GetDistance(Legokid.HumanoidRootPart,Char.HumanoidRootPart)
- if Dist <= Tool.Configuration.AttackRange.Value then
- -- Tool specific attacks --
- if Tool.Name == "sword" then
- local SwordMove = RNG:NextInteger(1,2)
- -- Lunge, swing --
- if SwordMove == 1 then
- Tool:Activate()
- elseif SwordMove == 2 then
- Tool:Activate()
- wait(.2)
- Tool:Activate()
- end
- else
- print("E")
- end
- end
- wait(.3)
- end
- end)
- end
- end
- end
- end
- end,
- ["dance"] = function()
- -- Stop any actions already running --
- Stop(true)
- -- Get the Motor6D's in the Torso --
- local Torso = Legokid.Torso
- local LS,RiS = Torso:FindFirstChild("Left Shoulder"),Torso:FindFirstChild("Right Shoulder")
- local LH,RH = Torso:FindFirstChild("Left Hip"),Torso:FindFirstChild("Right Hip")
- -- Do all the Motor6D's exist? --
- if LS and RiS and LH and RH then
- -- Repeat UNTIL Legokid dies or is told to stop --
- -- Move DesiredAngles into starting positions --
- LS.DesiredAngle = 2
- RiS.DesiredAngle = 2
- LH.DesiredAngle = 1
- RH.DesiredAngle = 1
- -- Dance with a duration of 10 seconds unless the Character dies or is told to stop --
- for i = 1,25 do
- if Humanoid.Health > 0 and StopAction == false then
- -- Boogy!! --
- print("Dancin'!")
- -- Move the arms --
- LS.DesiredAngle = 4
- RiS.DesiredAngle = 4
- LH.DesiredAngle = -1
- RH.DesiredAngle = -1
- wait(.2)
- LS.DesiredAngle = 2
- RiS.DesiredAngle = 2
- LH.DesiredAngle = 1
- RH.DesiredAngle = 1
- wait(.2)
- else
- break
- end
- end
- -- Set arms to default --
- LS.DesiredAngle = 0
- RiS.DesiredAngle = 0
- LH.DesiredAngle = 0
- RH.DesiredAngle = 0
- end
- end,
- ["chat"] = function(...) -- typing in messages will say it without spaces. maybe have them say it via a string. also add filtering
- local Args = {...}
- -- If the player supplied something for the Legokid to say --
- if Args[1] then
- ChatService:Chat(Legokid.Head,Args[1],Enum.ChatColor.Blue)
- end
- end,
- ["heal"] = function()
- -- Heal the Legokid --
- Humanoid.Health = Humanoid.MaxHealth
- end,
- ["speed"] = function(...)
- local Args = {...}
- -- Check for a player supplied speed --
- if Args[1] and tonumber(Args[1]) then
- print("Speed given: " .. Args[1])
- Humanoid.WalkSpeed = tonumber(Args[1])
- else
- -- If no speed provided, set to default --
- Humanoid.WalkSpeed = 16
- end
- end,
- ["health"] = function(...)
- local Args = {...}
- -- Check for a player supplied health --
- if Args[1] and tonumber(Args[1]) then
- print("Health given: " .. Args[1])
- Humanoid.Health = tonumber(Args[1])
- else
- -- If no 100 provided, set to default --
- Humanoid.Health = 100
- end
- end,
- ["clothes"] = function(...) -- allow for changing of individual pieces
- local Args = {...}
- -- If given clothes [1] and pants [2] arguments --
- if Args[1] and Args[2] and tonumber(Args[1]) and tonumber(Args[2]) then
- -- Make sure we can load in these assets --
- local Success,C1,C2 = pcall(function()
- return IS:LoadAsset(Args[1]),IS:LoadAsset(Args[2])
- end)
- -- If the assets successfully loaded in --
- if Success then
- -- Destroy any existing pants and replace them --
- local LegokidChildren = Legokid:GetDescendants()
- for object = 1,#LegokidChildren do
- if LegokidChildren[object]:IsA("Shirt") or LegokidChildren[object]:IsA("Pants") then
- LegokidChildren[object]:Destroy()
- print("Destroyed clothing item.")
- end
- end
- C1.Shirt.Parent = Legokid
- C2.Pants.Parent = Legokid
- print("Replaced clothing.")
- else
- warn("Could not load asset.")
- end
- end
- end,
- ["goto"] = function(...)
- -- Moves the NPC to specified coordinates. --
- -- Defaults Coords to Vector3.new(0,0,0)
- Stop()
- local Args = {...}
- -- If provided arguments, and they're all numbers --
- if Args[1] and Args[2] and Args[3] and tonumber(Args[1]) and tonumber(Args[2]) and tonumber(Args[3]) then
- Humanoid:MoveTo(Vector3.new(Args[1],Args[2],Args[3]))
- else
- Humanoid:MoveTo(Vector3.new(0,0,0))
- end
- end
- }
- function ParseMessage(msg)
- --[[
- This Function parses any given message for data
- required by the commands. It will only return any
- arguments and the message under certain conditions, these are:
- If the legokid isn't dead
- If the parsed message begins with "legokid"
- If it has an actual command inside of it
- --]]
- if Humanoid.Health > 0 then
- local MsgIdentifier = msg:sub(1,7):lower()
- local MsgRemainder = msg:sub(9,-1):lower() -- -1 indicating the ending of the str --
- -- Check if the first 7 characters in the string are "legokid" --
- if MsgIdentifier == "legokid" then
- -- Loop through all commands --
- for command,func in pairs(Commands) do
- local CommandEmbded = MsgRemainder:sub(1,command:len())
- local FinalRemainder = ((MsgRemainder:gsub(" ","")):sub(command:len()+1,-1))
- -- If the command is in the beginning of MsgRemainder --
- if CommandEmbded == command then
- print("Found command", command)
- print("Remainder of command:",FinalRemainder)
- -- Extract arguments --
- local Arguments = FinalRemainder:split(",")
- func(unpack(Arguments))
- else
- print("Command wasn't found on this key")
- end
- end
- else
- print("'legokid' not in beginning of command")
- end
- end
- end
- while wait(.1) do
- for index,plr in pairs(Players:GetPlayers()) do
- -- Check if player isn't in our list of hooked players --
- if FindInTable(PlayersHooked,plr.Name) == false then
- -- Add them to table of hooked players --
- table.insert(PlayersHooked,plr.Name)
- -- If the player isn't hooked, hook them --
- plr.Chatted:Connect(function(msg)
- print("Chatted")
- ParseMessage(msg:lower())
- end)
- -- If they are in it, check if they're still in the game --
- else
- -- If they're not still in the game, remove them from the table --
- -- So if they rejoin, it'll still re-hook them --
- for HookedIndex,HookedPlayer in pairs(PlayersHooked) do
- if not Players:FindFirstChild(HookedPlayer) then
- table.remove(PlayersHooked,index)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement