Advertisement
StefanBashkir

LinkedSword Rewrite

Dec 21st, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.35 KB | None | 0 0
  1. --LocalScript instance
  2.  
  3. if not script:IsA([==[LocalScript]==]) then
  4.     getfenv()['error']([==[SwordScript must be a LocalScript]==]);
  5. end
  6.  
  7. -- Crazy hacky weird stuff: So, sometimes the 'creator' instance doesn't appear as a child of the Humanoid. But when printing its parent (line 109)
  8. -- it is a child of the attacked Humanoid. So I don't know if it's an explorer glitch or what, but it is parented there when it is supposed to be.
  9.  
  10. local tool = script['Parent'];
  11. local player = Game['Players']['LocalPlayer'];
  12. local runservice = Game:GetService([==[RunService]==]);
  13. local sword = tool:WaitForChild("Handle"); -- it's amazing how many errors can be solved by waiting for children that _should_ be there
  14. local enabled = not false;
  15. local isAttacking = false; -- used as a 'debounce'
  16. local last_attack = 0;
  17. local deal_damage = 0; -- do not edit this variable. edit the values in 'damages' to change sword damage
  18. local OriginalSwordStates = {
  19.     ['GripUp'] = Vector3['new'](0,0,1);
  20.     ['GripRight'] = Vector3['new'](0,1,0);
  21.     ['GripForward'] = Vector3['new'](-1,0,0);
  22. }
  23. local damages = {
  24.     ['slash'] = 10;
  25.     ['lunge'] = 30;
  26. }
  27. local GetSound = {
  28.     ['slash'] = function()
  29.         local _s = Instance['new']([==[Sound]==], sword) ;
  30.         _s['SoundId'] = [==[rbxasset://sounds\\swordslash.wav]==];
  31.         _s['Volume'] = .7;
  32.         return _s;
  33.     end;
  34.     ['lunge'] = function()
  35.         local _s = Instance['new']([==[Sound]==], sword) ;
  36.         _s['SoundId'] = [==[rbxasset://sounds\\swordlunge.wav]==];
  37.         _s['Volume'] = .6;
  38.         return _s;
  39.     end;
  40.     ['unsheath'] = function()
  41.         local _s = Instance['new']([==[Sound]==], sword) ;
  42.         _s['SoundId'] = [==[rbxasset://sounds\\unsheath.wav]==];
  43.         _s['Volume'] = .6;
  44.         return _s;
  45.     end;
  46. }
  47.  
  48. getfenv()['PlayAnimation'] = function(value)
  49.     local sv = Instance['new']([==[StringValue]==]);
  50.     sv['Value'] = value;
  51.     sv['Name'] = [==[toolanim]==];
  52.     sv['Parent'] = tool;
  53. end
  54.  
  55. getfenv()['FloatCharacter'] = function()
  56.     coroutine['wrap'](
  57.         function()
  58.             local f = Instance['new']([==[BodyVelocity]==]);
  59.             local mass = GetMassOfEverything()
  60.             f['velocity'] = Vector3.new(0,(mass * 196.2) + 700, 0)
  61.             f['maxForce'] = Vector3.new(0,(mass * 196.2) + 700,0);
  62.             f['Parent'] = player['Character']['Torso']; -- avoid using Tool.Parent to stop unequipping issues]]
  63.             --player['Character']['Humanoid']['Jump'] = not false;
  64.             wait(.5);
  65.             f:Destroy();
  66.         end
  67.     )()
  68. end
  69.  
  70. getfenv()['Attack'] = function(action)
  71.     if (action == [==[Slash]==]) then
  72.         GetSound['slash']():Play();
  73.         PlayAnimation(action);
  74.         deal_damage = damages['slash'];
  75.     else -- lunge
  76.         GetSound['lunge']():Play();
  77.         PlayAnimation(action);
  78.         SwordOut();
  79.         deal_damage = damages['lunge'];
  80.         FloatCharacter();
  81.         wait(.5);
  82.         SwordUp();
  83.         deal_damage = 0;
  84.     end
  85. end
  86.  
  87. getfenv()['SwordUp'] = function()
  88.     for i,v in pairs(OriginalSwordStates) do
  89.         tool[i] = v;
  90.     end
  91. end
  92.  
  93. getfenv()['SwordOut'] = function()
  94.     tool['GripForward'] = Vector3['new'](0,0,1e0);
  95.     tool['GripRight'] = Vector3.new(0,-1e0,0);
  96.     tool['GripUp'] = Vector3['new'](-1e0,0,0);
  97. end
  98.  
  99.  
  100. getfenv()['TagHumanoid'] = function(humanoid)
  101.     coroutine['wrap']( -- create a coroutine so to not halt any threads (through Touched creates a new thread each time it fires)
  102.         -- however, this makes sure the sword script also doesn't break due to any problems with the parent of the humanoid or creator value
  103.         function()
  104.             if humanoid and humanoid:IsA([==[Humanoid]==]) then
  105.                 local humanoid = humanoid;
  106.                 local v = Instance['new']([==[ObjectValue]==]);
  107.                 v['Name'] = [==[creator]==];
  108.                 v['Value'] = player;
  109.                 v['Parent'] = humanoid;
  110.                 --print("Tagged with parent:", v.Parent);
  111.                 wait(2);
  112.                 v:Destroy();
  113.             end
  114.         end
  115.     )()
  116. end
  117.  
  118. getfenv()['GetMassOfEverything'] = function()
  119.     local allBaseParts = {};
  120.     local mass = 0;
  121.     local function Get(parent)
  122.         for i,v in pairs(parent:GetChildren()) do
  123.             if #v:GetChildren() > 0 then
  124.                 Get(v);
  125.             end
  126.             if (v:IsA([==[BasePart]==])) then
  127.                 table['insert'](allBaseParts, v);
  128.             end
  129.         end
  130.     end
  131.     Get(player['Character']);
  132.     for index, part in pairs(allBaseParts) do
  133.         mass = mass + part:GetMass();
  134.     end
  135.     return mass;
  136. end
  137.  
  138. tool['Equipped']:connect(
  139.     function(mouse)
  140.         GetSound['unsheath']():Play();
  141.         mouse['Icon'] = [==[rbxasset://textures\\GunCursor.png]==];
  142.         mouse['Button1Down']:connect(
  143.             function()
  144.                 if enabled then
  145.                     enabled = false;
  146.                     mouse['Icon'] = [==[rbxasset://textures\\GunCursor.png]==];
  147.                     wait(1e0-.5);
  148.                     mouse['Icon'] = [==[rbxasset://textures\\GunCursor.png]==];
  149.                     enabled = true;
  150.                 end
  151.             end
  152.         )
  153.     end
  154. )
  155.  
  156. tool['Activated']:connect(
  157.     function()
  158.         if isAttacking then return end
  159.         local hittime = runservice['Stepped']:wait()
  160.         isAttacking = true;
  161.         if (hittime-last_attack < 1e0-.8) then
  162.             -- lunge
  163.             Attack([==[Lunge]==]);
  164.         else
  165.             -- slash
  166.             Attack([==[Slash]==]);
  167.         end
  168.         last_attack = hittime;
  169.         isAttacking = false;
  170.         wait(.5)
  171.         deal_damage = 0;
  172.     end
  173. )
  174.  
  175. tool['Unequipped']:connect(
  176.     function()
  177.         deal_damage = 0;
  178.         isAttacking = false;
  179.     end
  180. )
  181.  
  182. sword['Touched']:connect(
  183.     function(hit)
  184.         if (hit['Parent']) then
  185.             local humanoid = hit['Parent']:FindFirstChild([==[Humanoid]==]);
  186.             if humanoid then
  187.                 if (humanoid['Health'] > 0) then
  188.                     TagHumanoid(humanoid); -- this function will create a new thread and remove the tag after two seconds
  189.                     humanoid:TakeDamage(deal_damage);
  190.                 end
  191.             end
  192.         end
  193.     end
  194. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement