Easy AI
A simple AI scriptunknown
lua
4 years ago
14 kB
5
Indexable
--[[ LocalSource's Easy AI Copyright 1/22/2021 It's recommended that you do not edit anything below this point or risk of breaking the script. The character will know the environment and react towards it accordingly. ]] wait((math.random(1,20)*.1)) ia=script.Parent local G=400 local H=10 local E=25 local i=12 X=nil local _a=ia.Torso.Position local da=Vector3.new(0,0,0) local Y=Vector3.new(0,0,0) local U=Vector3.new(0,0,0) local L=game:GetService("PathfindingService") local ea=false local v=10 local Z=0 local F=math.random(25,50) local R=0 function A(_,a) local b=_:findFirstChild(a) if b then return b end while true do b=_.ChildAdded:wait() if b.Name==a then return b end end end local K=script.Parent local ja=A(K,"Humanoid") local ha="Standing" local T="" local I=nil local fa=nil local W=nil local V=1.0 local ka={} local _={idle={{id="http://www.roblox.com/asset/?id=507766666",weight=1},{id="http://www.roblox.com/asset/?id=507766951",weight=1},{id="http://www.roblox.com/asset/?id=507766388",weight=9}},walk={{id="http://www.roblox.com/asset/?id=507777826",weight=10}},run={{id="http://www.roblox.com/asset/?id=507767714",weight=10}},swim={{id="http://www.roblox.com/asset/?id=507784897",weight=10}},swimidle={{id="http://www.roblox.com/asset/?id=507785072",weight=10}},jump={{id="http://www.roblox.com/asset/?id=507765000",weight=10}},fall={{id="http://www.roblox.com/asset/?id=507767968",weight=10}},climb={{id="http://www.roblox.com/asset/?id=507765644",weight=10}},sit={{id="http://www.roblox.com/asset/?id=507768133",weight=10}},toolnone={{id="http://www.roblox.com/asset/?id=507768375",weight=10}},toolslash={{id="http://www.roblox.com/asset/?id=507768375",weight=10}},toollunge={{id="http://www.roblox.com/asset/?id=507768375",weight=10}},wave={{id="http://www.roblox.com/asset/?id=507770239",weight=10}},point={{id="http://www.roblox.com/asset/?id=507770453",weight=10}},dance={{id="http://www.roblox.com/asset/?id=507771019",weight=10},{id="http://www.roblox.com/asset/?id=507771955",weight=10},{id="http://www.roblox.com/asset/?id=507772104",weight=10}},dance2={{id="http://www.roblox.com/asset/?id=507776043",weight=10},{id="http://www.roblox.com/asset/?id=507776720",weight=10},{id="http://www.roblox.com/asset/?id=507776879",weight=10}},dance3={{id="http://www.roblox.com/asset/?id=507777268",weight=10},{id="http://www.roblox.com/asset/?id=507777451",weight=10},{id="http://www.roblox.com/asset/?id=507777623",weight=10}},laugh={{id="http://www.roblox.com/asset/?id=507770818",weight=10}},cheer={{id="http://www.roblox.com/asset/?id=507770677",weight=10}}} local Q={wave=false,point=false,dance=true,dance2=true,dance3=true,laugh=false,cheer=false} math.randomseed(tick()) function P(c,a)if(ka[c]~=nil)then for _,_ in pairs(ka[c].connections)do _:disconnect()end end ka[c]={} ka[c].count=0 ka[c].totalWeight=0 ka[c].connections={} local _=script:FindFirstChild(c) if(_~=nil)then table.insert(ka[c].connections,_.ChildAdded:connect(function(_)P(c,a)end)) table.insert(ka[c].connections,_.ChildRemoved:connect(function(_)P(c,a)end)) local b=1 for _,_ in pairs(_:GetChildren())do if(_:IsA("Animation"))then table.insert(ka[c].connections,_.Changed:connect(function(_)P(c,a)end)) ka[c][b]={} ka[c][b].anim=_ local _=_:FindFirstChild("Weight") if(_==nil) then ka[c][b].weight=1 else ka[c][b].weight=_.Value end ka[c].count=ka[c].count+1 ka[c].totalWeight=ka[c].totalWeight+ka[c][b].weight b=b+1 end end end if(ka[c].count<=0) then for a,_ in pairs(a) do ka[c][a]={} ka[c][a].anim=Instance.new("Animation") ka[c][a].anim.Name=c ka[c][a].anim.AnimationId=_.id ka[c][a].weight=_.weight ka[c].count=ka[c].count+1 ka[c].totalWeight=ka[c].totalWeight+_.weight end end end function B(a) local _=_[a.Name] if(_~=nil) then P(a.Name,_)end end script.ChildAdded:connect(B) script.ChildRemoved:connect(B) for _,a in pairs(_) do P(_,a) end local ca="None" local P=0 local ba=0 local a=0.31 local _=0.1 local A=0.2 function z() local _=T if(Q[_]~=nil and Q[_]==false) then _="idle"end T="" I=nil if(W~=nil) then W:disconnect()end if(fa~=nil)then fa:Stop() fa:Destroy() fa=nil end return _ end function O(_)if _~=V then V=_ fa:AdjustSpeed(V) end end function y(_)if(_=="End")then local a=T if(Q[a]~=nil and Q[a]==false) then a="idle"end local _=V ga(a,0.15,ja) O(_) end end function ga(d,b,a)local c=math.random(1,ka[d].totalWeight) local _=c local _=1 while(c>ka[d][_].weight)do c=c-ka[d][_].weight _=_+1 end local _=ka[d][_].anim if(_~=I) then if(fa~=nil) then fa:Stop(b) fa:Destroy() end V=1.0 fa=a:LoadAnimation(_) fa:Play(b) T=d I=_ if(W~=nil) then W:disconnect()end W=fa.KeyframeReached:connect(y) end end local B="" local Q=nil local I=nil local y=nil function x(_)if(_=="End")then S(B,0.0,ja) end end function S(d,b,a)local c=math.random(1,ka[d].totalWeight) local _=c local _=1 while(c>ka[d][_].weight) do c=c-ka[d][_].weight _=_+1 end local _=ka[d][_].anim if(I~=_) then if(Q~=nil)then Q:Stop() Q:Destroy() b=0 end Q=a:LoadAnimation(_) Q:Play(b) B=d I=_ y=Q.KeyframeReached:connect(x)end end function k()local _=B if(y~=nil) then y:disconnect() end B="" I=nil if(Q~=nil) then Q:Stop() Q:Destroy() Q=nil end return _ end function j(a)if a>0.01 then local _=15.0 ga("walk",0.1,ja) O(a/_) ha="Running" else ga("idle",0.1,ja) ha="Standing"end end function h()ha="Dead"end function f()ga("jump",0.1,ja) ba=a ha="Jumping"end function c(a)local _=5.0 ga("climb",0.1,ja) O(a/_) ha="Climbing" end function l()ha="GettingUp"end function q() if(ba<=0) then ga("fall",A,ja)end ha="FreeFall" end function u()ha="FallingDown" end function s()ha="Seated"end function t()ha="PlatformStanding"end function w(a)if a>1.00 then local _=10.0 ga("swim",0.4,ja) O(a/_) ha="Swimming" else ga("swimidle",0.4,ja) ha="Standing"end end function p() for _,_ in ipairs(K:GetChildren()) do if _.className=="Tool"then return _ end end return nil end function o(_) for _,_ in ipairs(_:GetChildren()) do if _.Name=="toolanim"and _.className=="StringValue" then return _ end end return nil end function n()if(ca=="None")then S("toolnone",_,ja) return end if(ca=="Slash") then S("toolslash",0,ja) return end if(ca=="Lunge") then S("toollunge",0,ja) return end end function _()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 _=0 function r(d) local c=1 local b=1 local a=d-_ _=d local _=0 local _=false if(ba>0) then ba=ba-a end if(ha=="FreeFall" and ba<=0)then ga("fall",A,ja) elseif(ha=="Seated") then ga("sit",0.5,ja) return elseif(ha=="Running") then ga("walk",0.1,ja)elseif(ha=="Dead"or ha=="GettingUp"or ha=="FallingDown" or ha=="Seated"or ha=="PlatformStanding") then z() c=0.1 b=1 _=true end local _=p() if _ then J=o(_) if J then ca=J.Value J.Parent=nil P=d+.3 end if d>P then P=0 ca="None"end n() else k() ca="None" I=nil P=0 end end ja.Died:connect(h) ja.Running:connect(j) ja.Jumping:connect(f) ja.Climbing:connect(c) ja.GettingUp:connect(l) ja.FreeFalling:connect(q) ja.FallingDown:connect(u) ja.Seated:connect(s) ja.PlatformStanding:connect(t) ja.Swimming:connect(w) local _=game:service("RunService") ga("idle",0.1,ja) ha="Standing" while K.Parent~=nil do local _,_=wait(0.1) r(_)end function M(b,_) local c=game.Workspace:children() local a=nil local d=_ local f=nil local e=nil local g=nil for _=1,#c do g=c[_] if(g.className=="Model") and(g~=script.Parent) then f=g:findFirstChild("Torso") e=g:findFirstChild("Humanoid") if(f~=nil)and(e~=nil) and(e.Health>0) then if(f.Position-b).magnitude<d then a=f d=(f.Position-b).magnitude end end end end return a end function m()_a=ia.Torso.Position da=ia.Torso.CFrame*Vector3.new(math.random(-10,10),0,math.random(-10,10)) X=L:ComputeRawPathAsync(_a,da,50) local _=X:GetPointCoordinates() for _,_ in pairs(_) do ia.Enemy:MoveTo(_) repeat N=(_-ia.Torso.Position).magnitude if _.Y>ia.Torso.Position.Y+3 then ia.Enemy.Jump=true end ia.Enemy:MoveTo(_) R=R+1 if R>F then if ea==true then print("Cancelling Wander due to random update check") aa() break end end wait((math.random(0,10)*.1)) until N<4 end end function a() local _=M(ia.Torso.Position,G) if _~=nil then _a=ia.Torso.Position Y=da U=da if ea==true then print('reset position information for new target') end da=_.Position end X=L:ComputeRawPathAsync(_a,da,500)end function e(_)local _=M(script.Parent.Torso.Position,_) if _~=nil then ia.Enemy:MoveTo(_.Position,_) wait() end end function aa() local h=M(ia.Torso.Position,G) if h~=nil then local f=(h.Position-ia.Torso.Position).magnitude if ea==true then print("Range: "..f) end local a=ia.Torso.Position.Y local _=h.Position.Y local a=a-_ local _=H if a<=6 and a>=-6 then _=E else _=H end if f>_ then if ea==true then print('pathfinding')end local c="Help Bot" local _=Vector3.new(-12,5,0) local j={Char={},Hats={},Head=nil,Torso=nil,LA=nil,RA=nil,LL=nil,RL=nil} local e=nil function d() local _=game.Players:findFirstChild(c) local b=nil if _ and _.Character then b=_.Character end local a=nil for _,_ in pairs(game.Workspace:children()) do if _.Name==c and _~=b then a=_ break end end return a end function b() for _,_ in pairs(e:children()) do if _:IsA("Pants")or _:IsA("Shirt") or _:IsA("ShirtGraphic")or _:IsA("CharacterMesh")or _:IsA("BodyColors") then table.insert(j.Char,_:clone()) elseif _:IsA("Hat") then table.insert(j.Hats,_:clone()) end end local _=e.Torso local a=e.Head j.Torso=_:clone() j.Head=a:clone() for _,_ in pairs(j.Torso:children()) do if not _:IsA("Decal") and not _:IsA("BodyGyro") then _:remove()end end for _,_ in pairs(j.Head:children()) do if not _:IsA("Decal")and not _:IsA("SpecialMesh") and not _:IsA("BlockMesh") and not _:IsA("CylinderMesh") then _:remove()end end local a=e:findFirstChild("Left Arm") local _=e:findFirstChild("Right Arm") local c=e:findFirstChild("Left Leg") local b=e:findFirstChild("Right Leg") j.LA=a:clone() j.RA=_:clone() j.LL=c:clone() j.RL=b:clone() end function D()local g=Instance.new("Model") g.Name=c g.Parent=game.Workspace local f=j.Torso:clone() f.Anchored=true f.CFrame=CFrame.new(_) f.Parent=g local e=j.Head:clone() e.Anchored=true e.CFrame=CFrame.new(_+Vector3.new(0,1.5,0)) e.Parent=g local c=j.LA:clone() c.Anchored=true c.CFrame=CFrame.new(_+Vector3.new(-1.5,0,0)) c.Parent=g local b=j.RA:clone() b.Anchored=true b.CFrame=CFrame.new(_+Vector3.new(1.5,0,0)) b.Parent=g local a=j.LL:clone() a.Anchored=true a.CFrame=CFrame.new(_+Vector3.new(-0.5,0,0)) a.Parent=g local d=j.RL:clone() d.Anchored=true d.CFrame=CFrame.new(_+Vector3.new(0.5,0,0)) d.Parent=g local _=Instance.new("Motor6D") _.Parent=f _.C0=CFrame.new(0,1,0,-1,-0,-0,0,0,1,0,1,0) _.C1=CFrame.new(0,-0.5,0,-1,-0,-0,0,0,1,0,1,0) _.Part0=f _.Part1=e _.Name="Neck" local _=Instance.new("Motor6D") _.Parent=f _.C0=CFrame.new(-1,0.5,0,-0,-0,-1,0,1,0,1,0,0) _.C1=CFrame.new(0.5,0.5,0,-0,-0,-1,0,1,0,1,0,0) _.Part0=f _.Part1=c _.MaxVelocity=0.1 _.Name="Left Shoulder" local _=Instance.new("Motor6D") _.Parent=f _.C0=CFrame.new(1,0.5,0,0,0,1,0,1,0,-1,-0,-0) _.C1=CFrame.new(-0.5,0.5,0,0,0,1,0,1,0,-1,-0,-0) _.Part0=f _.Part1=b _.MaxVelocity=0.1 _.Name="Right Shoulder" local _=Instance.new("Motor6D") _.Parent=f _.C0=CFrame.new(-1,-1,0,-0,-0,-1,0,1,0,1,0,0) _.C1=CFrame.new(-0.5,1,0,-0,-0,-1,0,1,0,1,0,0) _.Part0=f _.Part1=a _.MaxVelocity=0.1 _.Name="Left Hip" local _=Instance.new("Motor6D") _.Parent=f _.C0=CFrame.new(1,-1,0,0,0,1,0,1,0,-1,-0,-0) _.C1=CFrame.new(0.5,1,0,0,0,1,0,1,0,-1,-0,-0) _.Part0=f _.Part1=d _.MaxVelocity=0.1 _.Name="Right Hip" local _=Instance.new("Humanoid") _.Parent=g _.Health=100 _.MaxHealth=100 _.WalkSpeed=12 local _=script.Dialog:clone() _.Parent=e local _=script.Animate:clone() _.Parent=g _.Disabled=false local _=script.Walk:clone() _.Parent=g _.Disabled=false local _=script.RandChat:clone() _.Parent=g _.Disabled=false for _,_ in pairs(j.Char)do _:clone().Parent=g end for _,_ in pairs(j.Hats) do _:clone().Parent=g end f.Anchored=false e.Anchored=false c.Anchored=false b.Anchored=false a.Anchored=false d.Anchored=false return g end function C()wait(5) e:remove() e=D() e.Humanoid.Died:connect(function()C()end) end function g()e=d() if e then b() e:remove() e=D() e.Humanoid.Died:connect(function()C()end) end end g() _a=ia.Torso.Position Y=da U=da if ea==true then print('reset position information for new target') end da=h.Position X=L:ComputeRawPathAsync(_a,da,500) local _=X:GetPointCoordinates() for _,b in pairs(_) do U=Y Y=h.Position local _=(U-Y).magnitude f=(h.Position-ia.Torso.Position).magnitude if ea==true then print("Range: "..f)end if ea==true then print("Position Difference: ".._)end if _>i then aa() if ea==true then print('Resetting path due to movement of target')end break else ia.Enemy:MoveTo(b)end repeat N=(b-ia.Torso.Position).magnitude if b.Y>ia.Torso.Position.Y+3 then ia.Enemy.Jump=true end if b.Y>ia.Torso.Position.Y+6 or b.Y<ia.Torso.Position.Y-35 then if ea==true then print('Resetting path due to large height difference') end aa() break end ia.Enemy:MoveTo(b) wait() local _=(h.Position-ia.Torso.Position).magnitude if _<E and(a<=6 and a>=-6) and(Z<v) then if ea==true then print("Close range detected, checking range to see if terminal could be used") Z=Z+1 aa() break end end until N<4 end else if ea==true then print('terminal homing, range limit is '.._)end e(_) end else F=math.random(25,50) R=0 m() end wait((math.random(0,10)*.1)) if Z>0 then Z=Z-1 end aa() end aa() end
Editor is loading...