Advertisement
tyridge77

CombatEngine

Aug 20th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.58 KB | None | 0 0
  1. NOTE = [=[
  2.  
  3. This is the combat 'engine' I'm working on for now.
  4. 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.
  5. 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.
  6.  
  7. ]=]
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. wait(5)
  15.  
  16.  
  17. --INTERPOLATE CFRAME
  18.  
  19.  
  20.  
  21. -- By Anaminus
  22.  
  23.  
  24. function QuaternionFromCFrame(cf)
  25.     local mx,  my,  mz,
  26.           m00, m01, m02,
  27.           m10, m11, m12,
  28.           m20, m21, m22 = cf:components()
  29.     local trace = m00 + m11 + m22
  30.     if trace > 0 then
  31.         local s = math.sqrt(1 + trace)
  32.         local recip = 0.5/s
  33.         return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5
  34.     else
  35.         local i = 0
  36.         if m11 > m00 then i = 1 end
  37.         if m22 > (i == 0 and m00 or m11) then i = 2 end
  38.         if i == 0 then
  39.             local s = math.sqrt(m00-m11-m22+1)
  40.             local recip = 0.5/s
  41.             return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip
  42.         elseif i == 1 then
  43.             local s = math.sqrt(m11-m22-m00+1)
  44.             local recip = 0.5/s
  45.             return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip
  46.         elseif i == 2 then
  47.             local s = math.sqrt(m22-m00-m11+1)
  48.             local recip = 0.5/s
  49.             return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip
  50.         end
  51.     end
  52. end
  53.  
  54. function QuaternionToCFrame(px, py, pz, x, y, z, w)
  55.     local xs, ys, zs = x + x, y + y, z + z
  56.     local wx, wy, wz = w*xs, w*ys, w*zs
  57.     --
  58.     local xx = x*xs
  59.     local xy = x*ys
  60.     local xz = x*zs
  61.     local yy = y*ys
  62.     local yz = y*zs
  63.     local zz = z*zs
  64.     --
  65.     return CFrame.new(px,        py,        pz,
  66.                       1-(yy+zz), xy - wz,   xz + wy,
  67.                       xy + wz,   1-(xx+zz), yz - wx,
  68.                       xz - wy,   yz + wx,   1-(xx+yy))
  69. end
  70.  
  71. function QuaternionSlerp(a, b, t)
  72.     local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4]
  73.     local startInterp, finishInterp;
  74.     if cosTheta >= 0.0001 then
  75.         if (1 - cosTheta) > 0.0001 then
  76.             local theta = math.acos(cosTheta)
  77.             local invSinTheta = 1/math.sin(theta)
  78.             startInterp = math.sin((1-t)*theta)*invSinTheta
  79.             finishInterp = math.sin(t*theta)*invSinTheta
  80.         else
  81.             startInterp = 1-t
  82.             finishInterp = t
  83.         end
  84.     else
  85.         if (1+cosTheta) > 0.0001 then
  86.             local theta = math.acos(-cosTheta)
  87.             local invSinTheta = 1/math.sin(theta)
  88.             startInterp = math.sin((t-1)*theta)*invSinTheta
  89.             finishInterp = math.sin(t*theta)*invSinTheta
  90.         else
  91.             startInterp = t-1
  92.             finishInterp = t
  93.         end
  94.     end
  95.     return a[1]*startInterp + b[1]*finishInterp,
  96.            a[2]*startInterp + b[2]*finishInterp,
  97.            a[3]*startInterp + b[3]*finishInterp,
  98.            a[4]*startInterp + b[4]*finishInterp        
  99. end
  100.  
  101. function TweenPart(part, a, b, length)
  102.     moving = nil
  103.     wait(0)
  104.     moving = true
  105.     local qa = {QuaternionFromCFrame(a)}
  106.     local qb = {QuaternionFromCFrame(b)}
  107.     local ax, ay, az = a.x, a.y, a.z
  108.     local bx, by, bz = b.x, b.y, b.z
  109.     --
  110.     local c = 0
  111.     local tot = 0
  112.     --
  113.     local startTime = tick()
  114.     while moving do
  115.         wait()
  116.         local t = (tick()-startTime)/length
  117.         local _t = 1-t
  118.         if t > 1 then break end
  119.         local startT = tick()
  120.         local cf = QuaternionToCFrame(_t*ax + t*bx, _t*ay + t*by, _t*az + t*bz,
  121.                                          QuaternionSlerp(qa, qb, t))
  122.         tot = tot+(tick()-startT)
  123.         c = c + 1
  124.         part.C0 = cf
  125.     end
  126. end
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. local PoolCommunication = Workspace.PoolCommunication;
  140. local Won = PoolCommunication.Won;
  141. local InBattle = PoolCommunication.InBattle;
  142. local Head1,Head2 = PoolCommunication.Head1,PoolCommunication.Head2;
  143.  
  144. local Lighting = game:GetService("Lighting");
  145. local DamageGUI = Lighting.DamageGUI;
  146. local ControllerService = game:GetService('ControllerService');
  147. local ContentProvider = game:GetService('ContentProvider');
  148. local debris = game:GetService("Debris");
  149. local Players = game:GetService("Players");
  150. local Player = script.Parent.Parent;
  151. local Char = Player.Character;
  152. repeat wait(0) until Char:FindFirstChild('BackSlot');
  153.  
  154.  
  155. if Char:FindFirstChild('NewAnimate') then
  156. Animate = Char.NewAnimate
  157. else
  158. Animate = Char:WaitForChild('Animate')
  159. end
  160. Animate:Destroy()
  161. Lighting.NewAnimate:Clone().Parent = Char;
  162.  
  163.  
  164. local Head,Torso,Human = Char:WaitForChild("Head"),Char:WaitForChild("Torso"),Char:WaitForChild("Humanoid");
  165. local LL,RL = Char['Left Leg'],Char['Right Leg'];
  166. local RA,LA = Char['Right Arm'],Char['Left Arm'];
  167. local LL,RL = Char['Left Leg'],Char['Right Leg'];
  168. local neck = Torso.Neck;
  169. LL.CanCollide = true;
  170. RL.CanCollide = true;
  171. RA.CanCollide = true;
  172. LA.CanCollide = true;
  173. local LS,RS = Torso['Left Shoulder'],Torso['Right Shoulder'];
  174.  
  175.  
  176. local SCC = Workspace:WaitForChild('Server_Client_Communications');
  177. local Cam = Workspace.CurrentCamera;
  178. local DamageDeals = SCC.DamageDeals;
  179. local ControlListeners = SCC.ControlListeners;
  180.  
  181.  
  182. local PlayerGui = Player.PlayerGui;
  183. local mouse = Player:GetMouse()
  184.  
  185. repeat wait(0) until Player:FindFirstChild('Stats');
  186. local Stats = Player.Stats;
  187.  
  188. local fatigue = Stats.Fatigue
  189. local mana = Stats.Mana
  190.  
  191.  
  192.  
  193. print('A')
  194. -- GUI Variables
  195. local Scripts = PlayerGui:WaitForChild("Scripts");
  196. local EmoteSelection = Scripts.EmoteSelection;
  197. local EmoteFrame = EmoteSelection.Frame;
  198. local playsound = Scripts.PlaySound;
  199. local Bow = Scripts.Bow
  200. local Magic = Scripts.Magic;
  201. local Arrows = Bow.Arrows;
  202. local ebutton = Scripts.EDisplay;
  203. local Blade = Scripts.Blade
  204. local MouseDisplay = PlayerGui:WaitForChild("MouseDisplay");
  205. local cursor = MouseDisplay.Cursor;
  206. local cursor2 = MouseDisplay.Cursor2;
  207. local framestab = {a = cursor2.Menu.Trade, b = cursor2.Menu.Invite, c = cursor2.Menu.Inspect}
  208. local connectionstab = {a = nil, b = nil, c = nil}
  209. local lpgui = Lighting.LockPicking
  210. local hitsmoke = Lighting.HitSmoke;
  211. --UDim2 Variables
  212. local UDim2_new = UDim2.new;
  213. wait()
  214.  
  215. --CFrame Variables
  216. local CFrame_new = CFrame.new;
  217. local CFrame_fromEulerAnglesXYZ = CFrame.fromEulerAnglesXYZ;
  218. local CFrame_Angles = CFrame.Angles;
  219.  
  220.  
  221.  
  222. local coroutine_resume = coroutine.resume;
  223. local coroutine_create = coroutine.create;
  224.  
  225. --Math Variables
  226. local math_pi = math.pi;
  227. local math_random = math.random;
  228. local math_floor = math.floor;
  229.  
  230. --Instancing
  231. local Instance_new = Instance.new;
  232.  
  233. --BrickColor Variables
  234. local BrickColor_new = BrickColor.new;
  235.  
  236. -- Ray
  237. local Ray_new = Ray.new;
  238.  
  239. --String Manipulation
  240. local string_byte = string.byte;
  241. local string_lower = string.lower;
  242.  
  243. --Vector3 Variables
  244. local Vector3_new = Vector3.new;
  245. local barreloffset=Vector3_new(-.05,.5,-1.5)
  246. local windvec=Vector3_new(2,-1,1).unit
  247. local MaxVelocity = Vector3.new(4000000,4000000,4000000);
  248. local MaxPower = 500000;
  249. --Mathematical Variables
  250. local math_floor = math.floor;
  251.  
  252. --UDim2 Variables
  253. local UDim2_new = UDim2.new;
  254.  
  255.  
  256. --BrickColor Variables
  257. local BrickColor_new = BrickColor.new;
  258.  
  259. --String variables
  260. local string_byte = string.byte;
  261. local keys = {"z", "x", "c", "f", "r"}
  262. local Emotes = {
  263. ['Charge'] = {
  264.     {"http://roblox.com/asset?id=105374058",.7}
  265. },
  266. ['Hey'] = {
  267.     {"http://roblox.com/asset?id=88115474",.7},
  268.     {"http://roblox.com/asset?id=88115998",.7},
  269.     {"http://www.roblox.com/asset/?id=33722497",1.1}
  270. },
  271. ['Laugh'] = {
  272.     {"http://roblox.com/asset?id=99800145",.7},
  273.     {"http://roblox.com/asset?id=88108591",.7},
  274.     {"http://www.roblox.com/asset/?id=43152481",.7},
  275.     {"http://roblox.com/asset?id=24721901",.5},
  276.     {"http://www.roblox.com/asset/?id=59774613",1}
  277. },
  278. ['Threaten'] = {
  279.     {"http://roblox.com/asset?id=95457922",.7},
  280.     {"http://roblox.com/asset?id=73199026",.7},
  281.     {"http://roblox.com/asset?id=22953881",.85},
  282.     {"http://roblox.com/asset?id=21420936",.9} 
  283. },
  284. ['Insult'] = {
  285.     {"http://roblox.com/asset?id=73198935",.7},
  286. },
  287. ['Stop!'] = {
  288.     {"http://roblox.com/asset?id=73199074",.7},
  289.     {"http://roblox.com/asset?id=73199059",.65}
  290. },
  291. }
  292. local EmoteBinds = {
  293. ["c"] = 'Charge',
  294. ['e'] = 'Hey',
  295. ['r'] = 'Laugh',
  296. ['t'] = 'Threaten',
  297. ['y'] = 'Insult',
  298. ['u'] = 'Stop!',
  299. }
  300. -- Integer variables
  301. local KEY_CLICK_DATA = {
  302. ['s'] = 0,
  303. ['w'] = 0
  304. }
  305. local Controllers = {};
  306. local LMBDown = 0;
  307. local keyDeb = 0;
  308. local ecount = 0;
  309. local rDeb = 0;
  310. local ecount = 0;
  311. local range=400
  312. local rate=1/30
  313. local deb = 0
  314. local AttackSpeedRanges = {
  315. ['<10>5'] = .5,
  316. ['<5>1'] = .25,
  317. ['<100>10'] = 1
  318. }
  319. 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);
  320. 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);
  321. 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);
  322. local DefaultNeckC0 = neck.C0;
  323. 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)
  324. 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);
  325. 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);
  326.  
  327.  
  328.  
  329. --null
  330. local cycling = {};
  331. local lastcycled
  332. local Targeting;
  333. local sword;
  334. local EmoteChoose;
  335. local sword2;
  336. local s;
  337. local swingWithOut = nil
  338. local ArrowAnim = nil
  339. local leftSlash = nil
  340. local leftFast = nil
  341. local OHSwing = nil
  342. local rightSlash = nil
  343. local rightFast = nil
  344. local stabone = nil
  345. local stabtwo = nil
  346. local humanoid = nil
  347. local enabled = false
  348. local pcf;
  349. local pst;
  350. local pcf2;
  351. local pst2;
  352. local equipped = false
  353. local up = false
  354. local clicked = false
  355. local dtab = {};
  356. local pickevents = {};
  357. local pickmove;
  358. local speed;   
  359. local wt;
  360. local dpos;
  361. local spos;
  362.  
  363.  
  364.  
  365. -- Object Instancing
  366.  
  367. local VurnerabilityDamage = Instance.new('NumberValue',Char);
  368. VurnerabilityDamage.Name = 'VurnerabilityDamage';
  369. local stagger = Instance.new('NumberValue',Char)
  370. stagger.Name = 'Stagger';
  371. stagger.Value = false;
  372. local blocking = Instance.new('BoolValue',Char);
  373. blocking.Name = 'Blocking';
  374. blocking.Value = false;
  375. local swinging = Instance_new('BoolValue',Char);
  376. swinging.Name = 'Swinging';
  377. local emote = Instance.new('Sound',Torso);
  378. emote.Volume = 1;
  379. local unsheath = Instance_new('Sound',Torso)
  380. unsheath.Volume = 1;
  381. unsheath.Pitch = .8;
  382. unsheath.SoundId = 'http://roblox.com/asset?id=109362789';
  383. ContentProvider:preload(unsheath.SoundId)
  384. local shieldbash = Instance_new('Sound',Torso)
  385. shieldbash.Name = 'ShieldBash';
  386. shieldbash.SoundId = 'http://roblox.com/Asset?id=92597264';
  387. shieldbash.Pitch = .4;
  388. shieldbash.Volume = 1;
  389. ContentProvider:preload(shieldbash.SoundId);
  390. local impact = Instance_new('Sound',Torso)
  391. impact.Name = 'Impact';
  392. impact.Volume = .35;
  393. impact.Pitch = .8;
  394. local swoosh = Instance_new('Sound',Torso)
  395. swoosh.Volume = .5;
  396. swoosh.Pitch = 1;
  397. --http://roblox.com/asset?id=109362710
  398. swoosh.SoundId = 'http://roblox.com/asset?id=119888724';
  399. ContentProvider:preload(swoosh.SoundId)
  400. local shieldup = Instance_new('Sound',Torso);
  401. shieldup.Volume = 1;
  402. shieldup.Pitch = 1.1;
  403. shieldup.SoundId = 'http://roblox.com/asset?ID=92597296';
  404. ContentProvider:preload(shieldup.SoundId);
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415. --Animations
  416. local swooshdata = {
  417. [1] = 1,
  418. [2] = 1.5,
  419. [3] = .5,
  420. [4] = 1,
  421. [5] = 1.5,
  422. [6] = 2,
  423. [7] = 2
  424. }
  425. local swinganims = {
  426. [1] = {Human:LoadAnimation(Scripts.LeftSlash),0,5},
  427. [2] = {Human:LoadAnimation(Scripts.LeftSwingFast),0,5},
  428. [3] = {Human:LoadAnimation(Scripts.OverHeadSwing),20,30},
  429. [4] = {Human:LoadAnimation(Scripts.RightSlash),0,5},
  430. [5] = {Human:LoadAnimation(Scripts.RightSwingFast),0,5},
  431. [6] = {Human:LoadAnimation(Scripts.Stab1),0,3},
  432. [7] = {Human:LoadAnimation(Scripts.Stab2),0,3}
  433. }
  434. local parry = Human:LoadAnimation(Scripts.Block);
  435. local kickback = Human:LoadAnimation(Scripts.Kickback);
  436. local staggeranim = Human:LoadAnimation(Scripts.Stagger);
  437. local swingWithOut = Human:LoadAnimation(Scripts.twohandswordwithswingout);
  438. local equip = Human:LoadAnimation(Scripts.Equip);
  439. local ArrowAnim = Human:LoadAnimation(Scripts.ArrowAnim);  
  440. local OffHand = Scripts.OffHand;
  441.  
  442. local function ResumeControl()
  443.     for _,v in pairs(Controllers) do
  444.         print(v,' : ',type(v))
  445.         v.Parent = ControllerService;
  446.     end
  447. end
  448. local function HaltControl()
  449.     Controllers = {};
  450.     for _,v in pairs(ControllerService:GetChildren()) do
  451.         Controllers[#Controllers+1] = v;
  452.         v.Parent = nil
  453.     end
  454. end
  455. local function CreateFake(...)
  456.     local args = {...}
  457.     for _,p in pairs(args) do
  458.         local clone = p:Clone();
  459.         clone.Parent = Cam;
  460.         clone.Name = 'Fake'..p.Name;
  461.         clone.CFrame = p.CFrame;
  462.         local w = Instance.new('Weld',Cam);
  463.         w.Part0 = p;
  464.         w.Part1 = clone;
  465.     end
  466. end
  467. --CreateFake(RA,LA,Torso,RL,LL)
  468. wait(0)
  469. local function CanCollideAll(...)
  470.     local args = {...}
  471.     for _,v in pairs(args) do
  472.         v.CanCollide = true;
  473.     end
  474. end
  475. CanCollideAll(LA,RA,LL,RL);
  476. local function PreloadChildren(tab)
  477.     for _,v in pairs(tab) do
  478.         if type(v) == 'string' and v:sub(1,3) == 'htt' then
  479.             print('Preloading: '..v)ContentProvider:preload(v);
  480.         elseif type(v) == 'table' then
  481.             PreloadChildren(v)
  482.         end
  483.     end
  484. end
  485. print('Preloaded');
  486. PreloadChildren(Emotes);
  487. local function resetct()
  488.     for i,v in pairs(connectionstab) do
  489.         if v ~= nil then
  490.             v:disconnect();
  491.             v = nil
  492.         end
  493.     end
  494. end
  495. local function  checkdistance(obj)
  496.     if (Torso.Position - obj.Position).magnitude <= 7 then
  497.         return true
  498.         else
  499.         return false
  500.     end
  501. end
  502. local function  error(text, duration)
  503.     local precount = 0
  504.     ebutton.Visible = true
  505.     ebutton.Text = text
  506.     ebutton.TextTransparency = 0
  507.     wait(duration)
  508.     repeat
  509.         wait(.1)
  510.         ebutton.TextTransparency = ecount
  511.         ecount = ecount + 0.1
  512.         precount = ecount
  513.         if precount > ecount then
  514.             break
  515.         end
  516.     until   ecount >= 1
  517.     if ecount > 1 then
  518.         ecount = 1
  519.     end
  520.     ebutton.Visible = false
  521. end
  522. local function  tagHumanoid(humanoid, Player)
  523.     local tag = Instance_new("ObjectValue")
  524.     tag.Value = Player
  525.     tag.Name = "Source"
  526.     tag.Parent = humanoid
  527.     coroutine_resume(coroutine_create(function()
  528.         wait(3)
  529.         tag:Destroy()
  530.     end))
  531. end    
  532. local function  damagef(mon, Player, what,extra)
  533.     local block = game.Lighting.DamageDeal:clone()
  534.     local wep = Blade.Value.Damage;
  535.     local damage = math_random(wep.Value - 2, wep.Value + 2) + extra;
  536.     block.TextLabel.Text = tostring(damage) + Stats[what].Value
  537.     block.Parent = mon.Parent.Parent.Head
  538.     block.Adornee = mon.Parent.Parent.Head
  539.     mon.Health.Value = mon.Health.Value - (damage + Stats[what].Value)
  540.     debris:AddItem(block, .5)
  541. end
  542. local damagep = function(char,extra)
  543.     local head = char:FindFirstChild('Head');
  544.     local wep = Blade.Value.Damage;
  545.     local damage = math_random(wep.Value - 2, wep.Value + 2) + extra;
  546.     local DamageGui = DamageGUI:Clone();
  547.     local frame = DamageGui.Frame;
  548.     DamageGui.Parent = head;
  549.     DamageGui.Adornee = head;
  550.     frame.TextLabel.Text = '-'..tostring(damage);
  551.     debris:AddItem(DamageGui,2)
  552.     local damageval = Instance_new('NumberValue',DamageDeals);
  553.     damageval.Name = char.Name;
  554.     damageval.Value = damage;
  555. end
  556. local function  cframe(part, to, offset, on, nn)
  557.     local bad = part:findFirstChild(on)
  558.     if bad then
  559.         bad:Destroy()
  560.     end
  561.     local tw = Instance_new("Weld", part)
  562.     tw.Part0 = to
  563.     tw.Part1 = part
  564.     tw.Name = nn
  565.     if offset ~= nil then
  566.         tw.C0 = offset
  567.         coroutine_resume(coroutine_create(function()wait(2) tw.C0 = offset end))
  568.     end
  569. end
  570.    
  571. local function  checkintangible(hit)
  572.     if hit and hit~=nil then
  573.         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
  574.             return true
  575.         end
  576.     end
  577.     return false
  578. end
  579.    
  580.  
  581. local CombatMode = function()
  582.     InCombatMode = true
  583.     bg = Instance_new('BodyGyro',Torso);
  584.     bg.maxTorque = Vector3.new(0,400000,0);
  585.     bg.D = 200;
  586.     while InCombatMode do wait(.1);
  587.         bg.cframe = Targeting ~= nil and CFrame_new(Torso.Position,Targeting.Position)
  588.         or Cam.CoordinateFrame;
  589.         if Targeting then
  590.             Cam:Interpolate(CFrame_new(Head.Position + -(Head.CFrame.lookVector*20) + Vector3.new(0,8,0)),Targeting.CFrame,.2)
  591.         end
  592.     end
  593.     bg:Destroy();
  594. end
  595.    
  596. Sheathed = true
  597. local function Sheath()
  598.     if Sheathing or Sheathed then return end
  599.     Cam.CameraType = 'Custom'
  600.     Targeting = nil
  601.     blocking.Value = false;
  602.     Sheathing = true
  603.     InCombatMode = nil;
  604.     equipped = false
  605.     if sword then
  606.         if sword.Parent ~= nil then
  607.             if sword:findFirstChild("Blade") then
  608.                 if sword.Blade:FindFirstChild("Script") ~= nil then
  609.                     sword.Blade.Script.Disabled = true
  610.                 end
  611.                 Scripts.Bow.Value = false
  612.             end
  613.             cframe(sword.Handle, pst, pcf, "Post", "Pre")
  614.         end
  615.     end
  616.     if sword2 then
  617.         if sword2:FindFirstChild("Shield") then
  618.             cframe(sword2.Handle, pst2, pcf2, "Post", "Pre")
  619.         end
  620.     end
  621.     if swingWithOut then
  622.         for _,v in pairs(swinganims) do v = nil; end
  623.     end
  624.     Sheathed = true
  625.     wait(1)
  626.     Sheathing = nil;
  627. end
  628.  
  629.  
  630.             local SpawnSmoke = function(cf,col)
  631.                 local cf = cf * CFrame.new(0,-5,0)
  632.                 coroutine_resume(coroutine_create(function()
  633.                 local smokepart = Instance.new('Part',Workspace);
  634.                 smokepart.CFrame = cf;
  635.                 smokepart.Anchored,smokepart.CanCollide,smokepart.Transparency = true,false,1;
  636.                 local smoke = Instance.new('Smoke');
  637.                 smoke.Size = .2;
  638.                 smoke.Color = col.Color;
  639.                 smoke.Opacity = .5
  640.                 smoke.RiseVelocity = 50
  641.                 smoke.Parent = smokepart;
  642.                 wait(1)
  643.                 smoke.Enabled = false
  644.             end))
  645.         end
  646.        
  647.        
  648.        
  649. local function PartUnder(p)
  650.     local partray = Ray_new(p.Position,Vector3.new(0,-10,0))
  651.    local partunder,position = Workspace:FindPartOnRayWithIgnoreList(partray,{Char});
  652.     return partunder;    
  653. end
  654. local function knockback(am)
  655.     local partunder = PartUnder(RL);
  656.     local Underhit;
  657.     coroutine_resume(coroutine_create(function() Sheath() end))
  658.     kickback:Play()
  659.     Human.Sit = true  
  660.     Torso.Velocity = -(Torso.CFrame.lookVector * am);
  661.     local underhitcheck = Torso.Touched:connect(function(obj)
  662.         if obj == partunder or obj.Name:match('Terrain') then
  663.             Underhit = true
  664.         end
  665.     end)
  666.     repeat wait(0) until Underhit
  667.     print('Landed!');
  668.     for i = 1, 14 do
  669.         local partunder = PartUnder(RL);
  670.         SpawnSmoke(Torso.CFrame * CFrame.new(0,-2,0),partunder and partunder.BrickColor or BrickColor_new('Pastel brown'));
  671.         wait(.1);
  672.     end
  673.     kickback:Stop()
  674. end
  675. pcall(function() Head.face:Destroy(); end)
  676. pcall(function() Head.Parent:WaitForChild('FakeHead').face:Destroy(); end)
  677. local function SeverHead(veloc,headd)
  678.     local ch = headd.Parent;
  679.     local head;
  680.     if headd.Name == 'FakeHead' then head = headd print('Fake')
  681.     else
  682.        head = ch.FakeHead
  683.     end
  684.     head.Transparency = 0
  685.     local fakehead = head:clone();
  686.     fakehead.CanCollide = true
  687.     fakehead.Anchored = true
  688.     local velo = Instance.new('BodyVelocity',fakehead)
  689.     velo.maxForce = Vector3.new(400000,400000,400000)
  690.     velo.P = 16000.000;
  691.     fakehead.CFrame = head.CFrame;
  692.     fakehead.Parent = Workspace;
  693.     fakehead.Transparency = 0
  694.     wait(0)
  695.     head.Transparency = 1;
  696.     velo.velocity = veloc * 10;--fakehead.CFrame:vectorToWorldSpace(Vector3.new(-6,0,8));
  697.     fakehead.Anchored = false;
  698.     wait(.5)
  699.     velo:Destroy();
  700. end
  701. wait(2)
  702. --SeverHead(Head)
  703. local function FindSpeed()
  704.     for _,v in pairs(AttackSpeedRanges) do
  705.         local les,gre = _:match('<(.-)>(.+)');
  706.         les,gre = tonumber(les),tonumber(gre);
  707.         local val = fatigue.Value;
  708.         if val < les and val > gre then
  709.             return v
  710.         end
  711.     end
  712.     return 1;
  713. end
  714. local function  go(tab,targetpos,startpos,fadedelay)
  715.     if  enabled then return end
  716.     local HandSlot = Char.HandSlot.Weld;
  717.     cursor.Visible = false
  718.     cursor2.Visible = false
  719.     resetct()
  720.     if equipped == true then
  721.         enabled = false
  722.         wait()
  723.         if Bow.Value == false and Magic.Value == false then
  724.             local swingbacks = {};
  725.             local t;
  726.             local touched;
  727.             local handle,blade = sword.Handle,sword.Blade;
  728.             local torso = Torso;
  729.             local weld = torso:FindFirstChild('Right Shoulder');
  730.             local ra = weld.Part1;
  731.             local rn = tab[math_random(1,#tab)];
  732.             local currentanim =  swinganims[rn]
  733.             swoosh.Pitch = swooshdata[rn];
  734.             wait(0)
  735.             local anim = currentanim[1];
  736.             local extra = currentanim[2];
  737.             local cost = currentanim[3];
  738.             local calc = fatigue.Value - cost;
  739.             if calc > 0 then
  740.                 fatigue.Value = calc;
  741.                 local spd = FindSpeed();
  742.                 coroutine_resume(coroutine_create(function()
  743.                     TweenPart(HandSlot,HandSlot.C0,HandSlot.C0 * CFrame.Angles(-1.5,0,0),spd/2.5)
  744.                 end))
  745.                 anim:Play(0,1,spd);
  746.                 swoosh:Play();
  747.                 t = blade.Touched:connect(function(hit)
  748.                     --Shield Parry
  749.                     if touched or (hit.Name:find('Terrain')) or hit.Name:find('Part') or not hit.Parent then return end
  750.                     if hit.Parent.Name:find('Shield') then
  751.                         anim:Stop()
  752.                         touched = true;
  753.                         local shield = hit.Parent;
  754.                         shieldbash:Play();
  755.                         local possiblechar = Players:FindFirstChild(shield.Name:match("(.-)'s"));
  756.                         print(possiblechar)
  757.                         if possiblechar and possiblechar.Character.Swinging.Value == true then
  758.                             knockback(60);
  759.                             local health = Stats.Health;
  760.                             health.Value = health.Value - 5;
  761.                             else
  762.                             --code
  763.                         end
  764.                         return;
  765.                     end
  766.                    
  767.                     local ch;
  768.                     local par = hit.Parent;
  769.                     if Players:FindFirstChild(par.Name) then
  770.                         ch = par;
  771.                         elseif Players:FindFirstChild(par.Parent.Name) then
  772.                         ch = par.Parent;
  773.                     end
  774.                     impact.SoundId = hit.Name ~= 'Blade' and 'http://roblox.com/asset?id=96667969' or
  775.                     'http://roblox.com/asset?id=62339698';
  776.                     impact.Pitch = hit.Name ~= 'Blade' and .6 or .8;
  777.                     wait(0)
  778.                     impact:Play();
  779.                     touched = true;
  780.                     if ch then
  781.                         damagep(ch,(extra + ch.VurnerabilityDamage.Value));
  782.                     end
  783.                 end)
  784.                 wait(0);
  785.                 enabled = true
  786.                 local tim = (spd < 1 and 4 or 1.25)
  787.                 print(tim);
  788.                 wait(tim);
  789.                 t:disconnect();
  790.                 coroutine_resume(coroutine_create(function()
  791.                     TweenPart(HandSlot,HandSlot.C0,HandSlot.C0 * CFrame.Angles(1.5,0,0),.25)
  792.                 end))
  793.                 enabled = false
  794.                 --anim:Stop();
  795.                 --TweenPart(RS,RS.C0,DefaultRightShoulderC0,.1);
  796.             else
  797.                 enabled = true
  798.             end
  799.             end
  800.     end
  801.     end
  802.         local function mainhand()
  803.             if Blade.Value ~= nil then
  804.                 equipped = true
  805.                 sword = Blade.Value
  806.                 if sword.Handle then
  807.                     pcf = sword.Handle.Pre.C0
  808.                     pst = sword.Handle.Pre.Part0
  809.                     if sword:findFirstChild("Blade") then
  810.                         equip:Play()
  811.                         wait(.5)
  812.                         cframe(sword.Handle, Char.HandSlot, nil, "Pre", "Post")
  813.                         wait(1.5)
  814.                         if Blade:FindFirstChild("Script") ~= nil then
  815.                             Blade.Script.Disabled = false
  816.                         end
  817.                         Bow.Value = false
  818.                         else
  819.                         if Bow.Value == true then
  820.                             cframe(sword.Handle, Char.HandSlot2, nil, "Pre", "Post")
  821.                         end
  822.                     end
  823.                 end
  824.             end
  825.         end
  826.         local function offhand()
  827.             if OffHand.Value then
  828.                 sword2 = OffHand.Value
  829.                 sword2.Name = Player.Name.."'s "..sword2.Name;
  830.                 if sword2:FindFirstChild("Shield") then
  831.                     pcf2 = sword2.Handle.Pre.C0
  832.                     pst2 = sword2.Handle.Pre.Part0
  833.                     local offsetshield = CFrame_new(-.5,0,0) * CFrame_fromEulerAnglesXYZ(0,math_pi/2,math_pi/2)
  834.                     cframe(sword2.Handle, Char["Left Arm"], DefaultPostC0, "Pre", "Post")  
  835.                 end
  836.             end
  837.            
  838.         end
  839.            
  840.            
  841.    
  842.         local Dash = function(direction)
  843.             print('Dash')
  844.             local lv = direction == 'back' and -Torso.CFrame.lookVector or Torso.CFrame.lookVector;
  845.             local partunder = PartUnder(RL);
  846.             local jumpamount = Torso.Velocity.magnitude > 5 and 150 or 100;
  847.             SpawnSmoke(RL.CFrame * CFrame.new(0,-1,0),partunder and partunder.BrickColor or                      BrickColor_new('White'));
  848.             local bv = Instance_new('BodyVelocity',Torso);
  849.             bv.maxForce = MaxVelocity;
  850.             bv.P = MaxPower;
  851.             bv.velocity = lv * jumpamount wait(.1) bv.P = 0;
  852.             bv:Destroy();
  853.         end
  854.         local function Unsheath()
  855.             if Unsheathing or not Sheathed then return end
  856.             blocking.Value = true;
  857.             Unsheathing = true;
  858.             coroutine_resume(coroutine_create(function()
  859.                 wait(.7)
  860.                 unsheath:Play();
  861.             end))
  862.             coroutine_resume(coroutine_create(CombatMode));
  863.             coroutine_resume(coroutine_create(mainhand))
  864.             TweenPart(RS,RS.C0,DefaultRightShoulderC0,.25)
  865.             coroutine_resume(coroutine_create(offhand))
  866.             startarmcf = Char:FindFirstChild('Right Arm').CFrame
  867.             Sheathed = nil
  868.             wait(1)
  869.             Unsheathing = nil;
  870.         end
  871.            
  872.            
  873.            
  874.         equipped = false;
  875.            
  876.         local function EmoteSelect()
  877.             print('EmoteSelect')
  878.             EmoteFrame.Visible = not EmoteFrame.Visible;
  879.             wait(0)
  880.             if EmoteFrame.Visible == true then
  881.                 ChoosingEmote = true;
  882.                 EmoteChoose = mouse.KeyDown:connect(function(key)
  883.                     if EmoteBinds[key] and not voice then
  884.                         voice = true
  885.                         local CurrentEmote = EmoteBinds[key];
  886.                         local label = EmoteFrame[CurrentEmote];
  887.                         label.BackgroundTransparency = .7
  888.                         local EmotesData = Emotes[CurrentEmote];
  889.                         local RandomEmoteTable = EmotesData[math_random(1,#EmotesData)];
  890.                         emote.SoundId = RandomEmoteTable[1];
  891.                         emote.Pitch = RandomEmoteTable[2];
  892.                         wait(0)
  893.                         emote:play();
  894.                         wait(.1)
  895.                         label.BackgroundTransparency = .9
  896.                         EmoteSelect();
  897.                         wait(1.9)
  898.                         voice = nil
  899.                     end
  900.                 end)
  901.             else
  902.                 ChoosingEmote = nil;
  903.                 EmoteChoose:disconnect();
  904.             end
  905.         end
  906.         local function LowerShield()
  907.             TweenPart(LS,LS.C0,DefaultShoulderC0,.1);
  908.         end
  909.         local function RaiseShield()
  910.             LS.DesiredAngle = 0;
  911.             LS.MaxVelocity = 1;
  912.             shieldup:Play();
  913.             TweenPart(LS,LS.C0,ShieldBlockC0,.25);
  914.             swinging.Value = true
  915.             coroutine_resume(coroutine_create(function()
  916.             wait(2)
  917.             swinging.Value = false
  918.             end))
  919.         end
  920.         local function DownSlash()
  921.             TweenPart(RS,RS.C0,DS1,1);
  922.             TweenPart(RS,RS.C0,DS2,.5);
  923.         end
  924.         local function ShieldBash()
  925.             RaiseShield()
  926.             if OffHand.Value == nil then return end
  927.             bashing = true;
  928.             local shieldc = LS.C0;
  929.             local bash;
  930.             local notcontinue;
  931.             local touched;
  932.             local shield = OffHand.Value.Handle;
  933.             local i = 0;
  934.             while bashing and i < 6 do wait(0)
  935.                 i = i + 1;
  936.                 LS.C0 = LS.C0 * CFrame.new(0,0,-.06)
  937.             end
  938.             bash = shield.Touched:connect(function(hit)
  939.             if touched or (hit.Name:find('Terrain')) or hit.Name:find('Part') or not hit.Parent then return end
  940.                     if hit.Parent.Name:find('Shield') then
  941.                         touched = true;
  942.                         local shield = hit.Parent;
  943.                         shieldbash:Play();
  944.                         return;
  945.                     end
  946.                     local ch;
  947.                     local par = hit.Parent;
  948.                     if Players:FindFirstChild(par.Name) then
  949.                         ch = par;
  950.                         elseif Players:FindFirstChild(par.Parent.Name) then
  951.                         ch = par.Parent;
  952.                     end
  953.                     shieldbash:Play();
  954.                     touched = true;
  955.                     if ch and ch:FindFirstChild('Stagger') then
  956.                         local stag = ch:FindFirstChild('Stagger');
  957.                         stag.Value = (Torso.Velocity.magnitude/2.5)*3;
  958.                     end
  959.             end)
  960.             local i = 0;
  961.                 while bashing and i < 5 do wait(0)
  962.                     i = i + 1;
  963.                     LS.C0 = LS.C0 * CFrame.new(0,0,.3)
  964.                 end
  965.             i = 0;
  966.                 while bashing and i < 5  do wait(0)
  967.                     i = i + 1;
  968.                     LS.C0 = LS.C0 * CFrame.new(0,0,-.3)
  969.                 end
  970.             wait((bashing and .5 or 0));
  971.             if bash then
  972.                 bash:disconnect()
  973.             end
  974.             LS.C0 = shieldc;
  975.             LowerShield();
  976.         end
  977.        
  978.         local function CycleTargets()
  979.             cycling = {};
  980.             for _,v in pairs(Players:GetPlayers()) do
  981.                 if v ~= Player and Workspace:FindFirstChild(v.Name) then
  982.                     local char = Workspace:FindFirstChild(v.Name)
  983.                     local tors = char.Torso
  984.                     if (tors.Position-Torso.Position).Magnitude < 20 and
  985.                         tors ~= lastcycled then
  986.                         cycling[#cycling+1] = tors;
  987.                     end
  988.                 end
  989.             end
  990.             if #cycling >0 then print('Found torso')
  991.                 local rt = cycling[math_random(1,#cycling)];
  992.                 print(rt)
  993.                 lastcycled = rt;
  994.                 Cam.CameraType = 'Scriptable'
  995.                 Targeting = rt;
  996.             else
  997.                 Cam.CameraType = 'Custom'
  998.                 Targeting = nil
  999.                 lastcycled = nil;
  1000.             end
  1001.         end
  1002.         local function Control(...)
  1003.             local params = {...};
  1004.             local name = params[1];
  1005.             if name == 'wander' then print('Wandering');
  1006.                 knockback(30)
  1007.                 for i = 1, 4 do
  1008.                     local wanderpart = Instance_new('Part');
  1009.                     wanderpart.CFrame = Torso.CFrame * CFrame.new(math_random(6,8),0,math_random(6,8));
  1010.                     Human:MoveTo(wanderpart.Position,wanderpart);
  1011.                     wait(3)
  1012.                 end
  1013.                 elseif name == 'knockback' then
  1014.                 knockback(50);
  1015.             end
  1016.             wait(3)
  1017.             KeysLocked = false;    
  1018.         end
  1019.         local StaggerAnimation = function()
  1020.             Staggering = true
  1021.             coroutine_resume(coroutine_create(function()
  1022.                 staggeranim:Play();
  1023.                 wait(.5)
  1024.                 staggeranim:Stop();
  1025.                 while Staggering do
  1026.                     TweenPart(neck,neck.C0,DefaultNeckC0 * CFrame.Angles(math_random(2,12)/10,0,0),1)
  1027.                     wait(0)
  1028.                 end
  1029.             end))
  1030.         end
  1031.         local charging = nil
  1032.         local ControlListener = ControlListeners.ChildAdded:connect(function(obj)
  1033.             local vec = obj.Value*Vector3.new();
  1034.             local magn = (Torso.Position-vec).Magnitude;
  1035.             print(vec,magn)
  1036.             local name,msg = obj.Name:match('(.-)/(.+)');
  1037.             if magn < 20 then
  1038.                 KeysLocked = msg;
  1039.                 Sheath();
  1040.                 Control(name)
  1041.             end
  1042.         end)
  1043.         local DamageListener = DamageDeals.ChildAdded:connect(function(obj)
  1044.             if Damaged then return end
  1045.             Damaged = true
  1046.             print(obj)
  1047.             if not obj.Name == Player.Name then return end
  1048.             local health = Stats.Health;
  1049.             health.Value = health.Value - obj.Value;
  1050.             if health.Value <= 0 then KeysLocked = 'Dead' knockback(10)
  1051.                 if Player.Name == Head1.Value.Parent.Name then
  1052.                     Won.Value = Head2 and Head2.Value.Parent.Name or '';
  1053.                     elseif Player.Name == Head2.Value.Parent.Name then
  1054.                     Won.Value = Head1 and Head1.Value.Parent.Name or '';
  1055.                 end
  1056.                 InBattle.Value = false;
  1057.                 script:Destroy();
  1058.             end
  1059.             wait(1)
  1060.             Damaged = nil;
  1061.         end)
  1062.         local StaggerListener = stagger.Changed:connect(function()
  1063.             if not InCombatMode or StaggerFiring then return end
  1064.             HaltControl();
  1065.             VurnerabilityDamage.Value = 5;
  1066.             StaggerFiring = true
  1067.             KeysLocked = 'Staggered'
  1068.             print('STAGGERING')
  1069.             StaggerAnimation()
  1070.             local walkback = Instance.new('Part',Workspace);
  1071.             walkback.Transparency,walkback.CanCollide = 1,false;
  1072.             walkback.CFrame = CFrame_new(Torso.Position + -Torso.CFrame.lookVector * stagger.Value)
  1073.             Human:MoveTo(walkback.Position,walkback);
  1074.             wait(8)
  1075.             Staggering = false
  1076.             TweenPart(neck,neck.C0,DefaultNeckC0,.25)
  1077.             KeysLocked = nil
  1078.             StaggerFiring = false
  1079.             ResumeControl()
  1080.             VurnerabilityDamage.Value = 10;
  1081.         end)
  1082.         local AntiJump = Human.Changed:connect(function()
  1083.             if InCombatMode then
  1084.                 Human.Jump = false;
  1085.             end
  1086.         end)
  1087.         local MouseListeners = {
  1088.         ['WheelForward'] = function() if not InCombatMode  then return end go({6,7},mouse.hit.p, Head.Position, .25) end,
  1089.         ['WheelBackward'] = function() if not InCombatMode  then return end DownSlash(); end,
  1090.         ['KeyDown'] = function(key)
  1091.             if KeysLocked then error(KeysLocked,.5);  return elseif ChoosingEmote then return end
  1092.                 local doubleclickbool = false;
  1093.                 if KEY_CLICK_DATA[key] then
  1094.                 KEY_CLICK_DATA[key] = KEY_CLICK_DATA[key] + 1;
  1095.                 coroutine_resume(coroutine_create(function() wait(.25) KEY_CLICK_DATA[key] = 0; end))
  1096.                 if KEY_CLICK_DATA[key] < 2 then doubleclickbool = false; else doubleclickbool = true end
  1097.                 end
  1098.             print(doubleclickbool)
  1099.             local calc = fatigue.Value;
  1100.             if key == "e" then
  1101.                 if equipped == false and Blade.Value then
  1102.                     Unsheath();
  1103.                     elseif equipped == true then
  1104.                     Sheath();
  1105.                 end
  1106.             elseif key == 's' and doubleclickbool == true and calc >= 5 then
  1107.                 fatigue.Value = fatigue.Value - 5;
  1108.                 coroutine_resume(coroutine_create(function()Dash('back')end));
  1109.             elseif key == 'w' and doubleclickbool == true and calc >= 5 then
  1110.                 fatigue.Value = fatigue.Value - 5;
  1111.                 coroutine_resume(coroutine_create(function()Dash('forward')end));
  1112.             elseif key == 'z' then
  1113.                 EmoteSelect();
  1114.             elseif key == 'f' and calc >= 30 then
  1115.                 fatigue.Value = fatigue.Value - 30;
  1116.                 ShieldBash()
  1117.             elseif key == 't' then
  1118.                 CycleTargets()
  1119.             end
  1120.             keyDeb = 0
  1121.         end,
  1122.         ['Button2Down'] = function() print('Firing')
  1123.             if KeysLocked then error(KeysLocked,.5);  return end
  1124.             if not InCombatMode  then return end print('Playing')
  1125.             local calc = fatigue.Value;
  1126.             if OffHand.Value and  calc >= 2 and OffHand.Value.Name:match('Shield') then
  1127.                 fatigue.Value = fatigue.Value - 2;
  1128.                 RaiseShield();
  1129.                 coroutine_resume(coroutine_create(function()wait(5)LowerShield()end))
  1130.             end
  1131.         end,
  1132.         ['Button2Up'] = function() print('Firing')
  1133.             if not InCombatMode then  return end print('Playing')
  1134.             if OffHand.Value and OffHand.Value.Name:match('Shield')  then
  1135.                 LowerShield();
  1136.             end
  1137.         end,
  1138.         ['Button1Down'] = function()
  1139.             if KeysLocked then error(KeysLocked,.5);  return end
  1140.             if not InCombatMode  then return end
  1141.                 go({1,2,4,5},mouse.hit.p,Head.Position,.25)
  1142.             end
  1143.         }
  1144.         for _,v in pairs(MouseListeners) do
  1145.             mouse[_]:connect(v);
  1146.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement