Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NOTE = [=[
- This is the combat 'engine' I'm working on for now.
- It's a bit buggy and unclean, but this is just an example of basic concepts I've been working on for a few days.
- I wrote this recently for my gladiator game, and I'm also planning on integrating it into other projects such as the RPG I'm making.
- ]=]
- wait(5)
- --INTERPOLATE CFRAME
- -- By Anaminus
- function QuaternionFromCFrame(cf)
- local mx, my, mz,
- m00, m01, m02,
- m10, m11, m12,
- m20, m21, m22 = cf:components()
- local trace = m00 + m11 + m22
- if trace > 0 then
- local s = math.sqrt(1 + trace)
- local recip = 0.5/s
- return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5
- else
- local i = 0
- if m11 > m00 then i = 1 end
- if m22 > (i == 0 and m00 or m11) then i = 2 end
- if i == 0 then
- local s = math.sqrt(m00-m11-m22+1)
- local recip = 0.5/s
- return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip
- elseif i == 1 then
- local s = math.sqrt(m11-m22-m00+1)
- local recip = 0.5/s
- return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip
- elseif i == 2 then
- local s = math.sqrt(m22-m00-m11+1)
- local recip = 0.5/s
- return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip
- end
- end
- end
- function QuaternionToCFrame(px, py, pz, x, y, z, w)
- local xs, ys, zs = x + x, y + y, z + z
- local wx, wy, wz = w*xs, w*ys, w*zs
- --
- local xx = x*xs
- local xy = x*ys
- local xz = x*zs
- local yy = y*ys
- local yz = y*zs
- local zz = z*zs
- --
- return CFrame.new(px, py, pz,
- 1-(yy+zz), xy - wz, xz + wy,
- xy + wz, 1-(xx+zz), yz - wx,
- xz - wy, yz + wx, 1-(xx+yy))
- end
- function QuaternionSlerp(a, b, t)
- local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4]
- local startInterp, finishInterp;
- if cosTheta >= 0.0001 then
- if (1 - cosTheta) > 0.0001 then
- local theta = math.acos(cosTheta)
- local invSinTheta = 1/math.sin(theta)
- startInterp = math.sin((1-t)*theta)*invSinTheta
- finishInterp = math.sin(t*theta)*invSinTheta
- else
- startInterp = 1-t
- finishInterp = t
- end
- else
- if (1+cosTheta) > 0.0001 then
- local theta = math.acos(-cosTheta)
- local invSinTheta = 1/math.sin(theta)
- startInterp = math.sin((t-1)*theta)*invSinTheta
- finishInterp = math.sin(t*theta)*invSinTheta
- else
- startInterp = t-1
- finishInterp = t
- end
- end
- return a[1]*startInterp + b[1]*finishInterp,
- a[2]*startInterp + b[2]*finishInterp,
- a[3]*startInterp + b[3]*finishInterp,
- a[4]*startInterp + b[4]*finishInterp
- end
- function TweenPart(part, a, b, length)
- moving = nil
- wait(0)
- moving = true
- local qa = {QuaternionFromCFrame(a)}
- local qb = {QuaternionFromCFrame(b)}
- local ax, ay, az = a.x, a.y, a.z
- local bx, by, bz = b.x, b.y, b.z
- --
- local c = 0
- local tot = 0
- --
- local startTime = tick()
- while moving do
- wait()
- local t = (tick()-startTime)/length
- local _t = 1-t
- if t > 1 then break end
- local startT = tick()
- local cf = QuaternionToCFrame(_t*ax + t*bx, _t*ay + t*by, _t*az + t*bz,
- QuaternionSlerp(qa, qb, t))
- tot = tot+(tick()-startT)
- c = c + 1
- part.C0 = cf
- end
- end
- local PoolCommunication = Workspace.PoolCommunication;
- local Won = PoolCommunication.Won;
- local InBattle = PoolCommunication.InBattle;
- local Head1,Head2 = PoolCommunication.Head1,PoolCommunication.Head2;
- local Lighting = game:GetService("Lighting");
- local DamageGUI = Lighting.DamageGUI;
- local ControllerService = game:GetService('ControllerService');
- local ContentProvider = game:GetService('ContentProvider');
- local debris = game:GetService("Debris");
- local Players = game:GetService("Players");
- local Player = script.Parent.Parent;
- local Char = Player.Character;
- repeat wait(0) until Char:FindFirstChild('BackSlot');
- if Char:FindFirstChild('NewAnimate') then
- Animate = Char.NewAnimate
- else
- Animate = Char:WaitForChild('Animate')
- end
- Animate:Destroy()
- Lighting.NewAnimate:Clone().Parent = Char;
- local Head,Torso,Human = Char:WaitForChild("Head"),Char:WaitForChild("Torso"),Char:WaitForChild("Humanoid");
- local LL,RL = Char['Left Leg'],Char['Right Leg'];
- local RA,LA = Char['Right Arm'],Char['Left Arm'];
- local LL,RL = Char['Left Leg'],Char['Right Leg'];
- local neck = Torso.Neck;
- LL.CanCollide = true;
- RL.CanCollide = true;
- RA.CanCollide = true;
- LA.CanCollide = true;
- local LS,RS = Torso['Left Shoulder'],Torso['Right Shoulder'];
- local SCC = Workspace:WaitForChild('Server_Client_Communications');
- local Cam = Workspace.CurrentCamera;
- local DamageDeals = SCC.DamageDeals;
- local ControlListeners = SCC.ControlListeners;
- local PlayerGui = Player.PlayerGui;
- local mouse = Player:GetMouse()
- repeat wait(0) until Player:FindFirstChild('Stats');
- local Stats = Player.Stats;
- local fatigue = Stats.Fatigue
- local mana = Stats.Mana
- print('A')
- -- GUI Variables
- local Scripts = PlayerGui:WaitForChild("Scripts");
- local EmoteSelection = Scripts.EmoteSelection;
- local EmoteFrame = EmoteSelection.Frame;
- local playsound = Scripts.PlaySound;
- local Bow = Scripts.Bow
- local Magic = Scripts.Magic;
- local Arrows = Bow.Arrows;
- local ebutton = Scripts.EDisplay;
- local Blade = Scripts.Blade
- local MouseDisplay = PlayerGui:WaitForChild("MouseDisplay");
- local cursor = MouseDisplay.Cursor;
- local cursor2 = MouseDisplay.Cursor2;
- local framestab = {a = cursor2.Menu.Trade, b = cursor2.Menu.Invite, c = cursor2.Menu.Inspect}
- local connectionstab = {a = nil, b = nil, c = nil}
- local lpgui = Lighting.LockPicking
- local hitsmoke = Lighting.HitSmoke;
- --UDim2 Variables
- local UDim2_new = UDim2.new;
- wait()
- --CFrame Variables
- local CFrame_new = CFrame.new;
- local CFrame_fromEulerAnglesXYZ = CFrame.fromEulerAnglesXYZ;
- local CFrame_Angles = CFrame.Angles;
- local coroutine_resume = coroutine.resume;
- local coroutine_create = coroutine.create;
- --Math Variables
- local math_pi = math.pi;
- local math_random = math.random;
- local math_floor = math.floor;
- --Instancing
- local Instance_new = Instance.new;
- --BrickColor Variables
- local BrickColor_new = BrickColor.new;
- -- Ray
- local Ray_new = Ray.new;
- --String Manipulation
- local string_byte = string.byte;
- local string_lower = string.lower;
- --Vector3 Variables
- local Vector3_new = Vector3.new;
- local barreloffset=Vector3_new(-.05,.5,-1.5)
- local windvec=Vector3_new(2,-1,1).unit
- local MaxVelocity = Vector3.new(4000000,4000000,4000000);
- local MaxPower = 500000;
- --Mathematical Variables
- local math_floor = math.floor;
- --UDim2 Variables
- local UDim2_new = UDim2.new;
- --BrickColor Variables
- local BrickColor_new = BrickColor.new;
- --String variables
- local string_byte = string.byte;
- local keys = {"z", "x", "c", "f", "r"}
- local Emotes = {
- ['Charge'] = {
- {"http://roblox.com/asset?id=105374058",.7}
- },
- ['Hey'] = {
- {"http://roblox.com/asset?id=88115474",.7},
- {"http://roblox.com/asset?id=88115998",.7},
- {"http://www.roblox.com/asset/?id=33722497",1.1}
- },
- ['Laugh'] = {
- {"http://roblox.com/asset?id=99800145",.7},
- {"http://roblox.com/asset?id=88108591",.7},
- {"http://www.roblox.com/asset/?id=43152481",.7},
- {"http://roblox.com/asset?id=24721901",.5},
- {"http://www.roblox.com/asset/?id=59774613",1}
- },
- ['Threaten'] = {
- {"http://roblox.com/asset?id=95457922",.7},
- {"http://roblox.com/asset?id=73199026",.7},
- {"http://roblox.com/asset?id=22953881",.85},
- {"http://roblox.com/asset?id=21420936",.9}
- },
- ['Insult'] = {
- {"http://roblox.com/asset?id=73198935",.7},
- },
- ['Stop!'] = {
- {"http://roblox.com/asset?id=73199074",.7},
- {"http://roblox.com/asset?id=73199059",.65}
- },
- }
- local EmoteBinds = {
- ["c"] = 'Charge',
- ['e'] = 'Hey',
- ['r'] = 'Laugh',
- ['t'] = 'Threaten',
- ['y'] = 'Insult',
- ['u'] = 'Stop!',
- }
- -- Integer variables
- local KEY_CLICK_DATA = {
- ['s'] = 0,
- ['w'] = 0
- }
- local Controllers = {};
- local LMBDown = 0;
- local keyDeb = 0;
- local ecount = 0;
- local rDeb = 0;
- local ecount = 0;
- local range=400
- local rate=1/30
- local deb = 0
- local AttackSpeedRanges = {
- ['<10>5'] = .5,
- ['<5>1'] = .25,
- ['<100>10'] = 1
- }
- local ShieldBlockC0 = CFrame_new(-0.830965996, 0.34894082, -0.628365874, -0.158662021, -0.47646451, -0.864759207, -0.935743272, -0.206848741, 0.285654992, -0.314978659, 0.854514956, -0.413029432);
- local DefaultShoulderC0 = CFrame_new(-0.992352366, 0.321608782, -0.153558239, -0.191315085, 0.412618041, -0.89058727, -0.948529541, 0.15557532, 0.275841504, 0.252370805, 0.897520781, 0.361616075);
- local DefaultPostC0 = CFrame_new(-0.200751364, -0.921221197, -5.36663549e-008, -0.997495294, 4.47034836e-008, 0.0707372129, 0.0707372129, -4.47034836e-008, 0.997495294, 4.77537014e-008, 1, 4.14293098e-008);
- local DefaultNeckC0 = neck.C0;
- local DefaultRightShoulderC0 = CFrame_new(0.91873014, 0.396266162, -1.03867185, 0.0859837234, -0.272994965, 0.958165526, 0.984390318, 0.171518028, -0.039469406, -0.153567985, 0.946602285, 0.283481032)
- local DS1 = CFrame_new(0.633589745, 0.882619858, -0.599454701, 0.141679958, 0.45801276, 0.87758261, 0.871429145, -0.478275061, 0.108926535, 0.469615579, 0.749318361, -0.466887653);
- local DS2 = CFrame_new(1.01355135, 0.649675727, -1.19620419, 0.139684856, -0.424679399, 0.894503236, 0.94930315, 0.314362228, 0.00100597553, -0.281625211, 0.849014103, 0.447061062);
- --null
- local cycling = {};
- local lastcycled
- local Targeting;
- local sword;
- local EmoteChoose;
- local sword2;
- local s;
- local swingWithOut = nil
- local ArrowAnim = nil
- local leftSlash = nil
- local leftFast = nil
- local OHSwing = nil
- local rightSlash = nil
- local rightFast = nil
- local stabone = nil
- local stabtwo = nil
- local humanoid = nil
- local enabled = false
- local pcf;
- local pst;
- local pcf2;
- local pst2;
- local equipped = false
- local up = false
- local clicked = false
- local dtab = {};
- local pickevents = {};
- local pickmove;
- local speed;
- local wt;
- local dpos;
- local spos;
- -- Object Instancing
- local VurnerabilityDamage = Instance.new('NumberValue',Char);
- VurnerabilityDamage.Name = 'VurnerabilityDamage';
- local stagger = Instance.new('NumberValue',Char)
- stagger.Name = 'Stagger';
- stagger.Value = false;
- local blocking = Instance.new('BoolValue',Char);
- blocking.Name = 'Blocking';
- blocking.Value = false;
- local swinging = Instance_new('BoolValue',Char);
- swinging.Name = 'Swinging';
- local emote = Instance.new('Sound',Torso);
- emote.Volume = 1;
- local unsheath = Instance_new('Sound',Torso)
- unsheath.Volume = 1;
- unsheath.Pitch = .8;
- unsheath.SoundId = 'http://roblox.com/asset?id=109362789';
- ContentProvider:preload(unsheath.SoundId)
- local shieldbash = Instance_new('Sound',Torso)
- shieldbash.Name = 'ShieldBash';
- shieldbash.SoundId = 'http://roblox.com/Asset?id=92597264';
- shieldbash.Pitch = .4;
- shieldbash.Volume = 1;
- ContentProvider:preload(shieldbash.SoundId);
- local impact = Instance_new('Sound',Torso)
- impact.Name = 'Impact';
- impact.Volume = .35;
- impact.Pitch = .8;
- local swoosh = Instance_new('Sound',Torso)
- swoosh.Volume = .5;
- swoosh.Pitch = 1;
- --http://roblox.com/asset?id=109362710
- swoosh.SoundId = 'http://roblox.com/asset?id=119888724';
- ContentProvider:preload(swoosh.SoundId)
- local shieldup = Instance_new('Sound',Torso);
- shieldup.Volume = 1;
- shieldup.Pitch = 1.1;
- shieldup.SoundId = 'http://roblox.com/asset?ID=92597296';
- ContentProvider:preload(shieldup.SoundId);
- --Animations
- local swooshdata = {
- [1] = 1,
- [2] = 1.5,
- [3] = .5,
- [4] = 1,
- [5] = 1.5,
- [6] = 2,
- [7] = 2
- }
- local swinganims = {
- [1] = {Human:LoadAnimation(Scripts.LeftSlash),0,5},
- [2] = {Human:LoadAnimation(Scripts.LeftSwingFast),0,5},
- [3] = {Human:LoadAnimation(Scripts.OverHeadSwing),20,30},
- [4] = {Human:LoadAnimation(Scripts.RightSlash),0,5},
- [5] = {Human:LoadAnimation(Scripts.RightSwingFast),0,5},
- [6] = {Human:LoadAnimation(Scripts.Stab1),0,3},
- [7] = {Human:LoadAnimation(Scripts.Stab2),0,3}
- }
- local parry = Human:LoadAnimation(Scripts.Block);
- local kickback = Human:LoadAnimation(Scripts.Kickback);
- local staggeranim = Human:LoadAnimation(Scripts.Stagger);
- local swingWithOut = Human:LoadAnimation(Scripts.twohandswordwithswingout);
- local equip = Human:LoadAnimation(Scripts.Equip);
- local ArrowAnim = Human:LoadAnimation(Scripts.ArrowAnim);
- local OffHand = Scripts.OffHand;
- local function ResumeControl()
- for _,v in pairs(Controllers) do
- print(v,' : ',type(v))
- v.Parent = ControllerService;
- end
- end
- local function HaltControl()
- Controllers = {};
- for _,v in pairs(ControllerService:GetChildren()) do
- Controllers[#Controllers+1] = v;
- v.Parent = nil
- end
- end
- local function CreateFake(...)
- local args = {...}
- for _,p in pairs(args) do
- local clone = p:Clone();
- clone.Parent = Cam;
- clone.Name = 'Fake'..p.Name;
- clone.CFrame = p.CFrame;
- local w = Instance.new('Weld',Cam);
- w.Part0 = p;
- w.Part1 = clone;
- end
- end
- --CreateFake(RA,LA,Torso,RL,LL)
- wait(0)
- local function CanCollideAll(...)
- local args = {...}
- for _,v in pairs(args) do
- v.CanCollide = true;
- end
- end
- CanCollideAll(LA,RA,LL,RL);
- local function PreloadChildren(tab)
- for _,v in pairs(tab) do
- if type(v) == 'string' and v:sub(1,3) == 'htt' then
- print('Preloading: '..v)ContentProvider:preload(v);
- elseif type(v) == 'table' then
- PreloadChildren(v)
- end
- end
- end
- print('Preloaded');
- PreloadChildren(Emotes);
- local function resetct()
- for i,v in pairs(connectionstab) do
- if v ~= nil then
- v:disconnect();
- v = nil
- end
- end
- end
- local function checkdistance(obj)
- if (Torso.Position - obj.Position).magnitude <= 7 then
- return true
- else
- return false
- end
- end
- local function error(text, duration)
- local precount = 0
- ebutton.Visible = true
- ebutton.Text = text
- ebutton.TextTransparency = 0
- wait(duration)
- repeat
- wait(.1)
- ebutton.TextTransparency = ecount
- ecount = ecount + 0.1
- precount = ecount
- if precount > ecount then
- break
- end
- until ecount >= 1
- if ecount > 1 then
- ecount = 1
- end
- ebutton.Visible = false
- end
- local function tagHumanoid(humanoid, Player)
- local tag = Instance_new("ObjectValue")
- tag.Value = Player
- tag.Name = "Source"
- tag.Parent = humanoid
- coroutine_resume(coroutine_create(function()
- wait(3)
- tag:Destroy()
- end))
- end
- local function damagef(mon, Player, what,extra)
- local block = game.Lighting.DamageDeal:clone()
- local wep = Blade.Value.Damage;
- local damage = math_random(wep.Value - 2, wep.Value + 2) + extra;
- block.TextLabel.Text = tostring(damage) + Stats[what].Value
- block.Parent = mon.Parent.Parent.Head
- block.Adornee = mon.Parent.Parent.Head
- mon.Health.Value = mon.Health.Value - (damage + Stats[what].Value)
- debris:AddItem(block, .5)
- end
- local damagep = function(char,extra)
- local head = char:FindFirstChild('Head');
- local wep = Blade.Value.Damage;
- local damage = math_random(wep.Value - 2, wep.Value + 2) + extra;
- local DamageGui = DamageGUI:Clone();
- local frame = DamageGui.Frame;
- DamageGui.Parent = head;
- DamageGui.Adornee = head;
- frame.TextLabel.Text = '-'..tostring(damage);
- debris:AddItem(DamageGui,2)
- local damageval = Instance_new('NumberValue',DamageDeals);
- damageval.Name = char.Name;
- damageval.Value = damage;
- end
- local function cframe(part, to, offset, on, nn)
- local bad = part:findFirstChild(on)
- if bad then
- bad:Destroy()
- end
- local tw = Instance_new("Weld", part)
- tw.Part0 = to
- tw.Part1 = part
- tw.Name = nn
- if offset ~= nil then
- tw.C0 = offset
- coroutine_resume(coroutine_create(function()wait(2) tw.C0 = offset end))
- end
- end
- local function checkintangible(hit)
- if hit and hit~=nil then
- if hit:IsDescendantOf(sword.Parent) or hit.Transparency>.9 or hit.Name=="Handle" or hit.Name=="Effect" or hit.Name=="Bullet" or hit.Name=="Laser" or string_lower(hit.Name)=="water" or hit.Name=="Rail" or hit.Name=="Arrow" then
- return true
- end
- end
- return false
- end
- local CombatMode = function()
- InCombatMode = true
- bg = Instance_new('BodyGyro',Torso);
- bg.maxTorque = Vector3.new(0,400000,0);
- bg.D = 200;
- while InCombatMode do wait(.1);
- bg.cframe = Targeting ~= nil and CFrame_new(Torso.Position,Targeting.Position)
- or Cam.CoordinateFrame;
- if Targeting then
- Cam:Interpolate(CFrame_new(Head.Position + -(Head.CFrame.lookVector*20) + Vector3.new(0,8,0)),Targeting.CFrame,.2)
- end
- end
- bg:Destroy();
- end
- Sheathed = true
- local function Sheath()
- if Sheathing or Sheathed then return end
- Cam.CameraType = 'Custom'
- Targeting = nil
- blocking.Value = false;
- Sheathing = true
- InCombatMode = nil;
- equipped = false
- if sword then
- if sword.Parent ~= nil then
- if sword:findFirstChild("Blade") then
- if sword.Blade:FindFirstChild("Script") ~= nil then
- sword.Blade.Script.Disabled = true
- end
- Scripts.Bow.Value = false
- end
- cframe(sword.Handle, pst, pcf, "Post", "Pre")
- end
- end
- if sword2 then
- if sword2:FindFirstChild("Shield") then
- cframe(sword2.Handle, pst2, pcf2, "Post", "Pre")
- end
- end
- if swingWithOut then
- for _,v in pairs(swinganims) do v = nil; end
- end
- Sheathed = true
- wait(1)
- Sheathing = nil;
- end
- local SpawnSmoke = function(cf,col)
- local cf = cf * CFrame.new(0,-5,0)
- coroutine_resume(coroutine_create(function()
- local smokepart = Instance.new('Part',Workspace);
- smokepart.CFrame = cf;
- smokepart.Anchored,smokepart.CanCollide,smokepart.Transparency = true,false,1;
- local smoke = Instance.new('Smoke');
- smoke.Size = .2;
- smoke.Color = col.Color;
- smoke.Opacity = .5
- smoke.RiseVelocity = 50
- smoke.Parent = smokepart;
- wait(1)
- smoke.Enabled = false
- end))
- end
- local function PartUnder(p)
- local partray = Ray_new(p.Position,Vector3.new(0,-10,0))
- local partunder,position = Workspace:FindPartOnRayWithIgnoreList(partray,{Char});
- return partunder;
- end
- local function knockback(am)
- local partunder = PartUnder(RL);
- local Underhit;
- coroutine_resume(coroutine_create(function() Sheath() end))
- kickback:Play()
- Human.Sit = true
- Torso.Velocity = -(Torso.CFrame.lookVector * am);
- local underhitcheck = Torso.Touched:connect(function(obj)
- if obj == partunder or obj.Name:match('Terrain') then
- Underhit = true
- end
- end)
- repeat wait(0) until Underhit
- print('Landed!');
- for i = 1, 14 do
- local partunder = PartUnder(RL);
- SpawnSmoke(Torso.CFrame * CFrame.new(0,-2,0),partunder and partunder.BrickColor or BrickColor_new('Pastel brown'));
- wait(.1);
- end
- kickback:Stop()
- end
- pcall(function() Head.face:Destroy(); end)
- pcall(function() Head.Parent:WaitForChild('FakeHead').face:Destroy(); end)
- local function SeverHead(veloc,headd)
- local ch = headd.Parent;
- local head;
- if headd.Name == 'FakeHead' then head = headd print('Fake')
- else
- head = ch.FakeHead
- end
- head.Transparency = 0
- local fakehead = head:clone();
- fakehead.CanCollide = true
- fakehead.Anchored = true
- local velo = Instance.new('BodyVelocity',fakehead)
- velo.maxForce = Vector3.new(400000,400000,400000)
- velo.P = 16000.000;
- fakehead.CFrame = head.CFrame;
- fakehead.Parent = Workspace;
- fakehead.Transparency = 0
- wait(0)
- head.Transparency = 1;
- velo.velocity = veloc * 10;--fakehead.CFrame:vectorToWorldSpace(Vector3.new(-6,0,8));
- fakehead.Anchored = false;
- wait(.5)
- velo:Destroy();
- end
- wait(2)
- --SeverHead(Head)
- local function FindSpeed()
- for _,v in pairs(AttackSpeedRanges) do
- local les,gre = _:match('<(.-)>(.+)');
- les,gre = tonumber(les),tonumber(gre);
- local val = fatigue.Value;
- if val < les and val > gre then
- return v
- end
- end
- return 1;
- end
- local function go(tab,targetpos,startpos,fadedelay)
- if enabled then return end
- local HandSlot = Char.HandSlot.Weld;
- cursor.Visible = false
- cursor2.Visible = false
- resetct()
- if equipped == true then
- enabled = false
- wait()
- if Bow.Value == false and Magic.Value == false then
- local swingbacks = {};
- local t;
- local touched;
- local handle,blade = sword.Handle,sword.Blade;
- local torso = Torso;
- local weld = torso:FindFirstChild('Right Shoulder');
- local ra = weld.Part1;
- local rn = tab[math_random(1,#tab)];
- local currentanim = swinganims[rn]
- swoosh.Pitch = swooshdata[rn];
- wait(0)
- local anim = currentanim[1];
- local extra = currentanim[2];
- local cost = currentanim[3];
- local calc = fatigue.Value - cost;
- if calc > 0 then
- fatigue.Value = calc;
- local spd = FindSpeed();
- coroutine_resume(coroutine_create(function()
- TweenPart(HandSlot,HandSlot.C0,HandSlot.C0 * CFrame.Angles(-1.5,0,0),spd/2.5)
- end))
- anim:Play(0,1,spd);
- swoosh:Play();
- t = blade.Touched:connect(function(hit)
- --Shield Parry
- if touched or (hit.Name:find('Terrain')) or hit.Name:find('Part') or not hit.Parent then return end
- if hit.Parent.Name:find('Shield') then
- anim:Stop()
- touched = true;
- local shield = hit.Parent;
- shieldbash:Play();
- local possiblechar = Players:FindFirstChild(shield.Name:match("(.-)'s"));
- print(possiblechar)
- if possiblechar and possiblechar.Character.Swinging.Value == true then
- knockback(60);
- local health = Stats.Health;
- health.Value = health.Value - 5;
- else
- --code
- end
- return;
- end
- local ch;
- local par = hit.Parent;
- if Players:FindFirstChild(par.Name) then
- ch = par;
- elseif Players:FindFirstChild(par.Parent.Name) then
- ch = par.Parent;
- end
- impact.SoundId = hit.Name ~= 'Blade' and 'http://roblox.com/asset?id=96667969' or
- 'http://roblox.com/asset?id=62339698';
- impact.Pitch = hit.Name ~= 'Blade' and .6 or .8;
- wait(0)
- impact:Play();
- touched = true;
- if ch then
- damagep(ch,(extra + ch.VurnerabilityDamage.Value));
- end
- end)
- wait(0);
- enabled = true
- local tim = (spd < 1 and 4 or 1.25)
- print(tim);
- wait(tim);
- t:disconnect();
- coroutine_resume(coroutine_create(function()
- TweenPart(HandSlot,HandSlot.C0,HandSlot.C0 * CFrame.Angles(1.5,0,0),.25)
- end))
- enabled = false
- --anim:Stop();
- --TweenPart(RS,RS.C0,DefaultRightShoulderC0,.1);
- else
- enabled = true
- end
- end
- end
- end
- local function mainhand()
- if Blade.Value ~= nil then
- equipped = true
- sword = Blade.Value
- if sword.Handle then
- pcf = sword.Handle.Pre.C0
- pst = sword.Handle.Pre.Part0
- if sword:findFirstChild("Blade") then
- equip:Play()
- wait(.5)
- cframe(sword.Handle, Char.HandSlot, nil, "Pre", "Post")
- wait(1.5)
- if Blade:FindFirstChild("Script") ~= nil then
- Blade.Script.Disabled = false
- end
- Bow.Value = false
- else
- if Bow.Value == true then
- cframe(sword.Handle, Char.HandSlot2, nil, "Pre", "Post")
- end
- end
- end
- end
- end
- local function offhand()
- if OffHand.Value then
- sword2 = OffHand.Value
- sword2.Name = Player.Name.."'s "..sword2.Name;
- if sword2:FindFirstChild("Shield") then
- pcf2 = sword2.Handle.Pre.C0
- pst2 = sword2.Handle.Pre.Part0
- local offsetshield = CFrame_new(-.5,0,0) * CFrame_fromEulerAnglesXYZ(0,math_pi/2,math_pi/2)
- cframe(sword2.Handle, Char["Left Arm"], DefaultPostC0, "Pre", "Post")
- end
- end
- end
- local Dash = function(direction)
- print('Dash')
- local lv = direction == 'back' and -Torso.CFrame.lookVector or Torso.CFrame.lookVector;
- local partunder = PartUnder(RL);
- local jumpamount = Torso.Velocity.magnitude > 5 and 150 or 100;
- SpawnSmoke(RL.CFrame * CFrame.new(0,-1,0),partunder and partunder.BrickColor or BrickColor_new('White'));
- local bv = Instance_new('BodyVelocity',Torso);
- bv.maxForce = MaxVelocity;
- bv.P = MaxPower;
- bv.velocity = lv * jumpamount wait(.1) bv.P = 0;
- bv:Destroy();
- end
- local function Unsheath()
- if Unsheathing or not Sheathed then return end
- blocking.Value = true;
- Unsheathing = true;
- coroutine_resume(coroutine_create(function()
- wait(.7)
- unsheath:Play();
- end))
- coroutine_resume(coroutine_create(CombatMode));
- coroutine_resume(coroutine_create(mainhand))
- TweenPart(RS,RS.C0,DefaultRightShoulderC0,.25)
- coroutine_resume(coroutine_create(offhand))
- startarmcf = Char:FindFirstChild('Right Arm').CFrame
- Sheathed = nil
- wait(1)
- Unsheathing = nil;
- end
- equipped = false;
- local function EmoteSelect()
- print('EmoteSelect')
- EmoteFrame.Visible = not EmoteFrame.Visible;
- wait(0)
- if EmoteFrame.Visible == true then
- ChoosingEmote = true;
- EmoteChoose = mouse.KeyDown:connect(function(key)
- if EmoteBinds[key] and not voice then
- voice = true
- local CurrentEmote = EmoteBinds[key];
- local label = EmoteFrame[CurrentEmote];
- label.BackgroundTransparency = .7
- local EmotesData = Emotes[CurrentEmote];
- local RandomEmoteTable = EmotesData[math_random(1,#EmotesData)];
- emote.SoundId = RandomEmoteTable[1];
- emote.Pitch = RandomEmoteTable[2];
- wait(0)
- emote:play();
- wait(.1)
- label.BackgroundTransparency = .9
- EmoteSelect();
- wait(1.9)
- voice = nil
- end
- end)
- else
- ChoosingEmote = nil;
- EmoteChoose:disconnect();
- end
- end
- local function LowerShield()
- TweenPart(LS,LS.C0,DefaultShoulderC0,.1);
- end
- local function RaiseShield()
- LS.DesiredAngle = 0;
- LS.MaxVelocity = 1;
- shieldup:Play();
- TweenPart(LS,LS.C0,ShieldBlockC0,.25);
- swinging.Value = true
- coroutine_resume(coroutine_create(function()
- wait(2)
- swinging.Value = false
- end))
- end
- local function DownSlash()
- TweenPart(RS,RS.C0,DS1,1);
- TweenPart(RS,RS.C0,DS2,.5);
- end
- local function ShieldBash()
- RaiseShield()
- if OffHand.Value == nil then return end
- bashing = true;
- local shieldc = LS.C0;
- local bash;
- local notcontinue;
- local touched;
- local shield = OffHand.Value.Handle;
- local i = 0;
- while bashing and i < 6 do wait(0)
- i = i + 1;
- LS.C0 = LS.C0 * CFrame.new(0,0,-.06)
- end
- bash = shield.Touched:connect(function(hit)
- if touched or (hit.Name:find('Terrain')) or hit.Name:find('Part') or not hit.Parent then return end
- if hit.Parent.Name:find('Shield') then
- touched = true;
- local shield = hit.Parent;
- shieldbash:Play();
- return;
- end
- local ch;
- local par = hit.Parent;
- if Players:FindFirstChild(par.Name) then
- ch = par;
- elseif Players:FindFirstChild(par.Parent.Name) then
- ch = par.Parent;
- end
- shieldbash:Play();
- touched = true;
- if ch and ch:FindFirstChild('Stagger') then
- local stag = ch:FindFirstChild('Stagger');
- stag.Value = (Torso.Velocity.magnitude/2.5)*3;
- end
- end)
- local i = 0;
- while bashing and i < 5 do wait(0)
- i = i + 1;
- LS.C0 = LS.C0 * CFrame.new(0,0,.3)
- end
- i = 0;
- while bashing and i < 5 do wait(0)
- i = i + 1;
- LS.C0 = LS.C0 * CFrame.new(0,0,-.3)
- end
- wait((bashing and .5 or 0));
- if bash then
- bash:disconnect()
- end
- LS.C0 = shieldc;
- LowerShield();
- end
- local function CycleTargets()
- cycling = {};
- for _,v in pairs(Players:GetPlayers()) do
- if v ~= Player and Workspace:FindFirstChild(v.Name) then
- local char = Workspace:FindFirstChild(v.Name)
- local tors = char.Torso
- if (tors.Position-Torso.Position).Magnitude < 20 and
- tors ~= lastcycled then
- cycling[#cycling+1] = tors;
- end
- end
- end
- if #cycling >0 then print('Found torso')
- local rt = cycling[math_random(1,#cycling)];
- print(rt)
- lastcycled = rt;
- Cam.CameraType = 'Scriptable'
- Targeting = rt;
- else
- Cam.CameraType = 'Custom'
- Targeting = nil
- lastcycled = nil;
- end
- end
- local function Control(...)
- local params = {...};
- local name = params[1];
- if name == 'wander' then print('Wandering');
- knockback(30)
- for i = 1, 4 do
- local wanderpart = Instance_new('Part');
- wanderpart.CFrame = Torso.CFrame * CFrame.new(math_random(6,8),0,math_random(6,8));
- Human:MoveTo(wanderpart.Position,wanderpart);
- wait(3)
- end
- elseif name == 'knockback' then
- knockback(50);
- end
- wait(3)
- KeysLocked = false;
- end
- local StaggerAnimation = function()
- Staggering = true
- coroutine_resume(coroutine_create(function()
- staggeranim:Play();
- wait(.5)
- staggeranim:Stop();
- while Staggering do
- TweenPart(neck,neck.C0,DefaultNeckC0 * CFrame.Angles(math_random(2,12)/10,0,0),1)
- wait(0)
- end
- end))
- end
- local charging = nil
- local ControlListener = ControlListeners.ChildAdded:connect(function(obj)
- local vec = obj.Value*Vector3.new();
- local magn = (Torso.Position-vec).Magnitude;
- print(vec,magn)
- local name,msg = obj.Name:match('(.-)/(.+)');
- if magn < 20 then
- KeysLocked = msg;
- Sheath();
- Control(name)
- end
- end)
- local DamageListener = DamageDeals.ChildAdded:connect(function(obj)
- if Damaged then return end
- Damaged = true
- print(obj)
- if not obj.Name == Player.Name then return end
- local health = Stats.Health;
- health.Value = health.Value - obj.Value;
- if health.Value <= 0 then KeysLocked = 'Dead' knockback(10)
- if Player.Name == Head1.Value.Parent.Name then
- Won.Value = Head2 and Head2.Value.Parent.Name or '';
- elseif Player.Name == Head2.Value.Parent.Name then
- Won.Value = Head1 and Head1.Value.Parent.Name or '';
- end
- InBattle.Value = false;
- script:Destroy();
- end
- wait(1)
- Damaged = nil;
- end)
- local StaggerListener = stagger.Changed:connect(function()
- if not InCombatMode or StaggerFiring then return end
- HaltControl();
- VurnerabilityDamage.Value = 5;
- StaggerFiring = true
- KeysLocked = 'Staggered'
- print('STAGGERING')
- StaggerAnimation()
- local walkback = Instance.new('Part',Workspace);
- walkback.Transparency,walkback.CanCollide = 1,false;
- walkback.CFrame = CFrame_new(Torso.Position + -Torso.CFrame.lookVector * stagger.Value)
- Human:MoveTo(walkback.Position,walkback);
- wait(8)
- Staggering = false
- TweenPart(neck,neck.C0,DefaultNeckC0,.25)
- KeysLocked = nil
- StaggerFiring = false
- ResumeControl()
- VurnerabilityDamage.Value = 10;
- end)
- local AntiJump = Human.Changed:connect(function()
- if InCombatMode then
- Human.Jump = false;
- end
- end)
- local MouseListeners = {
- ['WheelForward'] = function() if not InCombatMode then return end go({6,7},mouse.hit.p, Head.Position, .25) end,
- ['WheelBackward'] = function() if not InCombatMode then return end DownSlash(); end,
- ['KeyDown'] = function(key)
- if KeysLocked then error(KeysLocked,.5); return elseif ChoosingEmote then return end
- local doubleclickbool = false;
- if KEY_CLICK_DATA[key] then
- KEY_CLICK_DATA[key] = KEY_CLICK_DATA[key] + 1;
- coroutine_resume(coroutine_create(function() wait(.25) KEY_CLICK_DATA[key] = 0; end))
- if KEY_CLICK_DATA[key] < 2 then doubleclickbool = false; else doubleclickbool = true end
- end
- print(doubleclickbool)
- local calc = fatigue.Value;
- if key == "e" then
- if equipped == false and Blade.Value then
- Unsheath();
- elseif equipped == true then
- Sheath();
- end
- elseif key == 's' and doubleclickbool == true and calc >= 5 then
- fatigue.Value = fatigue.Value - 5;
- coroutine_resume(coroutine_create(function()Dash('back')end));
- elseif key == 'w' and doubleclickbool == true and calc >= 5 then
- fatigue.Value = fatigue.Value - 5;
- coroutine_resume(coroutine_create(function()Dash('forward')end));
- elseif key == 'z' then
- EmoteSelect();
- elseif key == 'f' and calc >= 30 then
- fatigue.Value = fatigue.Value - 30;
- ShieldBash()
- elseif key == 't' then
- CycleTargets()
- end
- keyDeb = 0
- end,
- ['Button2Down'] = function() print('Firing')
- if KeysLocked then error(KeysLocked,.5); return end
- if not InCombatMode then return end print('Playing')
- local calc = fatigue.Value;
- if OffHand.Value and calc >= 2 and OffHand.Value.Name:match('Shield') then
- fatigue.Value = fatigue.Value - 2;
- RaiseShield();
- coroutine_resume(coroutine_create(function()wait(5)LowerShield()end))
- end
- end,
- ['Button2Up'] = function() print('Firing')
- if not InCombatMode then return end print('Playing')
- if OffHand.Value and OffHand.Value.Name:match('Shield') then
- LowerShield();
- end
- end,
- ['Button1Down'] = function()
- if KeysLocked then error(KeysLocked,.5); return end
- if not InCombatMode then return end
- go({1,2,4,5},mouse.hit.p,Head.Position,.25)
- end
- }
- for _,v in pairs(MouseListeners) do
- mouse[_]:connect(v);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement