Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Converted with ttyyuu12345's model to script plugin v4
- function sandbox(var,func)
- local env = getfenv(func)
- local newenv = setmetatable({},{
- __index = function(self,k)
- if k=="script" then
- return var
- else
- return env[k]
- end
- end,
- })
- setfenv(func,newenv)
- return func
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- Model0 = Instance.new("Model")
- Part1 = Instance.new("Part")
- Motor6D2 = Instance.new("Motor6D")
- Part3 = Instance.new("Part")
- Motor6D4 = Instance.new("Motor6D")
- Motor6D5 = Instance.new("Motor6D")
- Motor6D6 = Instance.new("Motor6D")
- Motor6D7 = Instance.new("Motor6D")
- BodyForce8 = Instance.new("BodyForce")
- Motor6D9 = Instance.new("Motor6D")
- Part10 = Instance.new("Part")
- Part11 = Instance.new("Part")
- Part12 = Instance.new("Part")
- Part13 = Instance.new("Part")
- Part14 = Instance.new("Part")
- SpecialMesh15 = Instance.new("SpecialMesh")
- Humanoid16 = Instance.new("Humanoid")
- Script17 = Instance.new("Script")
- StringValue18 = Instance.new("StringValue")
- Animation19 = Instance.new("Animation")
- StringValue20 = Instance.new("StringValue")
- Animation21 = Instance.new("Animation")
- StringValue22 = Instance.new("StringValue")
- Animation23 = Instance.new("Animation")
- NumberValue24 = Instance.new("NumberValue")
- Animation25 = Instance.new("Animation")
- NumberValue26 = Instance.new("NumberValue")
- StringValue27 = Instance.new("StringValue")
- Animation28 = Instance.new("Animation")
- StringValue29 = Instance.new("StringValue")
- Animation30 = Instance.new("Animation")
- StringValue31 = Instance.new("StringValue")
- Animation32 = Instance.new("Animation")
- StringValue33 = Instance.new("StringValue")
- Animation34 = Instance.new("Animation")
- Script35 = Instance.new("Script")
- BillboardGui36 = Instance.new("BillboardGui")
- TextLabel37 = Instance.new("TextLabel")
- Configuration38 = Instance.new("Configuration")
- ModuleScript39 = Instance.new("ModuleScript")
- ModuleScript40 = Instance.new("ModuleScript")
- ModuleScript41 = Instance.new("ModuleScript")
- ModuleScript42 = Instance.new("ModuleScript")
- ModuleScript43 = Instance.new("ModuleScript")
- ModuleScript44 = Instance.new("ModuleScript")
- Configuration45 = Instance.new("Configuration")
- IntValue46 = Instance.new("IntValue")
- BoolValue47 = Instance.new("BoolValue")
- IntValue48 = Instance.new("IntValue")
- IntValue49 = Instance.new("IntValue")
- Configuration50 = Instance.new("Configuration")
- Animation51 = Instance.new("Animation")
- Animation52 = Instance.new("Animation")
- CharacterMesh53 = Instance.new("CharacterMesh")
- CharacterMesh54 = Instance.new("CharacterMesh")
- CharacterMesh55 = Instance.new("CharacterMesh")
- CharacterMesh56 = Instance.new("CharacterMesh")
- CharacterMesh57 = Instance.new("CharacterMesh")
- Sound58 = Instance.new("Sound")
- BodyColors59 = Instance.new("BodyColors")
- Script60 = Instance.new("Script")
- MeshPart61 = Instance.new("MeshPart")
- Model0.Name = "Drooling Zombie"
- Model0.Parent = mas
- Part1.Name = "HumanoidRootPart"
- Part1.Parent = Model0
- Part1.CFrame = CFrame.new(-28.6997967, 3.010041, 13.4000378, 4.49431016e-21, -6.795317e-22, -1, 4.72532479e-22, 1, -6.795317e-22, 1, -4.72532479e-22, 4.49431016e-21)
- Part1.Orientation = Vector3.new(0, -90, 0)
- Part1.Position = Vector3.new(-28.6997967, 3.010041, 13.4000378)
- Part1.Rotation = Vector3.new(0, -90, 0)
- Part1.Color = Color3.new(0.152941, 0.27451, 0.176471)
- Part1.Transparency = 1
- Part1.Size = Vector3.new(2, 2, 1)
- Part1.BottomSurface = Enum.SurfaceType.Smooth
- Part1.BrickColor = BrickColor.new("Earth green")
- Part1.Material = Enum.Material.WoodPlanks
- Part1.TopSurface = Enum.SurfaceType.Smooth
- Part1.brickColor = BrickColor.new("Earth green")
- Part1.FormFactor = Enum.FormFactor.Symmetric
- Part1.formFactor = Enum.FormFactor.Symmetric
- Motor6D2.Name = "Root Hip"
- Motor6D2.Parent = Part1
- Motor6D2.MaxVelocity = 0.10000000149012
- Motor6D2.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- Motor6D2.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- Motor6D2.Part0 = Part1
- Motor6D2.Part1 = Part3
- Motor6D2.part1 = Part3
- Part3.Name = "Torso"
- Part3.Parent = Model0
- Part3.CFrame = CFrame.new(-28.6997967, 3.010041, 13.4000378, 4.49431016e-21, -6.795317e-22, -1, 4.72532479e-22, 1, -6.795317e-22, 1, -4.72532479e-22, 4.49431016e-21)
- Part3.Orientation = Vector3.new(0, -90, 0)
- Part3.Position = Vector3.new(-28.6997967, 3.010041, 13.4000378)
- Part3.Rotation = Vector3.new(0, -90, 0)
- Part3.Color = Color3.new(0.156863, 0.498039, 0.278431)
- Part3.Transparency = 1
- Part3.Size = Vector3.new(2, 2, 1)
- Part3.BottomSurface = Enum.SurfaceType.Smooth
- Part3.BrickColor = BrickColor.new("Dark green")
- Part3.Material = Enum.Material.WoodPlanks
- Part3.TopSurface = Enum.SurfaceType.Smooth
- Part3.brickColor = BrickColor.new("Dark green")
- Part3.FormFactor = Enum.FormFactor.Symmetric
- Part3.formFactor = Enum.FormFactor.Symmetric
- Motor6D4.Name = "Left Hip"
- Motor6D4.Parent = Part3
- Motor6D4.MaxVelocity = 0.10000000149012
- Motor6D4.C0 = CFrame.new(-1, -1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- Motor6D4.C1 = CFrame.new(-0.5, 1, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- Motor6D4.Part0 = Part3
- Motor6D4.Part1 = Part10
- Motor6D4.part1 = Part10
- Motor6D5.Name = "Left Shoulder"
- Motor6D5.Parent = Part3
- Motor6D5.MaxVelocity = 0.10000000149012
- Motor6D5.C0 = CFrame.new(-1, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- Motor6D5.C1 = CFrame.new(0.5, 0.5, 0, -4.37113883e-08, 0, -1, 0, 0.99999994, 0, 1, 0, -4.37113883e-08)
- Motor6D5.Part0 = Part3
- Motor6D5.Part1 = Part12
- Motor6D5.part1 = Part12
- Motor6D6.Name = "Right Shoulder"
- Motor6D6.Parent = Part3
- Motor6D6.MaxVelocity = 0.10000000149012
- Motor6D6.C0 = CFrame.new(1, 0.5, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- Motor6D6.C1 = CFrame.new(-0.5, 0.5, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- Motor6D6.Part0 = Part3
- Motor6D6.Part1 = Part13
- Motor6D6.part1 = Part13
- Motor6D7.Name = "Neck"
- Motor6D7.Parent = Part3
- Motor6D7.MaxVelocity = 0.10000000149012
- Motor6D7.C0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- Motor6D7.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
- Motor6D7.Part0 = Part3
- Motor6D7.Part1 = Part14
- Motor6D7.part1 = Part14
- BodyForce8.Name = "RepulsionForce"
- BodyForce8.Parent = Part3
- BodyForce8.Force = Vector3.new(0, 0, 0)
- BodyForce8.force = Vector3.new(0, 0, 0)
- Motor6D9.Name = "Right Hip"
- Motor6D9.Parent = Part3
- Motor6D9.MaxVelocity = 0.10000000149012
- Motor6D9.C0 = CFrame.new(1, -1, 0, -4.37113883e-08, 0, 1, -0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- Motor6D9.C1 = CFrame.new(0.5, 1, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08)
- Motor6D9.Part0 = Part3
- Motor6D9.Part1 = Part11
- Motor6D9.part1 = Part11
- Part10.Name = "Left Leg"
- Part10.Parent = Model0
- Part10.CFrame = CFrame.new(-28.6997967, 1.01004112, 12.9000378, 4.49431016e-21, -6.795316e-22, -1, 4.72532479e-22, 0.999999881, -6.795317e-22, 1, -4.72532428e-22, 4.49431016e-21)
- Part10.Orientation = Vector3.new(0, -90, 0)
- Part10.Position = Vector3.new(-28.6997967, 1.01004112, 12.9000378)
- Part10.Rotation = Vector3.new(0, -90, 0)
- Part10.Color = Color3.new(0.0509804, 0.411765, 0.67451)
- Part10.Transparency = 1
- Part10.Size = Vector3.new(1, 2, 1)
- Part10.BottomSurface = Enum.SurfaceType.Smooth
- Part10.BrickColor = BrickColor.new("Bright blue")
- Part10.CanCollide = false
- Part10.Material = Enum.Material.WoodPlanks
- Part10.TopSurface = Enum.SurfaceType.Smooth
- Part10.brickColor = BrickColor.new("Bright blue")
- Part10.FormFactor = Enum.FormFactor.Symmetric
- Part10.formFactor = Enum.FormFactor.Symmetric
- Part11.Name = "Right Leg"
- Part11.Parent = Model0
- Part11.CFrame = CFrame.new(-28.6997967, 1.01004112, 13.9000378, 4.49431016e-21, -6.795316e-22, -1, 4.72532479e-22, 0.999999881, -6.795317e-22, 1, -4.72532428e-22, 4.49431016e-21)
- Part11.Orientation = Vector3.new(0, -90, 0)
- Part11.Position = Vector3.new(-28.6997967, 1.01004112, 13.9000378)
- Part11.Rotation = Vector3.new(0, -90, 0)
- Part11.Color = Color3.new(0.0509804, 0.411765, 0.67451)
- Part11.Transparency = 1
- Part11.Size = Vector3.new(1, 2, 1)
- Part11.BottomSurface = Enum.SurfaceType.Smooth
- Part11.BrickColor = BrickColor.new("Bright blue")
- Part11.CanCollide = false
- Part11.Material = Enum.Material.WoodPlanks
- Part11.TopSurface = Enum.SurfaceType.Smooth
- Part11.brickColor = BrickColor.new("Bright blue")
- Part11.FormFactor = Enum.FormFactor.Symmetric
- Part11.formFactor = Enum.FormFactor.Symmetric
- Part12.Name = "Left Arm"
- Part12.Parent = Model0
- Part12.CFrame = CFrame.new(-28.6997967, 3.010041, 11.9000378, 4.49431016e-21, -6.795316e-22, -1, 4.72532479e-22, 0.999999881, -6.795317e-22, 1, -4.72532428e-22, 4.49431016e-21)
- Part12.Orientation = Vector3.new(0, -90, 0)
- Part12.Position = Vector3.new(-28.6997967, 3.010041, 11.9000378)
- Part12.Rotation = Vector3.new(0, -90, 0)
- Part12.Color = Color3.new(0.992157, 0.917647, 0.552941)
- Part12.Transparency = 1
- Part12.Size = Vector3.new(1, 2, 1)
- Part12.BottomSurface = Enum.SurfaceType.Smooth
- Part12.BrickColor = BrickColor.new("Cool yellow")
- Part12.CanCollide = false
- Part12.Material = Enum.Material.WoodPlanks
- Part12.TopSurface = Enum.SurfaceType.Smooth
- Part12.brickColor = BrickColor.new("Cool yellow")
- Part12.FormFactor = Enum.FormFactor.Symmetric
- Part12.formFactor = Enum.FormFactor.Symmetric
- Part13.Name = "Right Arm"
- Part13.Parent = Model0
- Part13.CFrame = CFrame.new(-28.6997967, 3.010041, 14.9000378, 4.49431016e-21, -6.795316e-22, -1, 4.72532479e-22, 0.999999881, -6.795317e-22, 1, -4.72532428e-22, 4.49431016e-21)
- Part13.Orientation = Vector3.new(0, -90, 0)
- Part13.Position = Vector3.new(-28.6997967, 3.010041, 14.9000378)
- Part13.Rotation = Vector3.new(0, -90, 0)
- Part13.Color = Color3.new(0.992157, 0.917647, 0.552941)
- Part13.Transparency = 1
- Part13.Size = Vector3.new(1, 2, 1)
- Part13.BottomSurface = Enum.SurfaceType.Smooth
- Part13.BrickColor = BrickColor.new("Cool yellow")
- Part13.CanCollide = false
- Part13.Material = Enum.Material.WoodPlanks
- Part13.TopSurface = Enum.SurfaceType.Smooth
- Part13.brickColor = BrickColor.new("Cool yellow")
- Part13.FormFactor = Enum.FormFactor.Symmetric
- Part13.formFactor = Enum.FormFactor.Symmetric
- Part14.Name = "Head"
- Part14.Parent = Model0
- Part14.CFrame = CFrame.new(-28.6997967, 4.51004124, 13.4000378, 4.49431016e-21, -6.795317e-22, -1, 4.72532479e-22, 1, -6.795317e-22, 1, -4.72532479e-22, 4.49431016e-21)
- Part14.Orientation = Vector3.new(0, -90, 0)
- Part14.Position = Vector3.new(-28.6997967, 4.51004124, 13.4000378)
- Part14.Rotation = Vector3.new(0, -90, 0)
- Part14.Color = Color3.new(0.992157, 0.917647, 0.552941)
- Part14.Transparency = 1
- Part14.Size = Vector3.new(2, 1, 1)
- Part14.BottomSurface = Enum.SurfaceType.Smooth
- Part14.BrickColor = BrickColor.new("Cool yellow")
- Part14.Material = Enum.Material.WoodPlanks
- Part14.TopSurface = Enum.SurfaceType.Smooth
- Part14.brickColor = BrickColor.new("Cool yellow")
- Part14.FormFactor = Enum.FormFactor.Symmetric
- Part14.formFactor = Enum.FormFactor.Symmetric
- SpecialMesh15.Parent = Part14
- SpecialMesh15.Scale = Vector3.new(1.25, 1.25, 1.25)
- Humanoid16.Parent = Model0
- Humanoid16.Health = inf
- Humanoid16.Jump = true
- Humanoid16.LeftLeg = Part10
- Humanoid16.MaxHealth = inf
- Humanoid16.RightLeg = Part11
- Humanoid16.Torso = Part1
- Humanoid16.WalkSpeed = 26
- Humanoid16.maxHealth = inf
- Script17.Name = "Animate"
- Script17.Parent = Model0
- table.insert(cors,sandbox(Script17,function()
- 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 currentAnimTrack = nil
- local currentAnimKeyframeHandler = nil
- local currentAnimSpeed = 1.0
- local animTable = {}
- local animNames = {
- idle = {
- { id = "http://www.roblox.com/asset/?id=125750544", weight = 9 },
- { id = "http://www.roblox.com/asset/?id=125750618", weight = 1 }
- },
- walk = {
- { id = "http://www.roblox.com/asset/?id=125749145", 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=125750759", weight = 10 }
- },
- climb = {
- { id = "http://www.roblox.com/asset/?id=125750800", weight = 10 }
- },
- toolnone = {
- { id = "http://www.roblox.com/asset/?id=125750867", 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=130018893", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=132546839", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=132546884", weight = 10 }
- },
- dance2 = {
- { id = "http://www.roblox.com/asset/?id=160934142", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=160934298", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=160934376", weight = 10 }
- },
- dance3 = {
- { id = "http://www.roblox.com/asset/?id=160934458", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=160934530", weight = 10 },
- { id = "http://www.roblox.com/asset/?id=160934593", weight = 10 }
- },
- laugh = {
- { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
- },
- cheer = {
- { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
- },
- }
- -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
- local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
- 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
- -- return to idle if finishing an emote
- if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
- oldAnim = "idle"
- end
- currentAnim = ""
- 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 = stopAllAnimations()
- local animSpeed = currentAnimSpeed
- playAnimation(repeatAnim, 0.0, Humanoid)
- setAnimationSpeed(animSpeed)
- end
- end
- -- Preload animations
- function playAnimation(animName, transitionTime, humanoid)
- local idleFromEmote = (animName == "idle" and emoteNames[currentAnim] ~= nil)
- if (animName ~= currentAnim and not idleFromEmote) then
- if (currentAnimTrack ~= nil) then
- currentAnimTrack:Stop(transitionTime)
- currentAnimTrack:Destroy()
- end
- currentAnimSpeed = 1.0
- 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
- -- load it to the humanoid; get AnimationTrack
- currentAnimTrack = humanoid:LoadAnimation(anim)
- -- play the animation
- currentAnimTrack:Play(transitionTime)
- currentAnim = animName
- -- 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 currentToolAnimKeyframeHandler = nil
- function toolKeyFrameReachedFunc(frameName)
- if (frameName == "End") then
- -- print("Keyframe : ".. frameName)
- local repeatAnim = stopToolAnimations()
- playToolAnimation(repeatAnim, 0.0, Humanoid)
- end
- end
- function playToolAnimation(animName, transitionTime, humanoid)
- if (animName ~= toolAnimName) then
- if (toolAnimTrack ~= nil) then
- toolAnimTrack:Stop()
- toolAnimTrack:Destroy()
- transitionTime = 0
- end
- 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
- -- load it to the humanoid; get AnimationTrack
- toolAnimTrack = humanoid:LoadAnimation(anim)
- -- play the animation
- toolAnimTrack:Play(transitionTime)
- toolAnimName = animName
- currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
- end
- end
- function stopToolAnimations()
- local oldAnim = toolAnimName
- if (currentToolAnimKeyframeHandler ~= nil) then
- currentToolAnimKeyframeHandler:disconnect()
- end
- toolAnimName = ""
- 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
- stopAllAnimations()
- moveSit()
- 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)
- 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"
- 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))
- StringValue18.Name = "climb"
- StringValue18.Parent = Script17
- Animation19.Name = "ClimbAnim"
- Animation19.Parent = StringValue18
- Animation19.AnimationId = "http://www.roblox.com/asset/?id=125750800"
- StringValue20.Name = "fall"
- StringValue20.Parent = Script17
- Animation21.Name = "FallAnim"
- Animation21.Parent = StringValue20
- Animation21.AnimationId = "http://www.roblox.com/asset/?id=125750759"
- StringValue22.Name = "idle"
- StringValue22.Parent = Script17
- Animation23.Name = "Animation1"
- Animation23.Parent = StringValue22
- Animation23.AnimationId = "http://www.roblox.com/asset/?id=125750544"
- NumberValue24.Name = "Weight"
- NumberValue24.Parent = Animation23
- NumberValue24.Value = 9
- Animation25.Name = "Animation2"
- Animation25.Parent = StringValue22
- Animation25.AnimationId = "http://www.roblox.com/asset/?id=125750618"
- NumberValue26.Name = "Weight"
- NumberValue26.Parent = Animation25
- NumberValue26.Value = 1
- StringValue27.Name = "jump"
- StringValue27.Parent = Script17
- Animation28.Name = "JumpAnim"
- Animation28.Parent = StringValue27
- Animation28.AnimationId = "http://www.roblox.com/asset/?id=125750702"
- StringValue29.Name = "run"
- StringValue29.Parent = Script17
- Animation30.Name = "RunAnim"
- Animation30.Parent = StringValue29
- Animation30.AnimationId = "http://www.roblox.com/asset/?id=125749145"
- StringValue31.Name = "toolnone"
- StringValue31.Parent = Script17
- Animation32.Name = "ToolNoneAnim"
- Animation32.Parent = StringValue31
- Animation32.AnimationId = "http://www.roblox.com/asset/?id=125750867"
- StringValue33.Name = "walk"
- StringValue33.Parent = Script17
- Animation34.Name = "WalkAnim"
- Animation34.Parent = StringValue33
- Animation34.AnimationId = "http://www.roblox.com/asset/?id=125749145"
- Script35.Parent = Model0
- table.insert(cors,sandbox(Script35,function()
- local zombie = script.Parent
- for _, script in pairs(zombie.ModuleScripts:GetChildren()) do
- if not game.ServerStorage:FindFirstChild(script.Name) then
- script:Clone().Parent = game.ServerStorage
- end
- end
- local AI = require(game.ServerStorage.ROBLOX_ZombieAI).new(zombie)
- local DestroyService = require(game.ServerStorage.ROBLOX_DestroyService)
- local function clearParts(parent)
- for _, part in pairs(parent:GetChildren()) do
- clearParts(part)
- end
- local delay
- if parent:IsA("Part") then
- delay = math.random(5,10)
- else
- delay = 11
- end
- DestroyService:AddItem(parent, delay)
- end
- zombie.Humanoid.Died:connect(function()
- AI.Stop()
- math.randomseed(tick())
- clearParts(zombie)
- script.Disabled = true
- end)
- local lastMoan = os.time()
- math.randomseed(os.time())
- while true do
- local animationTrack = zombie.Humanoid:LoadAnimation(zombie.Animations.Arms)
- animationTrack:Play()
- -- local now = os.time()
- -- if now - lastMoan > 5 then
- -- if math.random() > .3 then
- -- zombie.Moan:Play()
- ---- print("playing moan")
- -- lastMoan = now
- -- end
- -- end
- wait(2)
- end
- end))
- BillboardGui36.Parent = Model0
- BillboardGui36.Size = UDim2.new(0, 100, 0, 30)
- BillboardGui36.StudsOffset = Vector3.new(0, 5, 0)
- TextLabel37.Parent = BillboardGui36
- TextLabel37.Visible = false
- TextLabel37.Size = UDim2.new(1, 0, 1, 0)
- TextLabel37.BackgroundColor = BrickColor.new("Institutional white")
- TextLabel37.BackgroundColor3 = Color3.new(1, 1, 1)
- TextLabel37.Font = Enum.Font.SourceSansBold
- TextLabel37.FontSize = Enum.FontSize.Size24
- TextLabel37.Text = "Idle"
- TextLabel37.TextSize = 24
- Configuration38.Name = "ModuleScripts"
- Configuration38.Parent = Model0
- ModuleScript39.Name = "ROBLOX_AIUtilities"
- ModuleScript39.Parent = Configuration38
- table.insert(cors,sandbox(ModuleScript39,function()
- local utility = {}
- function utility:WideRayCast(start, target, offset, ignoreList)
- local parts = {}
- local ray = Ray.new(start, target - start)
- local part, point = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
- if part then table.insert(parts, part) end
- local offsetVector = offset * (target - start):Cross(Vector3.FromNormalId(Enum.NormalId.Top)).unit
- local ray = Ray.new(start + offsetVector, target - start + offsetVector)
- local part, point = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
- if part then table.insert(parts, part) end
- local ray = Ray.new(start - offsetVector, target - start - offsetVector)
- local part, point = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
- if part then table.insert(parts, part) end
- return parts
- end
- function utility:FindNearestPathPoint(path, point, start, target, ignoreList)
- local occludePoint = path:CheckOcclusionAsync(point)
- if occludePoint > 0 then
- utility:WideRayCast(start)
- end
- end
- local maxForce = 75
- function utility:GetRepulsionVector(unitPosition, otherUnitsPositions)
- local repulsionVector = Vector3.new(0,0,0)
- local count = 0
- for _, other in pairs(otherUnitsPositions) do
- local fromOther = unitPosition - other
- --fromOther = fromOther.unit * ((-maxForce / 5) * math.pow(fromOther.magnitude,2) + maxForce)
- fromOther = fromOther.unit * 1000 / math.pow((fromOther.magnitude + 1), 2)
- repulsionVector = repulsionVector + fromOther
- end
- return repulsionVector * maxForce
- end
- function utility:GetIdleState(StateMachine)
- local IdleState = StateMachine.NewState()
- IdleState.Name = "Idle"
- IdleState.Action = function() end
- IdleState.Init = function() end
- return IdleState
- end
- function utility:GetClosestVisibleTarget(npcModel, characters, ignoreList, fieldOfView)
- local closestTarget = nil
- local closestDistance = math.huge
- for _, character in pairs(characters) do
- local toTarget = character.Torso.Position - npcModel.Torso.Position
- local toTargetWedge = toTarget * Vector3.new(1,0,1)
- local angle = math.acos(toTargetWedge:Dot(npcModel.Torso.CFrame.lookVector)/toTargetWedge.magnitude)
- if math.deg(angle) < fieldOfView then
- local targetRay = Ray.new(npcModel.Torso.Position, toTarget)
- local part, position = game.Workspace:FindPartOnRayWithIgnoreList(targetRay, ignoreList)
- if part and part.Parent == character then
- if toTarget.magnitude < closestDistance then
- closestTarget = character
- closestDistance = toTarget.magnitude
- end
- end
- end
- end
- return closestTarget
- end
- local function isSpaceEmpty(position)
- local region = Region3.new(position - Vector3.new(2,2,2), position + Vector3.new(2,2,2))
- return game.Workspace:IsRegion3Empty(region)
- end
- function utility:FindCloseEmptySpace(model)
- local targetPos = Vector3.new(0,0,0)
- local count = 0
- math.randomseed(os.time())
- repeat
- local xoff = math.random(5,10)
- if math.random() > .5 then
- xoff = xoff * -1
- end
- local zoff = math.random(5, 10)
- if math.random() > .5 then
- zoff = zoff * -1
- end
- targetPos = Vector3.new(model.Torso.Position.X + xoff,model.Torso.Position.Y,model.Torso.Position.Z + zoff)
- if isSpaceEmpty(targetPos) then
- return targetPos
- else
- targetPos = targetPos + Vector3.new(0,4,0)
- end
- if isSpaceEmpty(targetPos) then
- return targetPos
- end
- count = count + 1
- until count > 10
- return nil
- end
- return utility
- end))
- ModuleScript40.Name = "ROBLOX_DestroyService"
- ModuleScript40.Parent = Configuration38
- table.insert(cors,sandbox(ModuleScript40,function()
- local destroyService = {}
- local destroyQueue = {}
- function destroyService:AddItem(theobject, delay)
- local now = os.time()
- local destroyObject = {object = theobject, destroyTime = delay + now}
- for i, storedObject in pairs(destroyQueue) do
- if destroyQueue[i].destroyTime > destroyObject.destroyTime then
- table.insert(destroyQueue, i, destroyObject)
- return true
- end
- end
- table.insert(destroyQueue, destroyObject)
- return true
- end
- local updateThread = coroutine.create(function()
- while true do
- local now = os.time()
- for _, storedObject in pairs(destroyQueue) do
- if now >= storedObject.destroyTime then
- table.remove(destroyQueue, 1)
- if storedObject.object then
- storedObject.object:Destroy()
- end
- elseif now >= storedObject.destroyTime - 1 then
- if storedObject.object and storedObject.object:IsA("Part") then
- local trans = storedObject.object.Transparency + 1/30
- storedObject.object.Transparency = trans
- end
- else
- break
- end
- end
- wait()
- end
- end)
- coroutine.resume(updateThread)
- return destroyService
- end))
- ModuleScript41.Name = "ROBLOX_HumanoidList"
- ModuleScript41.Parent = Configuration38
- table.insert(cors,sandbox(ModuleScript41,function()
- local humanoidList = {}
- local storage = {}
- function humanoidList:GetCurrent()
- return storage
- end
- local function findHumanoids(object, list)
- if object then
- if object:IsA("Humanoid") then
- table.insert(list, object)
- end
- for _, child in pairs(object:GetChildren()) do
- local childList = findHumanoids(child, list)
- end
- end
- end
- local updateThread = coroutine.create(function()
- while true do
- storage = {}
- findHumanoids(game.Workspace, storage)
- wait(3)
- end
- end)
- coroutine.resume(updateThread)
- return humanoidList
- end))
- ModuleScript42.Name = "ROBLOX_StateMachine"
- ModuleScript42.Parent = Configuration38
- table.insert(cors,sandbox(ModuleScript42,function()
- local machine = {}
- machine.new = function()
- local StateMachine = {}
- StateMachine.WaitTime = .2
- StateMachine.CurrentState = nil
- StateMachine.SwitchState = function(newState)
- if StateMachine.CurrentState then
- StateMachine.CurrentState.Stop()
- end
- StateMachine.CurrentState = newState
- if newState then
- newState.Start()
- end
- end
- StateMachine.NewState = function()
- local state = {}
- state.Name = ""
- state.Conditions = {}
- state.isRunning = false
- state.Action = function() end
- state.Run = function()
- state.isRunning = true
- while state.isRunning do
- --check conditions
- --print("checking conditions")
- for _, condition in pairs(state.Conditions) do
- --print("Checking " .. condition.Name)
- if condition.Evaluate() then
- --print(condition.Name .. " is true. Switching states")
- StateMachine.SwitchState(condition.TransitionState)
- return
- end
- end
- --if no conditions satisfied, perform action
- state.Action()
- wait(StateMachine.WaitTime)
- end
- end
- state.Init = function()
- end
- state.Start = function()
- --print("Starting " .. state.Name)
- state.Init()
- local thread = coroutine.create(state.Run)
- coroutine.resume(thread)
- end
- state.Stop = function()
- --print("Stopping " .. state.Name)
- state.isRunning = false
- end
- return state
- end
- StateMachine.NewCondition = function()
- local condition = {}
- condition.Name = ""
- condition.Evaluate = function() print("replace me") return false end
- condition.TransitionState = {}
- return condition
- end
- return StateMachine
- end
- return machine
- end))
- ModuleScript43.Name = "ROBLOX_ZombieAI"
- ModuleScript43.Parent = Configuration38
- table.insert(cors,sandbox(ModuleScript43,function()
- --local PathLib = require(game.ServerStorage.PathfindingLibrary).new()
- local HumanoidList = require(game.ServerStorage.ROBLOX_HumanoidList)
- local AIUtilities = require(game.ServerStorage.ROBLOX_AIUtilities)
- local ZombieAI = {}
- function updateDisplay(display, state)
- local thread = coroutine.create(function()
- while true do
- wait()
- if state then
- display.Text = state.Name
- end
- end
- end)
- coroutine.resume(thread)
- end
- ZombieAI.new = function(model)
- local zombie = {}
- -- CONFIGURATION VARIABLES
- -- local AttackRange, FieldOfView, AggroRange, ChanceOfBoredom, BoredomDuration,
- -- Damage, DamageCooldown
- local configTable = model.Configurations
- local configs = {}
- local function loadConfig(configName, defaultValue)
- if configTable:FindFirstChild(configName) then
- configs[configName] = configTable:FindFirstChild(configName).Value
- else
- configs[configName] = defaultValue
- end
- end
- loadConfig("AttackRange", 3)
- loadConfig("FieldOfView", 180)
- loadConfig("AggroRange", 200)
- loadConfig("ChanceOfBoredom", .5)
- loadConfig("BoredomDuration", 10)
- loadConfig("Damage", 10)
- loadConfig("DamageCooldown", 1)
- local StateMachine = require(game.ServerStorage.ROBLOX_StateMachine).new()
- local PathLib = require(game.ServerStorage.ROBLOX_PathfindingLibrary).new()
- local ZombieTarget = nil
- local ZombieTargetLastLocation = nil
- local lastBored = os.time()
- -- STATE DEFINITIONS
- -- IdleState: NPC stays still. Refreshes bored timer when started to
- -- allow for random state change
- local IdleState = StateMachine.NewState()
- IdleState.Name = "Idle"
- IdleState.Action = function()
- end
- IdleState.Init = function()
- lastBored = os.time()
- end
- -- SearchState: NPC wanders randomly increasing chance of spotting
- -- enemy. Refreshed bored timer when started to allow for random state
- -- change
- local SearchState = StateMachine.NewState()
- SearchState.Name = "Search"
- local lastmoved = os.time()
- local searchTarget = nil
- SearchState.Action = function()
- -- move to random spot nearby
- if model then
- local now = os.time()
- if now - lastmoved > 2 then
- lastmoved = now
- local xoff = math.random(5, 10)
- if math.random() > .5 then
- xoff = xoff * -1
- end
- local zoff = math.random(5, 10)
- if math.random() > .5 then
- zoff = zoff * -1
- end
- local testtarg = AIUtilities:FindCloseEmptySpace(model)
- --if testtarg then print(testtarg) else print("could not find") end
- searchTarget = Vector3.new(model.Torso.Position.X + xoff,model.Torso.Position.Y,model.Torso.Position.Z + zoff)
- --local target = Vector3.new(model.Torso.Position.X + xoff,model.Torso.Position.Y,model.Torso.Position.Z + zoff)
- --model.Humanoid:MoveTo(target)
- searchTarget = testtarg
- end
- if searchTarget then
- PathLib:MoveToTarget(model, searchTarget)
- end
- end
- end
- SearchState.Init = function()
- lastBored = os.time()
- end
- -- PursueState: Enemy has been spotted, need to give chase.
- local PursueState = StateMachine.NewState()
- PursueState.Name = "Pursue"
- PursueState.Action = function()
- -- Double check we still have target
- if ZombieTarget then
- -- Get distance to target
- local distance = (model.Torso.Position - ZombieTarget.Torso.Position).magnitude
- -- If we're far from target use pathfinding to move. Otherwise just MoveTo
- if distance > configs["AttackRange"] + 5 then
- PathLib:MoveToTarget(model, ZombieTarget.Torso.Position)
- else
- model.Humanoid:MoveTo(ZombieTarget.Torso.Position)
- -- if ZombieTarget.Torso.Position.Y > model.Torso.Position.Y + 2 then
- -- model.Humanoid.Jump = true
- -- end
- end
- end
- end
- PursueState.Init = function()
- end
- -- AttackState: Keep moving towards target and play attack animation.
- local AttackState = StateMachine.NewState()
- AttackState.Name = "Attack"
- local lastAttack = os.time()
- local attackTrack = model.Humanoid:LoadAnimation(model.Animations.Attack)
- AttackState.Action = function()
- model.Humanoid:MoveTo(ZombieTarget.Torso.Position)
- local now = os.time()
- if now - lastAttack > 3 then
- lastAttack = now
- attackTrack:Play()
- end
- end
- -- HuntState: Can't see target but NPC will move to target's last known location.
- -- Will eventually get bored and switch state.
- local HuntState = StateMachine.NewState()
- HuntState.Name = "Hunt"
- HuntState.Action = function()
- if ZombieTargetLastLocation then
- PathLib:MoveToTarget(model, ZombieTargetLastLocation)
- end
- end
- HuntState.Init = function()
- lastBored = os.time() + configs["BoredomDuration"] / 2
- end
- -- CONDITION DEFINITIONS
- -- CanSeeTarget: Determines if a target is visible. Returns true if target is visible and
- -- sets current target. A target is valid if it is nearby, visible, has a Torso and WalkSpeed
- -- greater than 0 (this is to ignore inanimate objects that happen to use humanoids)
- local CanSeeTarget = StateMachine.NewCondition()
- CanSeeTarget.Name = "CanSeeTarget"
- CanSeeTarget.Evaluate = function()
- if model then
- -- Get list of all nearby Zombies and non-Zombie humanoids
- -- Zombie list is used to ignore zombies during later raycast
- local humanoids = HumanoidList:GetCurrent()
- local zombies = {}
- local characters = {}
- for _, object in pairs(humanoids) do
- if object and object.Parent and object.Parent:FindFirstChild("Torso") and object.Health > 0 and object.WalkSpeed > 0 then
- local torso = object.Parent:FindFirstChild("Torso")
- if torso then
- local distance = (model.Torso.Position - torso.Position).magnitude
- if distance <= configs["AggroRange"] then
- if object.Parent.Name == "Drooling Zombie" then
- table.insert(zombies, object.Parent)
- else
- table.insert(characters, object.Parent)
- end
- end
- end
- end
- end
- local target = AIUtilities:GetClosestVisibleTarget(model, characters, zombies, configs["FieldOfView"])
- if target then
- ZombieTarget = target
- return true
- end
- -- -- Go through each valid target to see if within field of view and if there is
- -- -- clear line of sight. Field of view treated as wedge in front of character.
- -- for _, character in pairs(characters) do
- -- local toTarget = (character.Torso.Position - model.Torso.Position)
- -- toTarget = Vector3.new(toTarget.X, 0, toTarget.Z)
- -- local angle = math.acos(toTarget:Dot(model.Torso.CFrame.lookVector)/toTarget.magnitude)
- -- if math.deg(angle) < configs["FieldOfView"]/2 then
- -- ZombieTarget = character
- -- -- raycast to see if target is actually visible
- -- local toTarget = Ray.new(model.Torso.Position, (ZombieTarget.Torso.Position - model.Torso.Position))
- -- local part, position = game.Workspace:FindPartOnRayWithIgnoreList(toTarget, zombies)
- -- if part and part.Parent == ZombieTarget then
- -- return true
- -- end
- -- ZombieTarget = nil
- -- end
- -- end
- end
- return false
- end
- CanSeeTarget.TransitionState = PursueState
- -- TargetDead: Check if target is dead.
- local TargetDead = StateMachine.NewCondition()
- TargetDead.Name = "TargetDead"
- TargetDead.Evaluate = function()
- if ZombieTarget and ZombieTarget.Humanoid then
- return ZombieTarget.Humanoid.Health <= 0
- end
- return true
- end
- TargetDead.TransitionState = IdleState
- -- GotDamaged: Check if NPC has taken damage
- local lastHealth = model.Humanoid.Health
- local GotDamaged = StateMachine.NewCondition()
- GotDamaged.Name = "GotDamaged"
- GotDamaged.Evaluate = function()
- if model then
- if lastHealth > model.Humanoid.Health then
- return true
- end
- end
- return false
- end
- GotDamaged.TransitionState = SearchState
- -- GotBored: Used to provide random state change.
- local GotBored = StateMachine.NewCondition()
- GotBored.Name = "GotBored"
- GotBored.Evaluate = function()
- local now = os.time()
- if now - lastBored > configs["BoredomDuration"] then
- local roll = math.random()
- if roll < configs["ChanceOfBoredom"] then
- lastBored = now
- if GotBored.TransitionState == SearchState then
- GotBored.TransitionState = IdleState
- else
- GotBored.TransitionState = SearchState
- end
- return true
- end
- end
- return false
- end
- GotBored.TransitionState = IdleState
- -- LostTarget: Checks clear line of sight
- local LostTarget = StateMachine.NewCondition()
- LostTarget.Name = "LostTarget"
- LostTarget.Evaluate = function()
- if true then return false end
- if ZombieTarget then
- if (ZombieTarget.Torso.Position - model.Torso.Position).magnitude > 10 then
- local toTarget = Ray.new(model.Torso.Position, (ZombieTarget.Torso.Position - model.Torso.Position))
- local part, position = game.Workspace:FindPartOnRay(toTarget, model)
- if not part or part.Parent ~= ZombieTarget then
- --print("Lost target!")
- ZombieTargetLastLocation = ZombieTarget.Torso.Position
- ZombieTarget = nil
- return true
- end
- end
- end
- return false
- end
- LostTarget.TransitionState = HuntState
- local WithinRange = StateMachine.NewCondition()
- WithinRange.Name = "WithinRange"
- WithinRange.Evaluate = function()
- if ZombieTarget then
- local distance = (model.Torso.Position - ZombieTarget.Torso.Position).magnitude
- if distance < configs["AttackRange"] then
- --print("Within attack range!")
- return true
- end
- end
- return false
- end
- WithinRange.TransitionState = AttackState
- local OutsideRange = StateMachine.NewCondition()
- OutsideRange.Name = "OutsideRange"
- OutsideRange.Evaluate = function()
- if ZombieTarget then
- local distance = (model.Torso.Position - ZombieTarget.Torso.Position).magnitude
- if distance > configs["AttackRange"] then
- --print("Outside attack range!")
- return true
- end
- end
- return false
- end
- OutsideRange.TransitionState = PursueState
- table.insert(IdleState.Conditions, CanSeeTarget)
- table.insert(IdleState.Conditions, GotDamaged)
- table.insert(IdleState.Conditions, GotBored)
- table.insert(SearchState.Conditions, GotBored)
- table.insert(SearchState.Conditions, CanSeeTarget)
- table.insert(PursueState.Conditions, LostTarget)
- table.insert(PursueState.Conditions, WithinRange)
- table.insert(PursueState.Conditions, TargetDead)
- table.insert(AttackState.Conditions, OutsideRange)
- table.insert(AttackState.Conditions, TargetDead)
- table.insert(HuntState.Conditions, GotBored)
- table.insert(HuntState.Conditions, CanSeeTarget)
- -- Setup arms damage
- local canHit = true
- local lastHit = os.time()
- local function handleHit(other)
- if canHit then
- if other and other.Parent and other.Parent.Name ~= "Drooling Zombie" and other.Parent:FindFirstChild("Humanoid") then
- local enemy = other.Parent
- if enemy.Humanoid.WalkSpeed > 0 then
- enemy.Humanoid.Health = enemy.Humanoid.Health - configs["Damage"]
- canHit = false
- end
- end
- else
- local now = os.time()
- if now - lastHit > configs["DamageCooldown"] then
- lastHit = now
- canHit = true
- end
- end
- end
- local leftHitConnect, rightHitConnect
- leftHitConnect = model:FindFirstChild("Left Arm").Touched:connect(handleHit)
- rightHitConnect = model:FindFirstChild("Right Arm").Touched:connect(handleHit)
- --ZombieAI.Animate(model)
- --updateDisplay()
- --updateDisplay(model.BillboardGui.TextLabel, StateMachine.CurrentState)
- local thread = coroutine.create(function()
- while true do
- wait()
- -- calculate repulsion force
- local humanoids = HumanoidList:GetCurrent()
- local localZombies = {}
- for _, humanoid in pairs(humanoids) do
- if humanoid and humanoid ~= model.Humanoid and humanoid.Parent and humanoid.Parent:FindFirstChild("Torso") then
- local torso = humanoid.Parent:FindFirstChild("Torso")
- local distance = (model.Torso.Position - torso.Position).magnitude
- if distance <= 2.5 then
- table.insert(localZombies, torso.Position)
- end
- end
- end
- local repulsionDirection = AIUtilities:GetRepulsionVector(model.Torso.Position, localZombies)
- if repulsionDirection.magnitude > 0 then
- --print("replusion direction: " .. tostring(repulsionDirection))
- end
- model.Torso.RepulsionForce.force = repulsionDirection
- if StateMachine.CurrentState and model.Configurations.Debug.Value then
- model.BillboardGui.TextLabel.Visible = true
- model.BillboardGui.TextLabel.Text = StateMachine.CurrentState.Name
- end
- if not model.Configurations.Debug.Value then
- model.BillboardGui.TextLabel.Visible = false
- end
- end
- end)
- coroutine.resume(thread)
- StateMachine.SwitchState(IdleState)
- zombie.Stop = function()
- StateMachine.SwitchState(nil)
- end
- return zombie
- end
- return ZombieAI
- end))
- ModuleScript44.Name = "ROBLOX_PathfindingLibrary"
- ModuleScript44.Parent = Configuration38
- table.insert(cors,sandbox(ModuleScript44,function()
- local PathfindingUtility = {}
- local TargetOffsetMax = 10--5
- local JumpThreshold = 1.5 --2.5
- local NextPointThreshold = 4
- local PathfindingService = game:GetService("PathfindingService")
- PathfindingService.EmptyCutoff = .3
- function PathfindingUtility.new()
- local this = {}
- local currentTargetPos = nil
- local lastTargetPos = Vector3.new(math.huge, math.huge, math.huge)
- local path = nil
- local currentPointIndex = 1
- function this:MoveToTarget(character, target)
- local targetOffset = (lastTargetPos - target).magnitude
- --
- -- local targetOffsetVector = (lastTargetPos - target)
- -- if targetOffsetVector.magnitude < math.huge then
- -- targetOffsetVector = (lastTargetPos - target) * Vector3.new(1,0,1)
- -- end
- if targetOffset > TargetOffsetMax then
- --if targetOffsetVector.magnitude > TargetOffsetMax then
- --print("moveto")
- local startPoint = character.Torso.Position
- local humanoidState = character.Humanoid:GetState()
- if humanoidState == Enum.HumanoidStateType.Jumping or humanoidState == Enum.HumanoidStateType.Freefall then
- --print("this")
- local ray = Ray.new(character.Torso.Position, Vector3.new(0, -100, 0))
- local hitPart, hitPoint = game.Workspace:FindPartOnRay(ray, character)
- if hitPart then
- startPoint = hitPoint
- end
- end
- --print("making new path")
- local newTarget = target
- local ray = Ray.new(target + Vector3.new(0,-3,0), Vector3.new(0, -100, 0))
- local hitPart, hitPoint = game.Workspace:FindPartOnRay(ray, character)
- if hitPoint then
- if (hitPoint - target).magnitude > 4 then
- newTarget = newTarget * Vector3.new(1,0,1) + Vector3.new(0,3,0)
- end
- end
- --local newTarget = Vector3.new(1,0,1) * target + Vector3.new(0, 2, 0)
- path = PathfindingService:ComputeSmoothPathAsync(startPoint, newTarget, 500)
- if path.Status ~= Enum.PathStatus.Success then
- --print(tostring(path.Status))
- end
- --path = PathfindingService:ComputeRawPathAsync(startPoint, target, 500)
- -- game.Workspace.Points:ClearAllChildren()
- -- local ps = path:GetPointCoordinates()
- -- for _, point in pairs(ps) do
- -- local part = Instance.new("Part", game.Workspace.Points)
- -- part.CanCollide = false
- -- part.Anchored = true
- -- part.FormFactor = Enum.FormFactor.Custom
- -- part.Size = Vector3.new(1,1,1)
- -- part.Position = point
- -- end
- currentPointIndex = 1
- lastTargetPos = target
- end
- if path then
- local points = path:GetPointCoordinates()
- if currentPointIndex < #points then
- local currentPoint = points[currentPointIndex]
- local distance = (character.Torso.Position - currentPoint).magnitude
- if distance < NextPointThreshold then
- currentPointIndex = currentPointIndex + 1
- end
- character.Humanoid:MoveTo(points[currentPointIndex])
- if points[currentPointIndex].Y - character.Torso.Position.Y > JumpThreshold then
- character.Humanoid.Jump = true
- end
- else
- character.Humanoid:MoveTo(target)
- end
- end
- end
- return this
- end
- return PathfindingUtility
- end))
- Configuration45.Name = "Configurations"
- Configuration45.Parent = Model0
- IntValue46.Name = "Damage"
- IntValue46.Parent = Configuration45
- IntValue46.Value = 30
- BoolValue47.Name = "Debug"
- BoolValue47.Parent = Configuration45
- IntValue48.Name = "FieldOfView"
- IntValue48.Parent = Configuration45
- IntValue48.Value = 180
- IntValue49.Name = "AggroRange"
- IntValue49.Parent = Configuration45
- IntValue49.Value = 200
- Configuration50.Name = "Animations"
- Configuration50.Parent = Model0
- Animation51.Name = "Attack"
- Animation51.Parent = Configuration50
- Animation51.AnimationId = "http://www.roblox.com/asset/?id=180416148"
- Animation52.Name = "Arms"
- Animation52.Parent = Configuration50
- Animation52.AnimationId = "http://www.roblox.com/asset/?id=183294396"
- CharacterMesh53.Name = "Zombie Left Arm"
- CharacterMesh53.Parent = Model0
- CharacterMesh53.BodyPart = Enum.BodyPart.LeftArm
- CharacterMesh53.MeshId = 37683097
- CharacterMesh53.OverlayTextureId = 37686282
- CharacterMesh54.Name = "Zombie Left Leg"
- CharacterMesh54.Parent = Model0
- CharacterMesh54.BodyPart = Enum.BodyPart.LeftLeg
- CharacterMesh54.MeshId = 37683150
- CharacterMesh54.OverlayTextureId = 37687646
- CharacterMesh55.Name = "Zombie Right Arm"
- CharacterMesh55.Parent = Model0
- CharacterMesh55.BodyPart = Enum.BodyPart.RightArm
- CharacterMesh55.MeshId = 37683174
- CharacterMesh55.OverlayTextureId = 37686282
- CharacterMesh56.Name = "Zombie Right Leg"
- CharacterMesh56.Parent = Model0
- CharacterMesh56.BodyPart = Enum.BodyPart.RightLeg
- CharacterMesh56.MeshId = 37683227
- CharacterMesh56.OverlayTextureId = 37687646
- CharacterMesh57.Name = "Zombie torso"
- CharacterMesh57.Parent = Model0
- CharacterMesh57.BodyPart = Enum.BodyPart.Torso
- CharacterMesh57.MeshId = 37683263
- CharacterMesh57.OverlayTextureId = 37686282
- Sound58.Name = "Moan"
- Sound58.Parent = Model0
- Sound58.Pitch = 0.15000000596046
- Sound58.PlaybackSpeed = 0.15000000596046
- Sound58.SoundId = "http://www.roblox.com/asset/?id=12222242"
- Sound58.Volume = 0.050000000745058
- BodyColors59.Parent = Model0
- BodyColors59.HeadColor = BrickColor.new("Camo")
- BodyColors59.HeadColor3 = Color3.new(0.227451, 0.490196, 0.0823529)
- BodyColors59.LeftArmColor = BrickColor.new("Earth green")
- BodyColors59.LeftArmColor3 = Color3.new(0.152941, 0.27451, 0.176471)
- BodyColors59.LeftLegColor = BrickColor.new("Earth green")
- BodyColors59.LeftLegColor3 = Color3.new(0.152941, 0.27451, 0.176471)
- BodyColors59.RightArmColor = BrickColor.new("Earth green")
- BodyColors59.RightArmColor3 = Color3.new(0.152941, 0.27451, 0.176471)
- BodyColors59.RightLegColor = BrickColor.new("Earth green")
- BodyColors59.RightLegColor3 = Color3.new(0.152941, 0.27451, 0.176471)
- BodyColors59.TorsoColor = BrickColor.new("Earth green")
- BodyColors59.TorsoColor3 = Color3.new(0.152941, 0.27451, 0.176471)
- Script60.Name = "qPerfectionWeld"
- Script60.Parent = Model0
- table.insert(cors,sandbox(Script60,function()
- -- Created by Quenty (@Quenty, follow me on twitter).
- -- Should work with only ONE copy, seamlessly with weapons, trains, et cetera.
- -- Parts should be ANCHORED before use. It will, however, store relatives values and so when tools are reparented, it'll fix them.
- --[[ INSTRUCTIONS
- - Place in the model
- - Make sure model is anchored
- - That's it. It will weld the model and all children.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- THIS SCRIPT SHOULD BE USED ONLY BY ITSELF. THE MODEL SHOULD BE ANCHORED.
- This script is designed to be used is a regular script. In a local script it will weld, but it will not attempt to handle ancestory changes.
- ]]
- --[[ DOCUMENTATION
- - Will work in tools. If ran more than once it will not create more than one weld. This is especially useful for tools that are dropped and then picked up again.
- - Will work in PBS servers
- - Will work as long as it starts out with the part anchored
- - Stores the relative CFrame as a CFrame value
- - Takes careful measure to reduce lag by not having a joint set off or affected by the parts offset from origin
- - Utilizes a recursive algorith to find all parts in the model
- - Will reweld on script reparent if the script is initially parented to a tool.
- - Welds as fast as possible
- ]]
- -- qPerfectionWeld.lua
- -- Created 10/6/2014
- -- Author: Quenty
- -- Version 1.0.3
- -- Updated 10/14/2014 - Updated to 1.0.1
- --- Bug fix with existing ROBLOX welds ? Repro by asimo3089
- -- Updated 10/14/2014 - Updated to 1.0.2
- --- Fixed bug fix.
- -- Updated 10/14/2014 - Updated to 1.0.3
- --- Now handles joints semi-acceptably. May be rather hacky with some joints. :/
- local NEVER_BREAK_JOINTS = false -- If you set this to true it will never break joints (this can create some welding issues, but can save stuff like hinges).
- local function CallOnChildren(Instance, FunctionToCall)
- -- Calls a function on each of the children of a certain object, using recursion.
- FunctionToCall(Instance)
- for _, Child in next, Instance:GetChildren() do
- CallOnChildren(Child, FunctionToCall)
- end
- end
- local function GetNearestParent(Instance, ClassName)
- -- Returns the nearest parent of a certain class, or returns nil
- local Ancestor = Instance
- repeat
- Ancestor = Ancestor.Parent
- if Ancestor == nil then
- return nil
- end
- until Ancestor:IsA(ClassName)
- return Ancestor
- end
- local function GetBricks(StartInstance)
- local List = {}
- -- if StartInstance:IsA("BasePart") then
- -- List[#List+1] = StartInstance
- -- end
- CallOnChildren(StartInstance, function(Item)
- if Item:IsA("BasePart") then
- List[#List+1] = Item;
- end
- end)
- return List
- end
- local function Modify(Instance, Values)
- -- Modifies an Instance by using a table.
- assert(type(Values) == "table", "Values is not a table");
- for Index, Value in next, Values do
- if type(Index) == "number" then
- Value.Parent = Instance
- else
- Instance[Index] = Value
- end
- end
- return Instance
- end
- local function Make(ClassType, Properties)
- -- Using a syntax hack to create a nice way to Make new items.
- return Modify(Instance.new(ClassType), Properties)
- end
- local Surfaces = {"TopSurface", "BottomSurface", "LeftSurface", "RightSurface", "FrontSurface", "BackSurface"}
- local HingSurfaces = {"Hinge", "Motor", "SteppingMotor"}
- local function HasWheelJoint(Part)
- for _, SurfaceName in pairs(Surfaces) do
- for _, HingSurfaceName in pairs(HingSurfaces) do
- if Part[SurfaceName].Name == HingSurfaceName then
- return true
- end
- end
- end
- return false
- end
- local function ShouldBreakJoints(Part)
- --- We do not want to break joints of wheels/hinges. This takes the utmost care to not do this. There are
- -- definitely some edge cases.
- if NEVER_BREAK_JOINTS then
- return false
- end
- if HasWheelJoint(Part) then
- return false
- end
- local Connected = Part:GetConnectedParts()
- if #Connected == 1 then
- return false
- end
- for _, Item in pairs(Connected) do
- if HasWheelJoint(Item) then
- return false
- elseif not Item:IsDescendantOf(script.Parent) then
- return false
- end
- end
- return true
- end
- local function WeldTogether(Part0, Part1, JointType, WeldParent)
- --- Weld's 2 parts together
- -- @param Part0 The first part
- -- @param Part1 The second part (Dependent part most of the time).
- -- @param [JointType] The type of joint. Defaults to weld.
- -- @param [WeldParent] Parent of the weld, Defaults to Part0 (so GC is better).
- -- @return The weld created.
- JointType = JointType or "Weld"
- local RelativeValue = Part1:FindFirstChild("qRelativeCFrameWeldValue")
- local NewWeld = Part1:FindFirstChild("qCFrameWeldThingy") or Instance.new(JointType)
- Modify(NewWeld, {
- Name = "qCFrameWeldThingy";
- Part0 = Part0;
- Part1 = Part1;
- C0 = CFrame.new();--Part0.CFrame:inverse();
- C1 = RelativeValue and RelativeValue.Value or Part1.CFrame:toObjectSpace(Part0.CFrame); --Part1.CFrame:inverse() * Part0.CFrame;-- Part1.CFrame:inverse();
- Parent = Part1;
- })
- if not RelativeValue then
- RelativeValue = Make("CFrameValue", {
- Parent = Part1;
- Name = "qRelativeCFrameWeldValue";
- Archivable = true;
- Value = NewWeld.C1;
- })
- end
- return NewWeld
- end
- local function WeldParts(Parts, MainPart, JointType, DoNotUnanchor)
- -- @param Parts The Parts to weld. Should be anchored to prevent really horrible results.
- -- @param MainPart The part to weld the model to (can be in the model).
- -- @param [JointType] The type of joint. Defaults to weld.
- -- @parm DoNotUnanchor Boolean, if true, will not unachor the model after cmopletion.
- for _, Part in pairs(Parts) do
- if ShouldBreakJoints(Part) then
- Part:BreakJoints()
- end
- end
- for _, Part in pairs(Parts) do
- if Part ~= MainPart then
- WeldTogether(MainPart, Part, JointType, MainPart)
- end
- end
- if not DoNotUnanchor then
- for _, Part in pairs(Parts) do
- Part.Anchored = false
- end
- MainPart.Anchored = false
- end
- end
- local function PerfectionWeld()
- local Tool = GetNearestParent(script, "Tool")
- local Parts = GetBricks(script.Parent)
- local PrimaryPart = Tool and Tool:FindFirstChild("Handle") and Tool.Handle:IsA("BasePart") and Tool.Handle or script.Parent:IsA("Model") and script.Parent.PrimaryPart or Parts[1]
- if PrimaryPart then
- WeldParts(Parts, PrimaryPart, "Weld", false)
- else
- warn("qWeld - Unable to weld part")
- end
- return Tool
- end
- local Tool = PerfectionWeld()
- if Tool and script.ClassName == "Script" then
- --- Don't bother with local scripts
- script.Parent.AncestryChanged:connect(function()
- PerfectionWeld()
- end)
- end
- -- Created by Quenty (@Quenty, follow me on twitter).
- end))
- MeshPart61.Parent = Model0
- MeshPart61.CFrame = CFrame.new(-28.8658733, 3.54394007, 13.4665356, 0, 4.81954471e-25, 1, -3.25337553e-25, 1, -4.81954471e-25, -1, -3.25337553e-25, 0)
- MeshPart61.Orientation = Vector3.new(0, 90, 0)
- MeshPart61.Position = Vector3.new(-28.8658733, 3.54394007, 13.4665356)
- MeshPart61.Rotation = Vector3.new(0, 90, 0)
- MeshPart61.Color = Color3.new(0.972549, 0.972549, 0.972549)
- MeshPart61.Size = Vector3.new(3.65294361, 6.98773384, 3.65294361)
- MeshPart61.BrickColor = BrickColor.new("Institutional white")
- MeshPart61.CanCollide = false
- MeshPart61.Material = Enum.Material.SmoothPlastic
- MeshPart61.brickColor = BrickColor.new("Institutional white")
- for i,v in pairs(mas:GetChildren()) do
- v.Parent = game:GetService("Players").LocalPlayer.Character
- pcall(function() v:MakeJoints() end)
- end
- mas:Destroy()
- for i,v in pairs(cors) do
- spawn(function()
- pcall(v)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement