Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- function module:Movement(list)
- local hum = list.Hum
- local npctype = list.NpcType
- local root = list.Root
- local dist = list.Dist
- local AttackDist = list.AttackDist
- local StopDist = list.StopDist
- local ComboNum = list.MaxComboNum
- local torso = nil
- local clone = hum:Clone()
- local pos = root.Position
- local function AttackMethod(details)
- local find = script:FindFirstChild(npctype)
- if find then
- local mod2 = require(find)
- mod2:Attack(details)
- end
- end
- -- Adding Combat Values
- local DFV = Instance.new("Folder",hum.Parent)
- local function newins(name,typ,val)
- local new = Instance.new(typ)
- new.Name = name
- new.Value = val
- new.Parent = DFV
- return new
- end
- local CanAttck = newins('CanAttack','BoolValue',true)
- --attackin anim(only need 1 i can just keep updating the animid)
- local anim = Instance.new("Animation")
- -- Animation tracking stuff
- local num = 0
- local ComboCoolDown = 1
- local function NumSystem()
- if npctype == 'CloseCombat' then
- if CanAttck.Value == true then
- if num >= ComboNum then
- CanAttck.Value = false
- delay(ComboCoolDown,function()
- CanAttck.Value = true
- end)
- else
- num = num + 1
- end
- else
- num = 0
- end
- end
- end
- local function move()
- NumSystem()
- local enemyhum = nil
- local enemyroot = nil
- local Funcdb = false
- for i,v in pairs(game.Workspace:GetChildren()) do
- if v:IsA("Model") then
- enemyhum = v:FindFirstChild("Humanoid")
- enemyroot = v:FindFirstChild("HumanoidRootPart")
- if enemyhum and enemyroot and enemyhum ~= hum then
- if enemyhum.Health ~= 0 and hum.Health ~= 0 then
- if torso == nil then
- if (enemyroot.Position - root.Position).Magnitude <= dist then
- torso = enemyroot
- AttackMethod(
- {
- ['Hum'] = hum;
- ['Dist'] = dist;
- ['AttackDist'] = AttackDist;
- ['StopDist'] = StopDist;
- ['Far'] = (torso.Position - root.Position).Magnitude;
- ['Num'] = num;
- ['AttackAnim'] = anim;
- ['CanAttack'] = CanAttck.Value
- }
- )
- end
- elseif torso ~= nil then
- if (enemyroot.Position - root.Position).Magnitude < (root.Position - torso.Position).Magnitude and not Funcdb then
- Funcdb = false
- torso = enemyroot
- AttackMethod(
- {
- ['Hum'] = hum;
- ['Dist'] = dist;
- ['AttackDist'] = AttackDist;
- ['StopDist'] = StopDist;
- ['Far'] = (torso.Position - root.Position).Magnitude;
- ['Num'] = num;
- ['AttackAnim'] = anim;
- ['CanAttack'] = CanAttck.Value
- }
- )
- end
- end
- end
- end
- end
- end
- if torso ~= nil then
- if (root.Position - torso.Position).Magnitude > dist then
- torso = nil
- end
- if not Funcdb then
- AttackMethod(
- {
- ['Hum'] = hum;
- ['Dist'] = dist;
- ['AttackDist'] = AttackDist;
- ['StopDist'] = StopDist;
- ['Far'] = (torso.Position - root.Position).Magnitude;
- ['Num'] = num;
- ['AttackAnim'] = anim;
- ['CanAttack'] = CanAttck.Value
- }
- )
- end
- end
- return torso
- end
- local mod2 = require(game.ServerScriptService.ModuleScripts.CollisionGroup.CantTouchModels)
- mod2:phy(hum.Parent)
- hum.Died:Connect(function()
- wait(2)
- hum.Parent:Destroy()
- wait(5)
- clone:WaitForChild("HumanoidRootPart").Position = pos
- clone.Parent = hum.Parent
- end)
- while wait(0.3) do
- local target = move()
- if move ~= nil then
- hum:MoveTo(target.Position,target)
- else
- hum:MoveTo(root.Position)
- end
- end
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement