Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local runDummyScript = function(f,scri)
- local oldenv = getfenv(f)
- local newenv = setmetatable({}, {
- __index = function(_, k)
- if k:lower() == 'script' then
- return scri
- else
- return oldenv[k]
- end
- end
- })
- setfenv(f, newenv)
- ypcall(function() f() end)
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- mas.Name = "CompiledModel"
- o1 = Instance.new("Model")
- o2 = Instance.new("Part")
- o3 = Instance.new("Motor6D")
- o4 = Instance.new("Part")
- o5 = Instance.new("Motor6D")
- o6 = Instance.new("Motor6D")
- o7 = Instance.new("Motor6D")
- o8 = Instance.new("Motor6D")
- o9 = Instance.new("Motor6D")
- o10 = Instance.new("Script")
- o11 = Instance.new("Part")
- o12 = Instance.new("Part")
- o13 = Instance.new("Part")
- o14 = Instance.new("Part")
- o15 = Instance.new("Part")
- o16 = Instance.new("Decal")
- o17 = Instance.new("SpecialMesh")
- o18 = Instance.new("Humanoid")
- o19 = Instance.new("Script")
- o20 = Instance.new("StringValue")
- o21 = Instance.new("Animation")
- o22 = Instance.new("StringValue")
- o23 = Instance.new("Animation")
- o24 = Instance.new("StringValue")
- o25 = Instance.new("Animation")
- o26 = Instance.new("NumberValue")
- o27 = Instance.new("Animation")
- o28 = Instance.new("NumberValue")
- o29 = Instance.new("StringValue")
- o30 = Instance.new("Animation")
- o31 = Instance.new("StringValue")
- o32 = Instance.new("Animation")
- o33 = Instance.new("StringValue")
- o34 = Instance.new("Animation")
- o35 = Instance.new("StringValue")
- o36 = Instance.new("Animation")
- o37 = Instance.new("StringValue")
- o38 = Instance.new("Animation")
- o39 = Instance.new("BindableEvent")
- o40 = Instance.new("Script")
- o41 = Instance.new("Animation")
- o42 = Instance.new("Configuration")
- o43 = Instance.new("NumberValue")
- o44 = Instance.new("BoolValue")
- o45 = Instance.new("BoolValue")
- o46 = Instance.new("Vector3Value")
- o47 = Instance.new("BoolValue")
- o48 = Instance.new("BrickColorValue")
- o49 = Instance.new("NumberValue")
- o50 = Instance.new("NumberValue")
- o51 = Instance.new("NumberValue")
- o52 = Instance.new("Configuration")
- o53 = Instance.new("ObjectValue")
- o54 = Instance.new("BindableEvent")
- o55 = Instance.new("BindableFunction")
- o56 = Instance.new("BindableEvent")
- o1.Name = "PathFinder"
- o1.Parent = mas
- o2.Name = "HumanoidRootPart"
- o2.Parent = o1
- o2.BrickColor = BrickColor.new("Light stone grey")
- o2.Transparency = 1
- o2.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
- o2.Rotation = Vector3.new(-180, 0, -180)
- o2.FormFactor = Enum.FormFactor.Symmetric
- o2.Size = Vector3.new(2, 2, 1)
- o2.CFrame = CFrame.new(20.7900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- o2.BottomSurface = Enum.SurfaceType.Smooth
- o2.TopSurface = Enum.SurfaceType.Smooth
- o2.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o2.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
- o2.Orientation = Vector3.new(0, 180, 0)
- o2.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o3.Name = "Root Hip"
- o3.Parent = o2
- o3.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- o3.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- o3.Part0 = o2
- o3.Part1 = o4
- o3.MaxVelocity = 0.10000000149012
- o4.Name = "Torso"
- o4.Parent = o1
- o4.BrickColor = BrickColor.new("Dark green")
- o4.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
- o4.Rotation = Vector3.new(-180, 0, -180)
- o4.FormFactor = Enum.FormFactor.Symmetric
- o4.Size = Vector3.new(2, 2, 1)
- o4.CFrame = CFrame.new(20.7900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- o4.BottomSurface = Enum.SurfaceType.Smooth
- o4.TopSurface = Enum.SurfaceType.Smooth
- o4.Color = Color3.new(0.156863, 0.498039, 0.278431)
- o4.Position = Vector3.new(20.7900028, 8.00001526, 3.98998308)
- o4.Orientation = Vector3.new(0, 180, 0)
- o4.Color = Color3.new(0.156863, 0.498039, 0.278431)
- o5.Name = "Left Hip"
- o5.Parent = o4
- o5.C0 = CFrame.new(-1, -1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- o5.C1 = CFrame.new(-0.5, 1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- o5.Part0 = o4
- o5.Part1 = o11
- o5.MaxVelocity = 0.10000000149012
- o6.Name = "Right Hip"
- o6.Parent = o4
- o6.C0 = CFrame.new(1, -1, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- o6.C1 = CFrame.new(0.5, 1, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- o6.Part0 = o4
- o6.Part1 = o12
- o6.MaxVelocity = 0.10000000149012
- o7.Name = "Left Shoulder"
- o7.Parent = o4
- o7.C0 = CFrame.new(-1, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- o7.C1 = CFrame.new(0.5, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- o7.Part0 = o4
- o7.Part1 = o13
- o7.MaxVelocity = 0.10000000149012
- o8.Name = "Right Shoulder"
- o8.Parent = o4
- o8.C0 = CFrame.new(1, 0.5, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- o8.C1 = CFrame.new(-0.5, 0.5, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- o8.Part0 = o4
- o8.Part1 = o14
- o8.MaxVelocity = 0.10000000149012
- o9.Name = "Neck"
- o9.Parent = o4
- o9.C0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- o9.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- o9.Part0 = o4
- o9.Part1 = o15
- o9.MaxVelocity = 0.10000000149012
- o10.Parent = o4
- table.insert(cors,coroutine.create(function()
- wait()
- runDummyScript(function()
- local color = script.Parent.Parent.Configurations.FriendlyTeam.Value
- print(color)
- script.Parent.BrickColor = color
- end,o10)
- end))
- o11.Name = "Left Leg"
- o11.Parent = o1
- o11.BrickColor = BrickColor.new("Pastel Blue")
- o11.Position = Vector3.new(21.2900028, 6.00001526, 3.98998308)
- o11.Rotation = Vector3.new(-180, 0, -180)
- o11.FormFactor = Enum.FormFactor.Symmetric
- o11.Size = Vector3.new(1, 2, 1)
- o11.CFrame = CFrame.new(21.2900028, 6.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
- o11.BottomSurface = Enum.SurfaceType.Smooth
- o11.TopSurface = Enum.SurfaceType.Smooth
- o11.Color = Color3.new(0.501961, 0.733333, 0.858824)
- o11.Position = Vector3.new(21.2900028, 6.00001526, 3.98998308)
- o11.Orientation = Vector3.new(0, 180, 0)
- o11.Color = Color3.new(0.501961, 0.733333, 0.858824)
- o12.Name = "Right Leg"
- o12.Parent = o1
- o12.BrickColor = BrickColor.new("Pastel Blue")
- o12.Position = Vector3.new(20.2900028, 6.00001526, 3.98998308)
- o12.Rotation = Vector3.new(-180, 0, -180)
- o12.FormFactor = Enum.FormFactor.Symmetric
- o12.Size = Vector3.new(1, 2, 1)
- o12.CFrame = CFrame.new(20.2900028, 6.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
- o12.BottomSurface = Enum.SurfaceType.Smooth
- o12.TopSurface = Enum.SurfaceType.Smooth
- o12.Color = Color3.new(0.501961, 0.733333, 0.858824)
- o12.Position = Vector3.new(20.2900028, 6.00001526, 3.98998308)
- o12.Orientation = Vector3.new(0, 180, 0)
- o12.Color = Color3.new(0.501961, 0.733333, 0.858824)
- o13.Name = "Left Arm"
- o13.Parent = o1
- o13.BrickColor = BrickColor.new("Light stone grey")
- o13.Position = Vector3.new(22.2900028, 8.00001526, 3.98998308)
- o13.Rotation = Vector3.new(-180, 0, -180)
- o13.FormFactor = Enum.FormFactor.Symmetric
- o13.Size = Vector3.new(1, 2, 1)
- o13.CFrame = CFrame.new(22.2900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
- o13.BottomSurface = Enum.SurfaceType.Smooth
- o13.TopSurface = Enum.SurfaceType.Smooth
- o13.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o13.Position = Vector3.new(22.2900028, 8.00001526, 3.98998308)
- o13.Orientation = Vector3.new(0, 180, 0)
- o13.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o14.Name = "Right Arm"
- o14.Parent = o1
- o14.BrickColor = BrickColor.new("Light stone grey")
- o14.Position = Vector3.new(19.2900028, 8.00001526, 3.98998308)
- o14.Rotation = Vector3.new(-180, 0, -180)
- o14.FormFactor = Enum.FormFactor.Symmetric
- o14.Size = Vector3.new(1, 2, 1)
- o14.CFrame = CFrame.new(19.2900028, 8.00001526, 3.98998308, -1, 0, 0, 0, 0.999999881, 0, 0, 0, -1)
- o14.BottomSurface = Enum.SurfaceType.Smooth
- o14.TopSurface = Enum.SurfaceType.Smooth
- o14.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o14.Position = Vector3.new(19.2900028, 8.00001526, 3.98998308)
- o14.Orientation = Vector3.new(0, 180, 0)
- o14.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o15.Name = "Head"
- o15.Parent = o1
- o15.BrickColor = BrickColor.new("Light stone grey")
- o15.Position = Vector3.new(20.7900028, 9.50001526, 3.98998308)
- o15.Rotation = Vector3.new(-180, 0, -180)
- o15.FormFactor = Enum.FormFactor.Symmetric
- o15.Size = Vector3.new(2, 1, 1)
- o15.CFrame = CFrame.new(20.7900028, 9.50001526, 3.98998308, -1, 0, 0, 0, 1, 0, 0, 0, -1)
- o15.BottomSurface = Enum.SurfaceType.Smooth
- o15.TopSurface = Enum.SurfaceType.Smooth
- o15.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o15.Position = Vector3.new(20.7900028, 9.50001526, 3.98998308)
- o15.Orientation = Vector3.new(0, 180, 0)
- o15.Color = Color3.new(0.898039, 0.894118, 0.87451)
- o16.Name = "Face"
- o16.Parent = o15
- o16.Texture = "rbxasset://textures/face.png"
- o17.Parent = o15
- o17.Scale = Vector3.new(1.25, 1.25, 1.25)
- o17.Scale = Vector3.new(1.25, 1.25, 1.25)
- o18.Parent = o1
- o18.NameOcclusion = Enum.NameOcclusion.NoOcclusion
- o18.RightLeg = o12
- o18.LeftLeg = o11
- o18.Torso = o2
- o19.Name = "Animate"
- o19.Parent = o1
- table.insert(cors,coroutine.create(function()
- wait()
- runDummyScript(function()
- -- This is in charge of the animations for the character. Pretty much stole it from the default character. Removed emote stuff.
- function waitForChild(parent, childName)
- local child = parent:findFirstChild(childName)
- if child then return child end
- while true do
- child = parent.ChildAdded:wait()
- if child.Name==childName then return child end
- end
- end
- local Figure = script.Parent
- local Torso = waitForChild(Figure, "Torso")
- local RightShoulder = waitForChild(Torso, "Right Shoulder")
- local LeftShoulder = waitForChild(Torso, "Left Shoulder")
- local RightHip = waitForChild(Torso, "Right Hip")
- local LeftHip = waitForChild(Torso, "Left Hip")
- local Neck = waitForChild(Torso, "Neck")
- local Humanoid = waitForChild(Figure, "Humanoid")
- local pose = "Standing"
- local currentAnim = ""
- local currentAnimInstance = nil
- local currentAnimTrack = nil
- local currentAnimKeyframeHandler = nil
- local currentAnimSpeed = 1.0
- local animTable = {}
- local animNames = {
- idle = {
- { id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
- { id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
- },
- walk = {
- { id = "http://www.roblox.com/asset/?id=180426354", weight = 10 }
- },
- run = {
- { id = "run.xml", weight = 10 }
- },
- jump = {
- { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
- },
- fall = {
- { id = "http://www.roblox.com/asset/?id=180436148", weight = 10 }
- },
- climb = {
- { id = "http://www.roblox.com/asset/?id=180436334", weight = 10 }
- },
- sit = {
- { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
- },
- toolnone = {
- { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
- },
- toolslash = {
- { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
- -- { id = "slash.xml", weight = 10 }
- },
- toollunge = {
- { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
- },
- wave = {
- { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
- },
- point = {
- { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
- },
- dance = {
- { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
- },
- dance2 = {
- { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
- },
- dance3 = {
- { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
- },
- laugh = {
- { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
- },
- cheer = {
- { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
- },
- }
- math.randomseed(tick())
- function configureAnimationSet(name, fileList)
- if (animTable[name] ~= nil) then
- for _, connection in pairs(animTable[name].connections) do
- connection:disconnect()
- end
- end
- animTable[name] = {}
- animTable[name].count = 0
- animTable[name].totalWeight = 0
- animTable[name].connections = {}
- -- check for config values
- local config = script:FindFirstChild(name)
- if (config ~= nil) then
- -- print("Loading anims " .. name)
- table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
- table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
- local idx = 1
- for _, childPart in pairs(config:GetChildren()) do
- if (childPart:IsA("Animation")) then
- table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
- animTable[name][idx] = {}
- animTable[name][idx].anim = childPart
- local weightObject = childPart:FindFirstChild("Weight")
- if (weightObject == nil) then
- animTable[name][idx].weight = 1
- else
- animTable[name][idx].weight = weightObject.Value
- end
- animTable[name].count = animTable[name].count + 1
- animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
- -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
- idx = idx + 1
- end
- end
- end
- -- fallback to defaults
- if (animTable[name].count <= 0) then
- for idx, anim in pairs(fileList) do
- animTable[name][idx] = {}
- animTable[name][idx].anim = Instance.new("Animation")
- animTable[name][idx].anim.Name = name
- animTable[name][idx].anim.AnimationId = anim.id
- animTable[name][idx].weight = anim.weight
- animTable[name].count = animTable[name].count + 1
- animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
- -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
- end
- end
- end
- -- Setup animation objects
- function scriptChildModified(child)
- local fileList = animNames[child.Name]
- if (fileList ~= nil) then
- configureAnimationSet(child.Name, fileList)
- end
- end
- script.ChildAdded:connect(scriptChildModified)
- script.ChildRemoved:connect(scriptChildModified)
- for name, fileList in pairs(animNames) do
- configureAnimationSet(name, fileList)
- end
- -- ANIMATION
- -- declarations
- local toolAnim = "None"
- local toolAnimTime = 0
- local jumpAnimTime = 0
- local jumpAnimDuration = 0.3
- local toolTransitionTime = 0.1
- local fallTransitionTime = 0.3
- local jumpMaxLimbVelocity = 0.75
- -- functions
- function stopAllAnimations()
- local oldAnim = currentAnim
- currentAnim = ""
- currentAnimInstance = nil
- if (currentAnimKeyframeHandler ~= nil) then
- currentAnimKeyframeHandler:disconnect()
- end
- if (currentAnimTrack ~= nil) then
- currentAnimTrack:Stop()
- currentAnimTrack:Destroy()
- currentAnimTrack = nil
- end
- return oldAnim
- end
- function setAnimationSpeed(speed)
- if speed ~= currentAnimSpeed then
- currentAnimSpeed = speed
- currentAnimTrack:AdjustSpeed(currentAnimSpeed)
- end
- end
- function keyFrameReachedFunc(frameName)
- if (frameName == "End") then
- -- print("Keyframe : ".. frameName)
- local repeatAnim = currentAnim
- local animSpeed = currentAnimSpeed
- playAnimation(repeatAnim, 0.0, Humanoid)
- setAnimationSpeed(animSpeed)
- end
- end
- -- Preload animations
- function playAnimation(animName, transitionTime, humanoid)
- local roll = math.random(1, animTable[animName].totalWeight)
- local origRoll = roll
- local idx = 1
- while (roll > animTable[animName][idx].weight) do
- roll = roll - animTable[animName][idx].weight
- idx = idx + 1
- end
- -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
- local anim = animTable[animName][idx].anim
- -- switch animation
- if (anim ~= currentAnimInstance) then
- if (currentAnimTrack ~= nil) then
- currentAnimTrack:Stop(transitionTime)
- currentAnimTrack:Destroy()
- end
- currentAnimSpeed = 1.0
- -- load it to the humanoid; get AnimationTrack
- currentAnimTrack = humanoid:LoadAnimation(anim)
- -- play the animation
- currentAnimTrack:Play(transitionTime)
- currentAnim = animName
- currentAnimInstance = anim
- -- set up keyframe name triggers
- if (currentAnimKeyframeHandler ~= nil) then
- currentAnimKeyframeHandler:disconnect()
- end
- currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
- end
- end
- -------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------
- local toolAnimName = ""
- local toolAnimTrack = nil
- local toolAnimInstance = nil
- local currentToolAnimKeyframeHandler = nil
- function toolKeyFrameReachedFunc(frameName)
- if (frameName == "End") then
- -- print("Keyframe : ".. frameName)
- playToolAnimation(toolAnimName, 0.0, Humanoid)
- end
- end
- function playToolAnimation(animName, transitionTime, humanoid)
- local roll = math.random(1, animTable[animName].totalWeight)
- local origRoll = roll
- local idx = 1
- while (roll > animTable[animName][idx].weight) do
- roll = roll - animTable[animName][idx].weight
- idx = idx + 1
- end
- -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
- local anim = animTable[animName][idx].anim
- if (toolAnimInstance ~= anim) then
- if (toolAnimTrack ~= nil) then
- toolAnimTrack:Stop()
- toolAnimTrack:Destroy()
- transitionTime = 0
- end
- -- load it to the humanoid; get AnimationTrack
- toolAnimTrack = humanoid:LoadAnimation(anim)
- -- play the animation
- toolAnimTrack:Play(transitionTime)
- toolAnimName = animName
- toolAnimInstance = anim
- currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
- end
- end
- function stopToolAnimations()
- local oldAnim = toolAnimName
- if (currentToolAnimKeyframeHandler ~= nil) then
- currentToolAnimKeyframeHandler:disconnect()
- end
- toolAnimName = ""
- toolAnimInstance = nil
- if (toolAnimTrack ~= nil) then
- toolAnimTrack:Stop()
- toolAnimTrack:Destroy()
- toolAnimTrack = nil
- end
- return oldAnim
- end
- -------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------
- function onRunning(speed)
- if speed>0.01 then
- playAnimation("walk", 0.1, Humanoid)
- pose = "Running"
- else
- playAnimation("idle", 0.1, Humanoid)
- pose = "Standing"
- end
- end
- function onDied()
- pose = "Dead"
- end
- function onJumping()
- playAnimation("jump", 0.1, Humanoid)
- jumpAnimTime = jumpAnimDuration
- pose = "Jumping"
- end
- function onClimbing(speed)
- playAnimation("climb", 0.1, Humanoid)
- setAnimationSpeed(speed / 12.0)
- pose = "Climbing"
- end
- function onGettingUp()
- pose = "GettingUp"
- end
- function onFreeFall()
- if (jumpAnimTime <= 0) then
- playAnimation("fall", fallTransitionTime, Humanoid)
- end
- pose = "FreeFall"
- end
- function onFallingDown()
- pose = "FallingDown"
- end
- function onSeated()
- pose = "Seated"
- end
- function onPlatformStanding()
- pose = "PlatformStanding"
- end
- function onSwimming(speed)
- if speed>0 then
- pose = "Running"
- else
- pose = "Standing"
- end
- end
- function getTool()
- for _, kid in ipairs(Figure:GetChildren()) do
- if kid.className == "Tool" then return kid end
- end
- return nil
- end
- function getToolAnim(tool)
- for _, c in ipairs(tool:GetChildren()) do
- if c.Name == "toolanim" and c.className == "StringValue" then
- return c
- end
- end
- return nil
- end
- function animateTool()
- if (toolAnim == "None") then
- playToolAnimation("toolnone", toolTransitionTime, Humanoid)
- return
- end
- if (toolAnim == "Slash") then
- playToolAnimation("toolslash", 0, Humanoid)
- return
- end
- if (toolAnim == "Lunge") then
- playToolAnimation("toollunge", 0, Humanoid)
- return
- end
- end
- function moveSit()
- RightShoulder.MaxVelocity = 0.15
- LeftShoulder.MaxVelocity = 0.15
- RightShoulder:SetDesiredAngle(3.14 /2)
- LeftShoulder:SetDesiredAngle(-3.14 /2)
- RightHip:SetDesiredAngle(3.14 /2)
- LeftHip:SetDesiredAngle(-3.14 /2)
- end
- local lastTick = 0
- function move(time)
- local amplitude = 1
- local frequency = 1
- local deltaTime = time - lastTick
- lastTick = time
- local climbFudge = 0
- local setAngles = false
- if (jumpAnimTime > 0) then
- jumpAnimTime = jumpAnimTime - deltaTime
- end
- if (pose == "FreeFall" and jumpAnimTime <= 0) then
- playAnimation("fall", fallTransitionTime, Humanoid)
- elseif (pose == "Seated") then
- playAnimation("sit", 0.5, Humanoid)
- return
- elseif (pose == "Running") then
- playAnimation("walk", 0.1, Humanoid)
- elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
- -- print("Wha " .. pose)
- stopAllAnimations()
- amplitude = 0.1
- frequency = 1
- setAngles = true
- end
- if (setAngles) then
- desiredAngle = amplitude * math.sin(time * frequency)
- RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
- LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
- RightHip:SetDesiredAngle(-desiredAngle)
- LeftHip:SetDesiredAngle(-desiredAngle)
- end
- -- Tool Animation handling
- local tool = getTool()
- if tool then
- animStringValueObject = getToolAnim(tool)
- if animStringValueObject then
- toolAnim = animStringValueObject.Value
- -- message recieved, delete StringValue
- animStringValueObject.Parent = nil
- toolAnimTime = time + .3
- end
- if time > toolAnimTime then
- toolAnimTime = 0
- toolAnim = "None"
- end
- animateTool()
- else
- stopToolAnimations()
- toolAnim = "None"
- toolAnimInstance = nil
- toolAnimTime = 0
- end
- end
- -- connect events
- Humanoid.Died:connect(onDied)
- Humanoid.Running:connect(onRunning)
- Humanoid.Jumping:connect(onJumping)
- Humanoid.Climbing:connect(onClimbing)
- Humanoid.GettingUp:connect(onGettingUp)
- Humanoid.FreeFalling:connect(onFreeFall)
- Humanoid.FallingDown:connect(onFallingDown)
- Humanoid.Seated:connect(onSeated)
- Humanoid.PlatformStanding:connect(onPlatformStanding)
- Humanoid.Swimming:connect(onSwimming)
- -- main program
- local runService = game:service("RunService");
- -- initialize to idle
- playAnimation("idle", 0.1, Humanoid)
- pose = "Standing"
- while Figure.Parent~=nil do
- local _, time = wait(0.1)
- move(time)
- end
- end,o19)
- end))
- o20.Name = "climb"
- o20.Parent = o19
- o21.Name = "ClimbAnim"
- o21.Parent = o20
- o21.AnimationId = "http://www.roblox.com/asset/?id=180436334"
- o22.Name = "fall"
- o22.Parent = o19
- o23.Name = "FallAnim"
- o23.Parent = o22
- o23.AnimationId = "http://www.roblox.com/asset/?id=180436148"
- o24.Name = "idle"
- o24.Parent = o19
- o25.Name = "Animation1"
- o25.Parent = o24
- o25.AnimationId = "http://www.roblox.com/asset/?id=180435571"
- o26.Name = "Weight"
- o26.Parent = o25
- o26.Value = 9
- o27.Name = "Animation2"
- o27.Parent = o24
- o27.AnimationId = "http://www.roblox.com/asset/?id=180435792"
- o28.Name = "Weight"
- o28.Parent = o27
- o28.Value = 1
- o29.Name = "jump"
- o29.Parent = o19
- o30.Name = "JumpAnim"
- o30.Parent = o29
- o30.AnimationId = "http://www.roblox.com/asset/?id=125750702"
- o31.Name = "run"
- o31.Parent = o19
- o32.Name = "RunAnim"
- o32.Parent = o31
- o32.AnimationId = "http://www.roblox.com/asset/?id=180426354"
- o33.Name = "sit"
- o33.Parent = o19
- o34.Name = "SitAnim"
- o34.Parent = o33
- o34.AnimationId = "http://www.roblox.com/asset/?id=178130996"
- o35.Name = "toolnone"
- o35.Parent = o19
- o36.Name = "ToolNoneAnim"
- o36.Parent = o35
- o36.AnimationId = "http://www.roblox.com/asset/?id=182393478"
- o37.Name = "walk"
- o37.Parent = o19
- o38.Name = "WalkAnim"
- o38.Parent = o37
- o38.AnimationId = "http://www.roblox.com/asset/?id=180426354"
- o39.Name = "Attacked"
- o39.Parent = o1
- o40.Name = "MonsterScript"
- o40.Parent = o1
- table.insert(cors,coroutine.create(function()
- wait()
- runDummyScript(function()
- --[[
- Basic Monster by ArceusInator
- Information:
- Configurations.MaximumDetectionDistance (default 200)
- The monster will not detect players past this point. If you set it to a negative number then the monster will be able to chase from any distance.
- Configurations.CanGiveUp (default true)
- If true, the monster will give up if its target goes past the MaximumDetectionDistance. This is a pretty good idea if you have people teleporting around.
- Configurations.CanRespawn (default true)
- If true, the monster will respawn after it dies
- Configurations.AutoDetectSpawnPoint (default true)
- If true, the spawn point will be auto detected based on where the monster is when it starts
- Configurations.SpawnPoint (default 0,0,0)
- If Settings.AutoDetectSpawnPoint is disabled, this will be set to the monster's initial position. This value will be used when the monster auto respawns to tell it where to spawn next.
- Configurations.FriendlyTeam (default Really black)
- The monster will not attack players on this team
- Mind.CurrentTargetHumanoid (Humanoid objects only)
- You can force the monster to follow a certain humanoid by setting this to that humanoid
- Monster.Respawn (Function)
- Arguments are: Vector3 point
- Info: Respawns the monster at the given point, or at the SpawnPoint setting if none if provided
- Monster.Died (Event)
- Info: Fired when the monster dies
- Monster.Respawned (Event)
- Info: Fired when the monster respawns
- --]]
- local Self = script.Parent
- local Settings = Self:FindFirstChild'Configurations' -- Points to the settings.
- local Mind = Self:FindFirstChild'Mind' -- Points to the monster's mind. You can edit parts of this from other scripts in-game to change the monster's behavior. Advanced users only.
- --
- -- Verify that everything is where it should be
- assert(Self:FindFirstChild'Humanoid' ~= nil, 'Monster does not have a humanoid')
- assert(Settings ~= nil, 'Monster does not have a Configurations object')
- assert(Settings:FindFirstChild'MaximumDetectionDistance' ~= nil and Settings.MaximumDetectionDistance:IsA'NumberValue', 'Monster does not have a MaximumDetectionDistance (NumberValue) setting')
- assert(Settings:FindFirstChild'CanGiveUp' ~= nil and Settings.CanGiveUp:IsA'BoolValue', 'Monster does not have a CanGiveUp (BoolValue) setting')
- assert(Settings:FindFirstChild'CanRespawn' ~= nil and Settings.CanRespawn:IsA'BoolValue', 'Monster does not have a CanRespawn (BoolValue) setting')
- assert(Settings:FindFirstChild'SpawnPoint' ~= nil and Settings.SpawnPoint:IsA'Vector3Value', 'Monster does not have a SpawnPoint (Vector3Value) setting')
- assert(Settings:FindFirstChild'AutoDetectSpawnPoint' ~= nil and Settings.AutoDetectSpawnPoint:IsA'BoolValue', 'Monster does not have a AutoDetectSpawnPoint (BoolValue) setting')
- assert(Settings:FindFirstChild'FriendlyTeam' ~= nil and Settings.FriendlyTeam:IsA'BrickColorValue', 'Monster does not have a FriendlyTeam (BrickColorValue) setting')
- assert(Settings:FindFirstChild'AttackDamage' ~= nil and Settings.AttackDamage:IsA'NumberValue', 'Monster does not have a AttackDamage (NumberValue) setting')
- assert(Settings:FindFirstChild'AttackFrequency' ~= nil and Settings.AttackFrequency:IsA'NumberValue', 'Monster does not have a AttackFrequency (NumberValue) setting')
- assert(Settings:FindFirstChild'AttackRange' ~= nil and Settings.AttackRange:IsA'NumberValue', 'Monster does not have a AttackRange (NumberValue) setting')
- assert(Mind ~= nil, 'Monster does not have a Mind object')
- assert(Mind:FindFirstChild'CurrentTargetHumanoid' ~= nil and Mind.CurrentTargetHumanoid:IsA'ObjectValue', 'Monster does not have a CurrentTargetHumanoid (ObjectValue) mind setting')
- assert(Self:FindFirstChild'Respawn' and Self.Respawn:IsA'BindableFunction', 'Monster does not have a Respawn BindableFunction')
- assert(Self:FindFirstChild'Died' and Self.Died:IsA'BindableEvent', 'Monster does not have a Died BindableEvent')
- assert(Self:FindFirstChild'Respawned' and Self.Died:IsA'BindableEvent', 'Monster does not have a Respawned BindableEvent')
- assert(Self:FindFirstChild'Attacked' and Self.Died:IsA'BindableEvent', 'Monster does not have a Attacked BindableEvent')
- assert(script:FindFirstChild'Attack' and script.Attack:IsA'Animation', 'Monster does not have a MonsterScript.Attack Animation')
- --
- --
- local Info = {
- -- These are constant values. Don't change them unless you know what you're doing.
- -- Services
- Players = Game:GetService 'Players',
- PathfindingService = Game:GetService 'PathfindingService',
- -- Advanced settings
- RecomputePathFrequency = 1, -- The monster will recompute its path this many times per second
- RespawnWaitTime = 5, -- How long to wait before the monster respawns
- JumpCheckFrequency = 1, -- How many times per second it will do a jump check
- }
- local Data = {
- -- These are variable values used internally by the script. Advanced users only.
- LastRecomputePath = 0,
- Recomputing = false, -- Reocmputing occurs async, meaning this script will still run while it's happening. This variable will prevent the script from running two recomputes at once.
- PathCoords = {},
- IsDead = false,
- TimeOfDeath = 0,
- CurrentNode = nil,
- CurrentNodeIndex = 1,
- AutoRecompute = true,
- LastJumpCheck = 0,
- LastAttack = 0,
- BaseMonster = Self:Clone(),
- AttackTrack = nil,
- }
- --
- --
- local Monster = {} -- Create the monster class
- function Monster:GetCFrame()
- -- Returns the CFrame of the monster's humanoidrootpart
- local humanoidRootPart = Self:FindFirstChild('HumanoidRootPart')
- if humanoidRootPart ~= nil and humanoidRootPart:IsA('BasePart') then
- return humanoidRootPart.CFrame
- else
- return CFrame.new()
- end
- end
- function Monster:GetMaximumDetectionDistance()
- -- Returns the maximum detection distance
- local setting = Settings.MaximumDetectionDistance.Value
- if setting < 0 then
- return math.huge
- else
- return setting
- end
- end
- function Monster:SearchForTarget()
- -- Finds the closest player and sets the target
- local players = Info.Players:GetPlayers()
- local closestCharacter, closestCharacterDistance
- for i=1, #players do
- local player = players[i]
- if player.Neutral or player.TeamColor ~= Settings.FriendlyTeam.Value then
- local character = player.Character
- if character ~= nil and character:FindFirstChild('Humanoid') ~= nil and character.Humanoid:IsA('Humanoid') then
- local distance = player:DistanceFromCharacter(Monster:GetCFrame().p)
- if distance < Monster:GetMaximumDetectionDistance() then
- if closestCharacter == nil then
- closestCharacter, closestCharacterDistance = character, distance
- else
- if closestCharacterDistance > distance then
- closestCharacter, closestCharacterDistance = character, distance
- end
- end
- end
- end
- end
- end
- if closestCharacter ~= nil then
- Mind.CurrentTargetHumanoid.Value = closestCharacter.Humanoid
- end
- end
- function Monster:TryRecomputePath()
- if Data.AutoRecompute or tick() - Data.LastRecomputePath > 1/Info.RecomputePathFrequency then
- Monster:RecomputePath()
- end
- end
- function Monster:GetTargetCFrame()
- local targetHumanoid = Mind.CurrentTargetHumanoid.Value
- if Monster:TargetIsValid() then
- return targetHumanoid.Torso.CFrame
- else
- return CFrame.new()
- end
- end
- function Monster:IsAlive()
- return Self.Humanoid.Health > 0 and Self.Humanoid.Torso ~= nil
- end
- function Monster:TargetIsValid()
- local targetHumanoid = Mind.CurrentTargetHumanoid.Value
- if targetHumanoid ~= nil and targetHumanoid:IsA 'Humanoid' and targetHumanoid.Torso ~= nil and targetHumanoid.Torso:IsA 'BasePart' then
- return true
- else
- return false
- end
- end
- function Monster:HasClearLineOfSight()
- -- Going to cast a ray to see if I can just see my target
- local myPos, targetPos = Monster:GetCFrame().p, Monster:GetTargetCFrame().p
- local hit, pos = Workspace:FindPartOnRayWithIgnoreList(
- Ray.new(
- myPos,
- targetPos - myPos
- ),
- {
- Self,
- Mind.CurrentTargetHumanoid.Value.Parent
- }
- )
- if hit == nil then
- return true
- else
- return false
- end
- end
- function Monster:RecomputePath()
- if not Data.Recomputing then
- if Monster:IsAlive() and Monster:TargetIsValid() then
- if Monster:HasClearLineOfSight() then
- Data.AutoRecompute = true
- Data.PathCoords = {
- Monster:GetCFrame().p,
- Monster:GetTargetCFrame().p
- }
- Data.LastRecomputePath = tick()
- Data.CurrentNode = nil
- Data.CurrentNodeIndex = 2 -- Starts chasing the target without evaluating its current position
- else
- -- Do pathfinding since you can't walk straight
- Data.Recomputing = true -- Basically a debounce.
- Data.AutoRecompute = false
- local path = Info.PathfindingService:ComputeSmoothPathAsync(
- Monster:GetCFrame().p,
- Monster:GetTargetCFrame().p,
- 500
- )
- Data.PathCoords = path:GetPointCoordinates()
- Data.Recomputing = false
- Data.LastRecomputePath = tick()
- Data.CurrentNode = nil
- Data.CurrentNodeIndex = 1
- end
- end
- end
- end
- function Monster:Update()
- Monster:ReevaluateTarget()
- Monster:SearchForTarget()
- Monster:TryRecomputePath()
- Monster:TravelPath()
- end
- function Monster:TravelPath()
- local closest, closestDistance, closestIndex
- local myPosition = Monster:GetCFrame().p
- local skipCurrentNode = Data.CurrentNode ~= nil and (Data.CurrentNode - myPosition).magnitude < 3
- for i=Data.CurrentNodeIndex, #Data.PathCoords do
- local coord = Data.PathCoords[i]
- if not (skipCurrentNode and coord == Data.CurrentNode) then
- local distance = (coord - myPosition).magnitude
- if closest == nil then
- closest, closestDistance, closestIndex = coord, distance, i
- else
- if distance < closestDistance then
- closest, closestDistance, closestIndex = coord, distance, i
- else
- break
- end
- end
- end
- end
- --
- if closest ~= nil then
- Data.CurrentNode = closest
- Data.CurrentNodeIndex = closestIndex
- local humanoid = Self:FindFirstChild 'Humanoid'
- if humanoid ~= nil and humanoid:IsA'Humanoid' then
- humanoid:MoveTo(closest)
- end
- if Monster:IsAlive() and Monster:TargetIsValid() then
- Monster:TryJumpCheck()
- Monster:TryAttack()
- end
- if closestIndex == #Data.PathCoords then
- -- Reached the end of the path, force a new check
- Data.AutoRecompute = true
- end
- end
- end
- function Monster:TryJumpCheck()
- if tick() - Data.LastJumpCheck > 1/Info.JumpCheckFrequency then
- Monster:JumpCheck()
- end
- end
- function Monster:TryAttack()
- if tick() - Data.LastAttack > 1/Settings.AttackFrequency.Value then
- Monster:Attack()
- end
- end
- function Monster:Attack()
- local myPos, targetPos = Monster:GetCFrame().p, Monster:GetTargetCFrame().p
- if (myPos - targetPos).magnitude <= Settings.AttackRange.Value then
- Mind.CurrentTargetHumanoid.Value:TakeDamage(Settings.AttackDamage.Value)
- Data.LastAttack = tick()
- Data.AttackTrack:Play()
- end
- end
- function Monster:JumpCheck()
- -- Do a raycast to check if we need to jump
- local myCFrame = Monster:GetCFrame()
- local checkVector = (Monster:GetTargetCFrame().p - myCFrame.p).unit*2
- local hit, pos = Workspace:FindPartOnRay(
- Ray.new(
- myCFrame.p + Vector3.new(0, -2.4, 0),
- checkVector
- ),
- Self
- )
- if hit ~= nil and not hit:IsDescendantOf(Mind.CurrentTargetHumanoid.Value.Parent) then
- -- Do a slope check to make sure we're not walking up a ramp
- local hit2, pos2 = Workspace:FindPartOnRay(
- Ray.new(
- myCFrame.p + Vector3.new(0, -2.3, 0),
- checkVector
- ),
- Self
- )
- if hit2 == hit then
- if ((pos2 - pos)*Vector3.new(1,0,1)).magnitude < 0.05 then -- Will pass for any ramp with <2 slope
- Self.Humanoid.Jump = true
- end
- end
- end
- Data.LastJumpCheck = tick()
- end
- function Monster:Connect()
- Mind.CurrentTargetHumanoid.Changed:connect(function(humanoid)
- if humanoid ~= nil then
- assert(humanoid:IsA'Humanoid', 'Monster target must be a humanoid')
- Monster:RecomputePath()
- end
- end)
- Self.Respawn.OnInvoke = function(point)
- Monster:Respawn(point)
- end
- end
- function Monster:Initialize()
- Monster:Connect()
- if Settings.AutoDetectSpawnPoint.Value then
- Settings.SpawnPoint.Value = Monster:GetCFrame().p
- end
- end
- function Monster:Respawn(point)
- local point = point or Settings.SpawnPoint.Value
- for index, obj in next, Data.BaseMonster:Clone():GetChildren() do
- if obj.Name == 'Configurations' or obj.Name == 'Mind' or obj.Name == 'Respawned' or obj.Name == 'Died' or obj.Name == 'MonsterScript' or obj.Name == 'Respawn' then
- obj:Destroy()
- else
- Self[obj.Name]:Destroy()
- obj.Parent = Self
- end
- end
- Monster:InitializeUnique()
- Self.Parent = Workspace
- Self.HumanoidRootPart.CFrame = CFrame.new(point)
- Settings.SpawnPoint.Value = point
- Self.Respawned:Fire()
- end
- function Monster:InitializeUnique()
- Data.AttackTrack = Self.Humanoid:LoadAnimation(script.Attack)
- end
- function Monster:ReevaluateTarget()
- local currentTarget = Mind.CurrentTargetHumanoid.Value
- if currentTarget ~= nil and currentTarget:IsA'Humanoid' then
- local character = currentTarget.Parent
- if character ~= nil then
- local player = Info.Players:GetPlayerFromCharacter(character)
- if player ~= nil then
- if not player.Neutral and player.TeamColor == Settings.FriendlyTeam.Value then
- Mind.CurrentTargetHumanoid.Value = nil
- end
- end
- end
- if currentTarget == Mind.CurrentTargetHumanoid.Value then
- local torso = currentTarget.Torso
- if torso ~= nil and torso:IsA 'BasePart' then
- if Settings.CanGiveUp.Value and (torso.Position - Monster:GetCFrame().p).magnitude > Monster:GetMaximumDetectionDistance() then
- Mind.CurrentTargetHumanoid.Value = nil
- end
- end
- end
- end
- end
- --
- --
- Monster:Initialize()
- Monster:InitializeUnique()
- while true do
- if not Monster:IsAlive() then
- if Data.IsDead == false then
- Data.IsDead = true
- Data.TimeOfDeath = tick()
- Self.Died:Fire()
- end
- if Data.IsDead == true then
- if tick()-Data.TimeOfDeath > Info.RespawnWaitTime then
- Monster:Respawn()
- end
- end
- end
- if Monster:IsAlive() then
- Monster:Update()
- end
- wait()
- end
- end,o40)
- end))
- o41.Name = "Attack"
- o41.Parent = o40
- o41.AnimationId = "http://www.roblox.com/asset?id=190149431"
- o42.Name = "Configurations"
- o42.Parent = o1
- o43.Name = "MaximumDetectionDistance"
- o43.Parent = o42
- o43.Value = 200
- o44.Name = "CanGiveUp"
- o44.Parent = o42
- o44.Value = true
- o45.Name = "CanRespawn"
- o45.Parent = o42
- o45.Value = true
- o46.Name = "SpawnPoint"
- o46.Parent = o42
- o47.Name = "AutoDetectSpawnPoint"
- o47.Parent = o42
- o47.Value = true
- o48.Name = "FriendlyTeam"
- o48.Parent = o42
- o48.Value = BrickColor.new("Dark green")
- o49.Name = "AttackDamage"
- o49.Parent = o42
- o50.Name = "AttackFrequency"
- o50.Parent = o42
- o50.Value = 2
- o51.Name = "AttackRange"
- o51.Parent = o42
- o51.Value = 3
- o52.Name = "Mind"
- o52.Parent = o1
- o53.Name = "CurrentTargetHumanoid"
- o53.Parent = o52
- o54.Name = "Died"
- o54.Parent = o1
- o55.Name = "Respawn"
- o55.Parent = o1
- o56.Name = "Respawned"
- o56.Parent = o1
- mas.Parent = workspace
- mas:MakeJoints()
- local mas1 = mas:GetChildren()
- for i=1,#mas1 do
- mas1[i].Parent = script
- ypcall(function() mas1[i]:MakeJoints() end)
- end
- mas:Destroy()
- for i=1,#cors do
- coroutine.resume(cors[i])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement