Advertisement
Guest User

error

a guest
Jul 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. if (SERVER) then
  2.  
  3. SWEP.Weight = 5
  4. SWEP.AutoSwitchTo = false
  5. SWEP.AutoSwitchFrom = false
  6. end
  7.  
  8. if ( CLIENT ) then
  9. SWEP.PrintName = "M9 Bayonet Knife | Tiger Tooth"
  10. SWEP.DrawAmmo = false
  11. SWEP.DrawCrosshair = false
  12. SWEP.ViewModelFOV = 65
  13. SWEP.ViewModelFlip = false
  14. SWEP.CSMuzzleFlashes = true
  15. SWEP.UseHands = true
  16.  
  17. SWEP.Slot = 0
  18. SWEP.SlotPos = 0
  19. end
  20.  
  21. SWEP.Skin = "models/csgo_knife/knife_m9_tiger.vmt"
  22.  
  23. SWEP.Base = "weapon_tttbase"
  24. SWEP.HoldType = "knife"
  25.  
  26. SWEP.ViewModel = "models/weapons/v_csgo_m9.mdl"
  27. SWEP.WorldModel = "models/weapons/w_csgo_m9.mdl"
  28.  
  29. SWEP.Weight = 5
  30. SWEP.AutoSwitchTo = false
  31. SWEP.AutoSwitchFrom = false
  32.  
  33. SWEP.Primary.Damage = -1
  34. SWEP.Primary.ClipSize = -1
  35. SWEP.Primary.DefaultClip = -1
  36. SWEP.Primary.Automatic = true
  37. SWEP.Primary.Ammo = "none"
  38.  
  39. SWEP.Secondary.Damage = -1
  40. SWEP.Secondary.ClipSize = -1
  41. SWEP.Secondary.DefaultClip = -1
  42. SWEP.Secondary.Automatic = true
  43. SWEP.Secondary.Ammo = "none"
  44.  
  45. function SWEP:SetupDataTables() --This also used for variable declaration and SetVar/GetVar getting work
  46. self:NetworkVar( "Float", 0, "InspectTime" )
  47. self:NetworkVar( "Float", 1, "IdleTime" )
  48. self:NetworkVar( "String", 0, "Classname" ) --Do we need this?
  49. self:NetworkVar( "Bool", 0, "Thrown" )
  50. -- self:NetworkVar( "Entity", 0, "Attacker" ) --Do we need this?
  51. -- self:NetworkVar( "Entity", 1, "Victim" ) --Do we need this?
  52. self:NetworkVar( "Entity", 2, "ViewModel" )
  53. end
  54.  
  55. function SWEP:Initialize()
  56. if ( CLIENT ) then surface.SetMaterial(Material( self.Skin or "models/csgo_knife/cssource" )) end --Ugly hack. Used to "precache" skin's material
  57. self:SetClassname(self:GetClass())
  58. self:SetHoldType( self.AreDaggers and "fist" or "knife" ) -- Avoid using SetWeaponHoldType! Otherwise the players could hold it wrong!
  59. end
  60.  
  61. function SWEP:ViewModelDrawn(ViewModel)
  62. self:SetViewModel(ViewModel) -- Stores viewmodel's entity into NetworkVar, NOT actually changes viewmodel. Do we need this?
  63. self:PaintMaterial(ViewModel)
  64. end
  65.  
  66. function SWEP:PaintMaterial(vm)
  67. if ( CLIENT ) and IsValid(vm) then
  68. local Mat = self:GetThrown() and "" or ( self.Skin or "" )
  69. if IsValid(vm) and vm:GetModel() == self.ViewModel then vm:SetMaterial(Mat) end
  70. end
  71. end
  72.  
  73. function SWEP:ClearMaterial()
  74. if IsValid(self.Owner) then
  75. local Viewmodel = self.Owner:GetViewModel()
  76. if IsValid(Viewmodel) then Viewmodel:SetMaterial("") end
  77. end
  78. end
  79.  
  80. function SWEP:Think()
  81. if CurTime()>=self:GetIdleTime() then
  82. self.Weapon:SendWeaponAnim( ACT_VM_IDLE )
  83. self:SetIdleTime( CurTime() + self.Owner:GetViewModel():SequenceDuration() )
  84. end
  85. end
  86.  
  87. function SWEP:DrawWorldModel()
  88. self:SetMaterial(self.Skin or "")
  89. self:DrawModel()
  90. end
  91.  
  92. function SWEP:Deploy()
  93. self:SetInspectTime( 0 )
  94. self:SetIdleTime( CurTime() + self.Owner:GetViewModel():SequenceDuration() )
  95. self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
  96. local NextAttack = 1
  97. self.Weapon:SetNextPrimaryFire( CurTime() + NextAttack )
  98. self.Weapon:SetNextSecondaryFire( CurTime() + NextAttack )
  99. -- self.Weapon:EmitSound( "Weapon_Knife.Deploy" ) -- The deploy sound should be played only from v_ model
  100. return true
  101. end
  102.  
  103. function SWEP:EntityFaceBack(ent)
  104. local angle = self.Owner:GetAngles().y -ent:GetAngles().y
  105. if angle < -180 then angle = 360 +angle end
  106. if angle <= 90 and angle >= -90 then return true end
  107. return false
  108. end
  109.  
  110. function SWEP:PrimaryAttack()
  111. if CurTime() < self.Weapon:GetNextPrimaryFire() then return end
  112. self:DoAttack( false )
  113. end
  114.  
  115. function SWEP:SecondaryAttack()
  116. if CurTime() < self.Weapon:GetNextSecondaryFire() then return end
  117. self:DoAttack( true )
  118. end
  119.  
  120. function SWEP:DoAttack( Altfire )
  121. local Weapon = self.Weapon
  122. local Attacker = self:GetOwner()
  123. local Range = Altfire and 36 or 48
  124. local Forward = Attacker:GetAimVector()
  125. local AttackSrc = Attacker:EyePos()
  126. local AttackEnd = AttackSrc + Forward * Range
  127. local Act
  128. local Snd
  129. local Backstab
  130. local Damage
  131.  
  132. Attacker:LagCompensation(true)
  133.  
  134. local tracedata = {}
  135.  
  136. tracedata.start = AttackSrc
  137. tracedata.endpos = AttackEnd
  138. tracedata.filter = Attacker
  139. tracedata.mask = MASK_SOLID
  140. tracedata.mins = Vector( -16 , -16 , -18 )
  141. tracedata.maxs = Vector( 16, 16 , 18 )
  142.  
  143. -- We should calculate trajectory twice. If TraceHull hits entity, then we use second trace, otherwise - first.
  144. -- It's needed to prevent head-shooting since in CS:GO you cannot headshot with knife
  145. local tr1 = util.TraceLine( tracedata )
  146. local tr2 = util.TraceHull( tracedata )
  147. local tr = IsValid(tr2.Entity) and tr2 or tr1
  148.  
  149. Attacker:LagCompensation(false) -- Don't forget to disable it!
  150.  
  151. local DidHit = tr.Hit and not tr.HitSky
  152. local HitEntity = tr.Entity
  153. local DidHitPlrOrNPC = HitEntity and ( HitEntity:IsPlayer() or HitEntity:IsNPC() ) and IsValid( HitEntity )
  154.  
  155. -- Calculate damage and deal hurt if we can
  156. if DidHit then
  157. if HitEntity and IsValid( HitEntity ) then
  158. Backstab = DidHitPlrOrNPC and self:EntityFaceBack( HitEntity ) -- Because we can only backstab creatures
  159. Damage = ( Altfire and (Backstab and 180 or 55) ) or ( Backstab and 35 ) or 35
  160.  
  161. local damageinfo = DamageInfo()
  162. damageinfo:SetAttacker( Attacker )
  163. damageinfo:SetInflictor( self )
  164. damageinfo:SetDamage( Damage )
  165. damageinfo:SetDamageType( bit.bor( DMG_BULLET , DMG_NEVERGIB ) )
  166. damageinfo:SetDamageForce( Forward * 1000 )
  167. damageinfo:SetDamagePosition( AttackEnd )
  168. HitEntity:DispatchTraceAttack( damageinfo, tr, Forward )
  169.  
  170. else
  171. util.Decal("ManhackCut", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
  172. end
  173. end
  174.  
  175. --Change next attack time
  176. local NextAttack = Altfire and 1.0 or DidHit and 0.5 or 0.4
  177. Weapon:SetNextPrimaryFire( CurTime() + NextAttack )
  178. Weapon:SetNextSecondaryFire( CurTime() + NextAttack )
  179.  
  180. Attacker:SetAnimation( PLAYER_ATTACK1 )
  181.  
  182. Act = DidHit and ( Altfire and ( Backstab and ACT_VM_SWINGHARD or ACT_VM_HITCENTER2 ) or ( Backstab and ACT_VM_SWINGHIT or ACT_VM_HITCENTER) ) or ( Altfire and ACT_VM_MISSCENTER2 or ACT_VM_MISSCENTER)
  183. if Act then
  184. Weapon:SendWeaponAnim( Act )
  185. self:SetIdleTime( CurTime() + self.Owner:GetViewModel():SequenceDuration() )
  186. end
  187.  
  188. --Play sound
  189. local Oldsounds
  190. if GetConVar("csgo_knives_oldsounds") then Oldsounds = GetConVar("csgo_knives_oldsounds"):GetBool() else Oldsounds = false end
  191. local StabSnd = "csgo_knife.Stab"
  192. local HitSnd = "csgo_knife.Hit"
  193. local HitwallSnd = Oldsounds and "csgo_knife.HitWall_old" or "csgo_knife.HitWall"
  194. local SlashSnd = Oldsounds and "csgo_knife.Slash_old" or "csgo_knife.Slash"
  195. Snd = DidHitPlrOrNPC and (Altfire and StabSnd or HitSnd) or DidHit and HitwallSnd or SlashSnd
  196. if Snd then Weapon:EmitSound( Snd ) end
  197.  
  198. return true
  199. end
  200.  
  201. function SWEP:Reload()
  202.  
  203. local getseq = self:GetSequence()
  204. local act = self:GetSequenceActivity(getseq)
  205. if (act == ACT_VM_IDLE_LOWERED and CurTime() < self:GetInspectTime()) then
  206. self:SetInspectTime( CurTime() + 0.1 ) -- We should press R repeately instead of holding it to loop
  207. return end
  208.  
  209. self.Weapon:SendWeaponAnim(ACT_VM_IDLE_LOWERED)
  210. self:SetIdleTime( CurTime() + self.Owner:GetViewModel():SequenceDuration() )
  211. self:SetInspectTime( CurTime() + 0.1 )
  212. return true
  213. end
  214.  
  215. function SWEP:Equip()
  216. self:SetThrown(false)
  217. end
  218.  
  219. function SWEP:OwnerChanged()
  220. self:ClearMaterial()
  221. return true
  222. end
  223.  
  224. function SWEP:OnRemove()
  225. self:ClearMaterial()
  226. return true
  227. end
  228.  
  229. function SWEP:Holster()
  230. self:ClearMaterial()
  231. return true
  232. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement