Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- A.I./I.A System/Système
- internetExplorerchad
- --]]
- local alien = {}
- local GameLoop = require(game.ServerScriptService["Game Loop"])
- function alien.new(health,walkSpeed)
- local obj = setmetatable({
- currentTarget = nil,
- model = script.Alien:Clone(),
- targetDistance = 1e10,
- deathConnection = nil
- },{__index=alien})
- obj.model.Humanoid.MaxHealth = health or 100
- obj.model.Humanoid.Health = health or 100
- obj.model.Humanoid.WalkSpeed = walkSpeed or 16
- return obj
- end
- local pathfindingService = game:GetService("PathfindingService")
- function alien:walkTo()
- if self.currentTarget and self.currentTarget.Parent == workspace then
- local path = pathfindingService:CreatePath({AgentRadius = 2, AgentHeight = 5, AgentCanJump = true})
- path:ComputeAsync(self.model.PrimaryPart.Position,self.currentTarget.PrimaryPart.Position)
- local waypoints = path:GetWaypoints()
- for x = 1,#waypoints-1,1 do
- local ray1 = Ray.new(self.model.PrimaryPart.Position,waypoints[x].Position)
- local ray2 = Ray.new(self.currentTarget.PrimaryPart.Position,waypoints[x].Position)
- local hit1 = workspace:FindPartOnRay(ray1,self.model.PrimaryPart)
- local hit2 = workspace:FindPartOnRay(ray2,self.currentTarget.PrimaryPart)
- if not hit1 and not hit2 then
- print("...")
- self.model.Humanoid:MoveTo(waypoints[x].Position)
- local t = (waypoints[x].Position-self.model.PrimaryPart.Position).magnitude/self.model.Humanoid.WalkSpeed
- local bind = Instance.new("BindableEvent")
- local event = bind.Event
- local hasFired = false
- do
- spawn(function()
- local hasReached = self.model.Humanoid.MoveToFinished:Wait()
- if not hasFired then
- hasFired = true
- bind:Fire("Success")
- end
- end)
- delay(t,function()
- if not hasFired then
- hasFired = true
- bind:Fire("Error : has not been reached within time")
- end
- end)
- end
- local result = event:Wait()
- print(result)
- if result == "Error : has not been reached within time" then
- break
- end
- else
- print(",,,")
- local t = (self.currentTarget.PrimaryPart.Position-self.model.PrimaryPart.Position).magnitude/self.model.Humanoid.WalkSpeed
- self.model.Humanoid:MoveTo(self.currentTarget.PrimaryPart.Position,self.currentTarget.PrimaryPart)
- local bind = Instance.new("BindableEvent")
- local event = bind.Event
- local hasFired = false
- do
- spawn(function()
- local hasReached = self.model.Humanoid.MoveToFinished:Wait()
- if not hasFired then
- hasFired = true
- bind:Fire("Success")
- end
- end)
- delay(t,function()
- if not hasFired then
- hasFired = true
- bind:Fire("Error : has not been reached within time")
- end
- end)
- end
- local result = event:Wait()
- print(result)
- if result == "Error : has not been reached within time" then
- break
- end
- end
- end
- end
- end
- function alien:chase()
- self.model.Humanoid.Died:Connect(function()
- local modelSave = self.model
- self = nil
- modelSave:Destroy()
- return
- end)
- local waterJumpDebounce = false
- self.model.Humanoid.Swimming:Connect(function()
- if waterJumpDebounce == false then
- waterJumpDebounce = true
- self.model.PrimaryPart.Velocity = self.model.PrimaryPart.Velocity + Vector3.new(0,100,0)
- delay(wait(),function() waterJumpDebounce = false end)
- end
- end)
- repeat
- for _,v in pairs(game.Players:GetPlayers()) do
- if GameLoop.activePlayers[v.Name] and v.Character and self.model.Humanoid.Health > 0 and v.Character.Humanoid.Health > 0 then
- local mag = (v.Character.PrimaryPart.Position-self.model.PrimaryPart.Position).magnitude
- if mag < self.targetDistance then
- self.targetDistance = mag
- self.currentTarget = v.Character
- self.deathConnection = v.Character.Humanoid.Died:Connect(function()
- self.targetDistance = 1e10
- self.currentTarget = nil
- self.deathConnection = self.deathConnection and self.deathConnection:Disconnect()
- self.deathConnection = nil
- self:chase()
- return
- end)
- end
- end
- end
- --print("Alien is currently chasing ", self.currentTarget)
- self:walkTo()
- wait(1)
- until 5 == 6
- end
- return alien
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement