Advertisement
RiasGremory0100

Untitled

Mar 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. local function WaitForChild(parent, childName)
  2. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  3. return parent[childName]
  4. end
  5.  
  6.  
  7. local SLASH_DAMAGE = 1000000000000000
  8. local DOWNSTAB_DAMAGE = 1000000000000000
  9. local THROWING_DAMAGE = 1000000000000000
  10. local HOLD_TO_THROW_TIME = 0
  11.  
  12.  
  13. local Damage = 1000000000000000
  14.  
  15. local MyHumanoid = nil
  16. local MyTorso = nil
  17. local MyCharacter = nil
  18. local MyPlayer = nil
  19.  
  20. local Tool = script.Parent
  21. local Handle = WaitForChild(Tool, 'Handle')
  22.  
  23. local BlowConnection
  24. local Button1DownConnection
  25. local Button1UpConnection
  26.  
  27. local PlayStabPunch
  28. local PlayDownStab
  29. local PlayThrow
  30. local PlayThrowCharge
  31.  
  32. local IconUrl = Tool.TextureId -- URL to the weapon knife icon asset
  33.  
  34. local DebrisService = game:GetService('Debris')
  35. local PlayersService = game:GetService('Players')
  36.  
  37. local SlashSound
  38.  
  39. local HitPlayers = {}
  40.  
  41. local LeftButtonDownTime = nil
  42.  
  43. local Attacking = false
  44.  
  45. function Blow(hit)
  46. if Attacking then
  47. BlowDamage(hit, Damage)
  48. end
  49. end
  50.  
  51. function BlowDamage(hit, damage)
  52. local humanoid = hit.Parent:FindFirstChild('Humanoid')
  53. local player = PlayersService:GetPlayerFromCharacter(hit.Parent)
  54. if humanoid ~= nil and MyHumanoid ~= nil and humanoid ~= MyHumanoid then
  55. if not MyPlayer.Neutral then
  56. -- Ignore teammates hit
  57. if player and player ~= MyPlayer and player.TeamColor == MyPlayer.TeamColor then
  58. return
  59. end
  60. end
  61. -- final check, make sure weapon is in-hand
  62. local rightArm = MyCharacter:FindFirstChild('Right Arm')
  63. if (rightArm ~= nil) then
  64. -- Check if the weld exists between the hand and the weapon
  65. local joint = rightArm:FindFirstChild('RightGrip')
  66. if (joint ~= nil and (joint.Part0 == Handle or joint.Part1 == Handle)) then
  67. -- Make sure you only hit them once per swing
  68. TagHumanoid(humanoid, MyPlayer)
  69. print("Sending " .. damage)
  70.  
  71. local checksound = humanoid.Parent:findFirstChild("Sound")
  72. if checksound == nil then
  73. local givesound = script.Parent.Sound:clone()
  74. givesound.Parent = humanoid.Parent
  75. givesound.Disabled = false
  76. else
  77. checksound:remove()
  78. local givesound = script.Parent.Sound:clone()
  79. givesound.Parent = humanoid.Parent
  80. givesound.Disabled = false
  81. end
  82. wait()
  83. humanoid:TakeDamage(humanoid.MaxHealth)
  84. if humanoid.Health == math.huge or humanoid.MaxHealth == math.huge then
  85. humanoid.Parent:BreakJoints()
  86. end
  87. end
  88. end
  89. end
  90. end
  91.  
  92. function TagHumanoid(humanoid, player)
  93. -- Add more tags here to customize what tags are available.
  94. while humanoid:FindFirstChild('creator') do
  95. humanoid:FindFirstChild('creator'):Destroy()
  96. end
  97.  
  98. local creatorTag = Instance.new('ObjectValue')
  99. creatorTag.Value = player
  100. creatorTag.Name = 'creator'
  101. creatorTag.Parent = humanoid
  102. DebrisService:AddItem(creatorTag, 1.5)
  103.  
  104. local weaponIconTag = Instance.new('StringValue')
  105. weaponIconTag.Value = IconUrl
  106. weaponIconTag.Name = 'icon'
  107. weaponIconTag.Parent = creatorTag
  108. DebrisService:AddItem(weaponIconTag, 1.5)
  109. end
  110.  
  111. function HardAttack()
  112. Damage = SLASH_DAMAGE
  113. HitSound:play()
  114. if PlayStabPunch then
  115. PlayStabPunch.Value = true
  116. wait(1.0)
  117. PlayStabPunch.Value = false
  118. end
  119. end
  120.  
  121. function NormalAttack()
  122. Damage = DOWNSTAB_DAMAGE
  123. KnifeDown()
  124. HitSound:play()
  125. if PlayDownStab then
  126. PlayDownStab.Value = true
  127. wait(1.0)
  128. PlayDownStab.Value = false
  129. end
  130. KnifeUp()
  131. end
  132.  
  133. function ThrowAttack()
  134. KnifeOut()
  135. if PlayThrow then
  136. PlayThrow.Value = true
  137. wait()
  138. if not Handle then return end
  139. local throwingHandle = Handle:Clone()
  140. DebrisService:AddItem(throwingHandle, 5)
  141. throwingHandle.Parent = game.Workspace
  142. if MyCharacter and MyHumanoid then
  143. throwingHandle.Velocity = (MyHumanoid.TargetPoint - throwingHandle.CFrame.p).unit * 100
  144. -- set the orientation to the direction it is being thrown in
  145. throwingHandle.CFrame = CFrame.new(throwingHandle.CFrame.p, throwingHandle.CFrame.p + throwingHandle.Velocity) * CFrame.Angles(0, 0, math.rad(-90))
  146. local floatingForce = Instance.new('BodyForce', throwingHandle)
  147. floatingForce.force = Vector3.new(0, 196.2 * throwingHandle:GetMass() * 0.98, 0)
  148. local spin = Instance.new('BodyAngularVelocity', throwingHandle)
  149. spin.angularvelocity = throwingHandle.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0))
  150. end
  151. Handle.Transparency = 1
  152. -- Wait so that the knife has left the thrower's general area
  153. wait()
  154. if throwingHandle then
  155. local Throwevent = script.Parent.ThrowHandleHitWeld:Clone()
  156. Throwevent.Parent = throwingHandle
  157. Throwevent.Disabled = false
  158. local touchedConn = throwingHandle.Touched:connect(function(hit) print("hit throw") BlowDamage(hit, THROWING_DAMAGE) end)
  159. end
  160. -- must check if it still exists since we waited
  161. if throwingHandle then
  162. throwingHandle.CanCollide = true
  163. end
  164. wait(0.6)
  165. if Handle and PlayThrow then
  166. Handle.Transparency = 0
  167. PlayThrow.Value = false
  168. end
  169. end
  170. KnifeUp()
  171. end
  172.  
  173. function KnifeUp()
  174. Tool.GripForward = Vector3.new(0,0,-1)
  175. Tool.GripRight = Vector3.new(1,0,0)
  176. Tool.GripUp = Vector3.new(0,1,0)
  177. end
  178.  
  179. function KnifeDown()
  180. Tool.GripForward = Vector3.new(0,0,-1)
  181. Tool.GripRight = Vector3.new(1,0,0)
  182. Tool.GripUp = Vector3.new(0,-1,0)
  183. end
  184.  
  185. function KnifeOut()
  186. Tool.GripForward = Vector3.new(0,0,-1)
  187. Tool.GripRight = Vector3.new(1,0,0)
  188. Tool.GripUp = Vector3.new(0,1,0)
  189. end
  190.  
  191. Tool.Enabled = true
  192.  
  193. function OnLeftButtonDown()
  194. LeftButtonDownTime = time()
  195. if PlayThrowCharge then
  196. PlayThrowCharge.Value = true
  197. end
  198. end
  199.  
  200. function OnLeftButtonUp()
  201. if not Tool.Enabled then return end
  202. -- Reset the list of hit players every time we start a new attack
  203. HitPlayers = {}
  204. if PlayThrowCharge then
  205. PlayThrowCharge.Value = false
  206. end
  207. if Tool.Enabled and MyHumanoid and MyHumanoid.Health > 0 then
  208. Tool.Enabled = false
  209. local currTime = time()
  210. if LeftButtonDownTime and currTime - LeftButtonDownTime > HOLD_TO_THROW_TIME and
  211. currTime - LeftButtonDownTime < 1.15 then
  212. ThrowAttack()
  213. else
  214. Attacking = true
  215. if math.random(1, 2) == 1 then
  216. HardAttack()
  217. else
  218. NormalAttack()
  219. end
  220. Attacking = false
  221. end
  222. Tool.Enabled = true
  223. end
  224. end
  225.  
  226. function OnEquipped(mouse)
  227. PlayStabPunch = WaitForChild(Tool, 'PlayStabPunch')
  228. PlayDownStab = WaitForChild(Tool, 'PlayDownStab')
  229. PlayThrow = WaitForChild(Tool, 'PlayThrow')
  230. PlayThrowCharge = WaitForChild(Tool, 'PlayThrowCharge')
  231. SlashSound = WaitForChild(Handle, 'Swoosh1')
  232. HitSound = WaitForChild(Handle, 'Ting')
  233. SlashSound:play()
  234. BlowConnection = Handle.Touched:connect(Blow)
  235. MyCharacter = Tool.Parent
  236. MyTorso = MyCharacter:FindFirstChild('Torso')
  237. MyHumanoid = MyCharacter:FindFirstChild('Humanoid')
  238. MyPlayer = PlayersService.LocalPlayer
  239. if mouse then
  240. Button1DownConnection = mouse.Button1Down:connect(OnLeftButtonDown)
  241. Button1UpConnection = mouse.Button1Up:connect(OnLeftButtonUp)
  242. end
  243. KnifeUp()
  244. end
  245.  
  246. function OnUnequipped()
  247. -- Unequip logic here
  248. if BlowConnection then
  249. BlowConnection:disconnect()
  250. BlowConnection = nil
  251. end
  252. if Button1DownConnection then
  253. Button1DownConnection:disconnect()
  254. Button1DownConnection = nil
  255. end
  256. if Button1UpConnection then
  257. Button1UpConnection:disconnect()
  258. Button1UpConnection = nil
  259. end
  260. MyHumanoid = nil
  261. end
  262.  
  263.  
  264. Tool.Equipped:connect(OnEquipped)
  265. Tool.Unequipped:connect(OnUnequipped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement