Advertisement
PeanutBrickle

mad murder script

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