Advertisement
Guest User

Untitled

a guest
Oct 13th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. local Dir, Dir2, dot, sp, ent, trace, seed, hm
  2. local trace_normal = bit.bor(CONTENTS_SOLID, CONTENTS_OPAQUE, CONTENTS_MOVEABLE, CONTENTS_DEBRIS, CONTENTS_MONSTER, CONTENTS_HITBOX, 402653442, CONTENTS_WATER)
  3. local trace_walls = bit.bor(CONTENTS_TESTFOGVOLUME, CONTENTS_EMPTY, CONTENTS_MONSTER, CONTENTS_HITBOX)
  4. local NoPenetration = {[MAT_SLOSH] = true}
  5. local NoRicochet = {[MAT_FLESH] = true, [MAT_ANTLION] = true, [MAT_BLOODYFLESH] = true, [MAT_DIRT] = true, [MAT_SAND] = true, [MAT_GLASS] = true, [MAT_ALIENFLESH] = true}
  6. local PenMod = {[MAT_SAND] = 0.5, [MAT_DIRT] = 0.8, [MAT_METAL] = 1.1, [MAT_TILE] = 0.9, [MAT_WOOD] = 1.2}
  7. local bul, tr = {}, {}
  8. local SP = game.SinglePlayer()
  9.  
  10. local reg = debug.getregistry()
  11. local GetShootPos = reg.Player.GetShootPos
  12. local GetCurrentCommand = reg.Player.GetCurrentCommand
  13. local CommandNumber = reg.CUserCmd.CommandNumber
  14.  
  15. function SWEP:FireBullet()
  16. if CLIENT then
  17. hm = GetConVarNumber("fas2_hitmarker")
  18. else
  19. if SP then
  20. hm = tonumber(self.Owner:GetInfo("fas2_hitmarker"))
  21. end
  22. end
  23.  
  24. sp = GetShootPos(self.Owner)
  25. math.randomseed(CommandNumber(GetCurrentCommand(self.Owner)))
  26.  
  27. Dir = (self.Owner:EyeAngles() + self.Owner:GetPunchAngle() + Angle(math.Rand(-self.CurCone, self.CurCone), math.Rand(-self.CurCone, self.CurCone), 0) * 25):Forward()
  28.  
  29. for i = 1, self.Shots do
  30. Dir2 = Dir
  31.  
  32. if self.ClumpSpread and self.ClumpSpread > 0 then
  33. Dir2 = Dir + Vector(math.Rand(-1, 1), math.Rand(-1, 1), math.Rand(-1, 1)) * self.ClumpSpread
  34.  
  35. --Dir2 = Dir + VectorRand() * self.ClumpSpread
  36. end
  37.  
  38. bul.Num = 1
  39. bul.Src = sp
  40. bul.Dir = Dir2
  41. bul.Spread = Vector(0, 0, 0)
  42. bul.Tracer = 4
  43. bul.Force = self.Damage
  44. bul.Damage = math.Round(self.Damage)
  45. bul.Callback = function(a, b, c)
  46. if SERVER and SP and hm > 0 then
  47. ent = b.Entity
  48.  
  49. if ent:IsNPC() or ent:IsPlayer() then
  50. SendUserMessage("FAS2_HITMARKER", self.Owner)
  51. end
  52. end
  53.  
  54. if CLIENT and hm > 0 then
  55. ent = b.Entity
  56.  
  57. if ent:IsNPC() or ent:IsPlayer() then
  58. self.HitMarkerTime = CurTime() + 0.2
  59. self.HitMarkerAlpha = 255
  60. end
  61. end
  62. end
  63.  
  64. self.Owner:FireBullets(bul)
  65.  
  66. tr.start = sp
  67. tr.endpos = tr.start + Dir2 * 16384
  68. tr.filter = self.Owner
  69. tr.mask = trace_normal
  70.  
  71. trace = util.TraceLine(tr)
  72.  
  73. if not NoPenetration[trace.MatType] then
  74. dot = -Dir2:DotProduct(trace.HitNormal)
  75. ent = trace.Entity
  76.  
  77. if dot > 0.26 and not ent:IsNPC() and not ent:IsPlayer() then
  78. tr.start = trace.HitPos
  79. tr.endpos = tr.start + Dir2 * self.PenStr * (PenMod[trace.MatType] and PenMod[trace.MatType] or 1) * self.PenMod
  80. tr.filter = self.Owner
  81. tr.mask = trace_walls
  82.  
  83. trace = util.TraceLine(tr)
  84.  
  85. tr.start = trace.HitPos
  86. tr.endpos = tr.start + Dir2 * 0.1
  87. tr.filter = self.Owner
  88. tr.mask = trace_normal
  89.  
  90. trace = util.TraceLine(tr) -- run ANOTHER trace to check whether we've penetrated a surface or not
  91.  
  92. if not trace.Hit then
  93. bul.Num = 1
  94. bul.Src = trace.HitPos
  95. bul.Dir = Dir2
  96. bul.Spread = Vec0
  97. bul.Tracer = 4
  98. bul.Force = self.Damage * 0.5
  99. bul.Damage = bul.Damage * 0.5
  100.  
  101. bul.Callback = function(a, b, c)
  102. if SERVER and SP and hm > 0 then
  103. ent = b.Entity
  104.  
  105. if ent:IsNPC() or ent:IsPlayer() then
  106. SendUserMessage("FAS2_HITMARKER", self.Owner)
  107. end
  108. end
  109.  
  110. if CLIENT and hm > 0 then
  111. ent = b.Entity
  112.  
  113. if ent:IsNPC() or ent:IsPlayer() then
  114. self.HitMarkerTime = CurTime() + 0.2
  115. self.HitMarkerAlpha = 255
  116. end
  117. end
  118. end
  119.  
  120. self.Owner:FireBullets(bul)
  121.  
  122. bul.Num = 1
  123. bul.Src = trace.HitPos
  124. bul.Dir = -Dir2
  125. bul.Spread = Vec0
  126. bul.Tracer = 4
  127. bul.Force = self.Damage * 0.5
  128. bul.Damage = bul.Damage * 0.5
  129.  
  130. bul.Callback = function(a, b, c)
  131. if SERVER and SP and hm > 0 then
  132. ent = b.Entity
  133.  
  134. if ent:IsNPC() or ent:IsPlayer() then
  135. SendUserMessage("FAS2_HITMARKER", self.Owner)
  136. end
  137. end
  138.  
  139. if CLIENT and hm > 0 then
  140. ent = b.Entity
  141.  
  142. if ent:IsNPC() or ent:IsPlayer() then
  143. self.HitMarkerTime = CurTime() + 0.2
  144. self.HitMarkerAlpha = 255
  145. end
  146. end
  147. end
  148.  
  149. self.Owner:FireBullets(bul)
  150. end
  151. else
  152. if not NoRicochet[trace.MatType] then
  153. Dir2 = Dir2 + (trace.HitNormal * dot) * 3
  154. Dir2 = Dir2 + VectorRand() * 0.06
  155. bul.Num = 1
  156. bul.Src = trace.HitPos
  157. bul.Dir = Dir2
  158. bul.Spread = Vec0
  159. bul.Tracer = 0
  160. bul.Force = self.Damage * 0.75
  161. bul.Damage = bul.Damage * 0.75
  162.  
  163. bul.Callback = function(a, b, c)
  164. if SERVER and SP then
  165. ent = b.Entity
  166.  
  167. if ent:IsNPC() or ent:IsPlayer() then
  168. SendUserMessage("FAS2_HITMARKER", self.Owner)
  169. end
  170. end
  171.  
  172. if CLIENT and hm > 0 then
  173. ent = b.Entity
  174.  
  175. if ent:IsNPC() or ent:IsPlayer() then
  176. self.HitMarkerTime = CurTime() + 0.2
  177. self.HitMarkerAlpha = 255
  178. end
  179. end
  180. end
  181.  
  182. self.Owner:FireBullets(bul)
  183. end
  184. end
  185. end
  186. end
  187.  
  188. tr.mask = trace_normal
  189. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement