Guest User

Untitled

a guest
Jul 21st, 2013
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if( SERVER ) then
  2. AddCSLuaFile( "shared.lua" )
  3. resource.AddFile("materials/vgui/ttt/icon_bb_katana.vmt")
  4. resource.AddFile( "models/weapons/W_katana.dx80.vtx" )
  5. resource.AddFile( "models/weapons/W_katana.dx90.vtx" )
  6. resource.AddFile( "models/weapons/w_katana.mdl" )
  7. resource.AddFile( "models/weapons/W_katana.phy" )
  8. resource.AddFile( "models/weapons/W_katana.sw.vtx" )
  9. resource.AddFile( "models/weapons/w_katana.vvd" )
  10. resource.AddFile("models/weapons/v_katana.mdl")
  11. resource.AddFile("materials/models/weapons/v_katana/katana_normal.vtf")
  12. resource.AddFile("materials/models/weapons/v_katana/katana.vtf")
  13. resource.AddFile("materials/models/weapons/v_katana/katana.vmt")
  14. resource.AddFile("materials/vgui/entities/weapon_katana.vmt")
  15. resource.AddFile("materials/vgui/entities/weapon_katana.vtf")
  16. resource.AddFile("sound/katana/glass_hit_1.wav")
  17. resource.AddFile("sound/katana/glass_hit_2.wav")
  18. resource.AddFile("sound/katana/glass_hit_3.wav")
  19. resource.AddFile("sound/katana/wood_hit_1.wav")
  20. resource.AddFile("sound/katana/wood_hit_2.wav")
  21. resource.AddFile("sound/katana/wood_hit_3.wav")
  22. resource.AddFile("sound/katana/ground_hit_1.wav")
  23. resource.AddFile("sound/katana/ground_hit_2.wav")
  24. resource.AddFile("sound/katana/ground_hit_3.wav")
  25. resource.AddFile("sound/katana/ground_hit_4.wav")
  26. resource.AddFile("sound/katana/ground_hit_5.wav")
  27. resource.AddFile("sound/katana/metal_hit_1.wav")
  28. resource.AddFile("sound/katana/metal_hit_2.wav")
  29. resource.AddFile("sound/katana/metal_hit_3.wav")
  30. resource.AddFile("sound/katana/metal_hit_4.wav")
  31. resource.AddFile("sound/katana/metal_hit_5.wav")
  32. resource.AddFile("sound/katana/metal_hit_6.wav")
  33. resource.AddFile("sound/katana/metal_hit_7.wav")
  34. resource.AddFile("sound/katana/draw.wav")
  35. end
  36.  
  37. if CLIENT then
  38.  
  39.    SWEP.PrintName    = "Katana"
  40.    SWEP.Slot         = 6
  41.  
  42.    SWEP.ViewModelFlip = false
  43.  
  44.    SWEP.EquipMenuData = {
  45.       type="Weapon",
  46.       desc="Katana, the famous japanese sword.\nDeadly."
  47.    };
  48.  
  49.    SWEP.Icon = "vgui/ttt/icon_bb_katana"
  50. end
  51.  
  52. SWEP.Base               = "weapon_tttbase"
  53.  
  54. SWEP.PrintName = "Katana"
  55. SWEP.DrawAmmo = false
  56. SWEP.Author         = "Baddog"
  57. SWEP.Instructions   = "Left click to slash. Right click to bash."
  58. SWEP.Contact        = ""
  59. SWEP.Purpose        = "Cut people up."
  60. SWEP.Category       = "Baddog's Weapons"
  61.  
  62. SWEP.ViewModelFOV   = 60
  63. SWEP.ViewModelFlip  = false
  64.  
  65. SWEP.Spawnable          = true
  66. SWEP.AdminSpawnable     = true
  67.  
  68.  
  69. SWEP.ViewModel      = "models/weapons/v_katana.mdl"
  70. SWEP.WorldModel     = "models/weapons/w_katana.mdl"
  71.  
  72. SWEP.Primary.Delay              = 0.6
  73. SWEP.Primary.ClipSize           = -1
  74. SWEP.Primary.DefaultClip        = -1
  75. SWEP.Primary.Automatic          = false
  76. SWEP.Primary.Ammo               = "none"
  77.  
  78. SWEP.Secondary.Delay            = 0.4
  79. SWEP.Secondary.ClipSize         = -1
  80. SWEP.Secondary.DefaultClip      = -1
  81. SWEP.Secondary.Automatic        = false
  82. SWEP.Secondary.Ammo             = "none"
  83.  
  84. SWEP.Kind = WEAPON_EQUIP1
  85. SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
  86. SWEP.LimitedStock = true -- only buyable once
  87.  
  88. function SWEP:Initialize()
  89. self:SetWeaponHoldType("sword")
  90. SWoodHit = {
  91.     Sound( "katana/wood_hit_1.wav" ),
  92.     Sound( "katana/wood_hit_2.wav" ),
  93.     Sound( "katana/wood_hit_3.wav" )}
  94. SFleshHit = {
  95.     Sound( "ambient/machines/slicer1.wav" ),
  96.     Sound( "ambient/machines/slicer2.wav" ),
  97.     Sound( "ambient/machines/slicer3.wav" ),
  98.     Sound( "ambient/machines/slicer4.wav" )}
  99. SGlassHit = {
  100.     Sound( "katana/glass_hit_1.wav" ),
  101.     Sound( "katana/glass_hit_2.wav" ),
  102.     Sound( "katana/glass_hit_3.wav" )}
  103. SMetalHit = {
  104.     Sound( "katana/metal_hit_1.wav" ),
  105.     Sound( "katana/metal_hit_2.wav" ),
  106.     Sound( "katana/metal_hit_3.wav" ),
  107.     Sound( "katana/metal_hit_4.wav" ),
  108.     Sound( "katana/metal_hit_5.wav" ),
  109.     Sound( "katana/metal_hit_6.wav" ),
  110.     Sound( "katana/metal_hit_7.wav" )}
  111. SGroundHit = {
  112.     Sound( "katana/ground_hit_1.wav" ),
  113.     Sound( "katana/ground_hit_2.wav" ),
  114.     Sound( "katana/ground_hit_3.wav" ),
  115.     Sound( "katana/ground_hit_4.wav" ),
  116.     Sound( "katana/ground_hit_5.wav" )}
  117. BWoodHit = {
  118.     Sound( "physics/wood/wood_box_impact_hard1.wav" ),
  119.     Sound( "physics/wood/wood_box_impact_hard2.wav" ),
  120.     Sound( "physics/wood/wood_box_impact_hard3.wav" ),
  121.     Sound( "physics/wood/wood_box_impact_hard4.wav" ),
  122.     Sound( "physics/wood/wood_box_impact_hard5.wav" ),
  123.     Sound( "physics/wood/wood_box_impact_hard6.wav" )}
  124. BFleshHit = {
  125.     Sound( "physics/flesh/flesh_impact_hard1.wav" ),
  126.     Sound( "physics/flesh/flesh_impact_hard2.wav" ),
  127.     Sound( "physics/flesh/flesh_impact_hard3.wav" ),
  128.     Sound( "physics/flesh/flesh_impact_hard4.wav" ),
  129.     Sound( "physics/flesh/flesh_impact_hard5.wav" ),
  130.     Sound( "physics/flesh/flesh_impact_hard6.wav" )}
  131. BGlassHit = {
  132.     Sound( "physics/glass/glass_sheet_impact_hard1.wav" ),
  133.     Sound( "physics/glass/glass_sheet_impact_hard2.wav" ),
  134.     Sound( "physics/glass/glass_sheet_impact_hard3.wav" )}
  135. BRockHit = {
  136.     Sound( "physics/concrete/concrete_impact_hard1.wav" ),
  137.     Sound( "physics/concrete/concrete_impact_hard2.wav" ),
  138.     Sound( "physics/concrete/concrete_impact_hard3.wav" )}
  139. BMetalHit = {
  140.     Sound( "physics/metal/metal_barrel_impact_hard1.wav" ),
  141.     Sound( "physics/metal/metal_barrel_impact_hard2.wav" ),
  142.     Sound( "physics/metal/metal_barrel_impact_hard3.wav" ),
  143.     Sound( "physics/metal/metal_barrel_impact_hard5.wav" ),
  144.     Sound( "physics/metal/metal_barrel_impact_hard6.wav" ),
  145.     Sound( "physics/metal/metal_barrel_impact_hard7.wav" ),
  146.     Sound( "physics/metal/metal_box_impact_hard1.wav" ),
  147.     Sound( "physics/metal/metal_box_impact_hard2.wav" ),
  148.     Sound( "physics/metal/metal_box_impact_hard3.wav" ),
  149.     Sound( "physics/metal/metal_computer_impact_hard1.wav" ),
  150.     Sound( "physics/metal/metal_computer_impact_hard2.wav" ),
  151.     Sound( "physics/metal/metal_computer_impact_hard3.wav" ),
  152.     Sound( "physics/metal/metal_grate_impact_hard1.wav" ),
  153.     Sound( "physics/metal/metal_grate_impact_hard2.wav" ),
  154.     Sound( "physics/metal/metal_grate_impact_hard3.wav" ),
  155.     Sound( "physics/metal/metal_sheet_impact_hard2.wav" ),
  156.     Sound( "physics/metal/metal_sheet_impact_hard6.wav" ),
  157.     Sound( "physics/metal/metal_sheet_impact_hard7.wav" ),
  158.     Sound( "physics/metal/metal_sheet_impact_hard8.wav" ),
  159.     Sound( "physics/metal/metal_solid_impact_hard1.wav" ),
  160.     Sound( "physics/metal/metal_solid_impact_hard4.wav" ),
  161.     Sound( "physics/metal/metal_solid_impact_hard5.wav" )}
  162. BGroundHit = {
  163.     Sound( "physics/surfaces/sand_impact_bullet1.wav" ),
  164.     Sound( "physics/surfaces/sand_impact_bullet2.wav" ),
  165.     Sound( "physics/surfaces/sand_impact_bullet3.wav" ),
  166.     Sound( "physics/surfaces/sand_impact_bullet4.wav" )}
  167. end
  168.  
  169. function SWEP:Holster()
  170. return true
  171. end
  172.  
  173. function SWEP:Deploy()
  174.     self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
  175.     self:SetNextPrimaryFire(CurTime() + 0.7)
  176.     self:SetNextSecondaryFire(CurTime() + 0.7)
  177.     self.Weapon:EmitSound("katana/draw.wav")
  178. return true
  179. end
  180.  
  181. function SWEP:OnRemove()
  182. return true
  183. end
  184.  
  185. function SWEP:PreDrop()
  186.    -- for consistency, dropped knife should not have DNA/prints
  187.    self.fingerprints = {}
  188. end
  189.  
  190. function SWEP:SecondaryAttack()
  191.     self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  192.     self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  193.     timer.Simple(0.10,self.Bash, self)
  194.     self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
  195.     self.Owner:SetAnimation( PLAYER_ATTACK1 )
  196. end
  197.  
  198. function SWEP:PrimaryAttack()
  199.     self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  200.     self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  201.     timer.Simple(0.15,self.Slash, self)
  202.     self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
  203.     self.Owner:SetAnimation( PLAYER_ATTACK1 )
  204. end
  205.  
  206. function SWEP:Slash()
  207.     local phtr = self.Owner:GetEyeTrace()
  208.     local trace = util.GetPlayerTrace(self.Owner)
  209.     local tr = util.TraceLine(trace)
  210.     local ph = phtr.Entity:GetPhysicsObject()
  211.     if (self.Owner:GetPos() - tr.HitPos):Length() < 100 then
  212.         if tr.Entity:IsPlayer() or string.find(tr.Entity:GetClass(),"npc") or string.find(tr.Entity:GetClass(),"prop_ragdoll") or tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH or tr.MatType == MAT_ANTLION then
  213.            
  214.             self.Weapon:EmitSound( SFleshHit[math.random(1,#SFleshHit)] )
  215.                     bullet = {}
  216.                     bullet.Num    = 1
  217.                     bullet.Src    = self.Owner:GetShootPos()
  218.                     bullet.Dir    = self.Owner:GetAimVector()
  219.                     bullet.Spread = Vector(0, 0, 0)
  220.                     bullet.Tracer = 0
  221.                     bullet.Force  = 20
  222.                     bullet.Damage = 65             
  223.                 self.Owner:FireBullets(bullet)                         
  224.         else
  225.             util.Decal("ManhackCut", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
  226.                
  227.                 if (tr.MatType == MAT_METAL or tr.MatType == MAT_VENT or tr.MatType == MAT_COMPUTER) then
  228.                 self.Weapon:EmitSound(SMetalHit[math.random(1,#SMetalHit)])
  229.                 elseif (tr.MatType == MAT_WOOD or tr.MatType == "MAT_FOLIAGE") then
  230.                 self.Weapon:EmitSound(SWoodHit[math.random(1,#SWoodHit)])
  231.                 elseif (tr.MatType == MAT_GLASS) then
  232.                 self.Weapon:EmitSound(SGlassHit[math.random(1,#SGlassHit)])
  233.                 elseif (tr.MatType == MAT_DIRT or tr.MatType == MAT_SAND or tr.MatType == MAT_SLOSH or tr.MatType == MAT_TILE or tr.MatType == MAT_PLASTIC or tr.MatType == MAT_CONCRETE) then
  234.                 self.Weapon:EmitSound(SGroundHit[math.random(1,#SGroundHit)])
  235.                 else
  236.                 self.Weapon:EmitSound(SGroundHit[math.random(1,#SGroundHit)])
  237.                 end
  238.             if not tr.HitWorld and not string.find(tr.Entity:GetClass(),"prop_static") then
  239.                 if SERVER then ph:ApplyForceCenter(self.Owner:GetAimVector()*5000)
  240.                 tr.Entity:TakeDamage(65, self.Owner, self)
  241.                 end
  242.             end
  243.         end
  244.     else
  245.         self.Weapon:EmitSound("Weapon_Knife.Slash")
  246.     end    
  247. end
  248.  
  249. function SWEP:Bash()
  250.     local phtr = self.Owner:GetEyeTrace()
  251.     local trace = util.GetPlayerTrace(self.Owner)
  252.     local tr = util.TraceLine(trace)
  253.     local ph = phtr.Entity:GetPhysicsObject()
  254.     if (self.Owner:GetPos() - tr.HitPos):Length() < 100 then
  255.         if tr.Entity:IsPlayer() or string.find(tr.Entity:GetClass(),"npc") or string.find(tr.Entity:GetClass(),"prop_ragdoll") or tr.MatType == MAT_FLESH then
  256.             self.Weapon:EmitSound( BFleshHit[math.random(1,#BFleshHit)] )
  257.             tr.Entity:SetVelocity((phtr.Entity:GetPos() - self.Owner:GetPos()) * 35)
  258.             if SERVER then
  259.             tr.Entity:TakeDamage(25, self.Owner, self)
  260.             end
  261.         else
  262.             if (tr.MatType == MAT_METAL or tr.MatType == MAT_VENT or tr.MatType == MAT_COMPUTER) then
  263.             self.Weapon:EmitSound(BMetalHit[math.random(1,#BMetalHit)])
  264.             elseif (tr.MatType == MAT_WOOD or tr.MatType == "MAT_FOLIAGE") then
  265.             self.Weapon:EmitSound(BWoodHit[math.random(1,#BWoodHit)])
  266.             elseif (tr.MatType == MAT_GLASS) then
  267.             self.Weapon:EmitSound(BGlassHit[math.random(1,#BGlassHit)])
  268.             elseif (tr.MatType == MAT_DIRT or tr.MatType == MAT_SAND or tr.MatType == MAT_SLOSH or tr.MatType == MAT_TILE or tr.MatType == MAT_PLASTIC) then
  269.             self.Weapon:EmitSound(BGroundHit[math.random(1,#BGroundHit)])
  270.             elseif (tr.MatType == MAT_CONCRETE) then
  271.             self.Weapon:EmitSound(BRockHit[math.random(1,#BRockHit)])
  272.             else
  273.             self.Weapon:EmitSound(BGroundHit[math.random(1,#BGroundHit)])
  274.             end
  275.             if not tr.HitWorld and not string.find(tr.Entity:GetClass(),"prop_static") then
  276.                 if SERVER then ph:ApplyForceCenter(self.Owner:GetAimVector()*20000)
  277.                 tr.Entity:TakeDamage(25, self.Owner, self)
  278.                 end
  279.             end
  280.         end
  281.     else
  282.         self.Weapon:EmitSound("Weapon_Knife.Slash")
  283.     end
  284. end
  285.  
  286.  
  287. local ActIndex = {}
  288.     ActIndex["pistol"]      = ACT_HL2MP_IDLE_PISTOL
  289.     ActIndex["smg"]             = ACT_HL2MP_IDLE_SMG1
  290.     ActIndex["grenade"]         = ACT_HL2MP_IDLE_GRENADE
  291.     ActIndex["ar2"]             = ACT_HL2MP_IDLE_AR2
  292.     ActIndex["shotgun"]         = ACT_HL2MP_IDLE_SHOTGUN
  293.     ActIndex["rpg"]         = ACT_HL2MP_IDLE_RPG
  294.     ActIndex["physgun"]         = ACT_HL2MP_IDLE_PHYSGUN
  295.     ActIndex["crossbow"]        = ACT_HL2MP_IDLE_CROSSBOW
  296.     ActIndex["melee"]       = ACT_HL2MP_IDLE_MELEE
  297.     ActIndex["slam"]            = ACT_HL2MP_IDLE_SLAM
  298.     ActIndex["normal"]      = ACT_HL2MP_IDLE
  299.     ActIndex["knife"]           = ACT_HL2MP_IDLE_KNIFE
  300.     ActIndex["sword"]           = ACT_HL2MP_IDLE_MELEE2
  301.     ActIndex["passive"]     = ACT_HL2MP_IDLE_PASSIVE
  302.     ActIndex["fist"]            = ACT_HL2MP_IDLE_FIST
  303.  
  304. function SWEP:SetWeaponHoldType(t)
  305.  
  306.     local index = ActIndex[t]
  307.    
  308.     if (index == nil) then
  309.         Msg("SWEP:SetWeaponHoldType - ActIndex[ \""..t.."\" ] isn't set!\n")
  310.         return
  311.     end
  312.  
  313. self.ActivityTranslate = {}
  314. self.ActivityTranslate [ ACT_MP_STAND_IDLE ]                = index
  315. self.ActivityTranslate [ ACT_MP_WALK ]                      = index+1
  316. self.ActivityTranslate [ ACT_MP_RUN ]                       = index+2        
  317. self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ]               = index+3
  318. self.ActivityTranslate [ ACT_MP_CROUCHWALK ]                = index+4
  319. self.ActivityTranslate [ ACT_MP_ATTACK_STAND_PRIMARYFIRE ]  = index+5
  320. self.ActivityTranslate [ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index+5
  321. self.ActivityTranslate [ ACT_MP_RELOAD_STAND ]              = index+6
  322. self.ActivityTranslate [ ACT_MP_RELOAD_CROUCH ]             = index+6
  323. self.ActivityTranslate [ ACT_MP_JUMP ]                      = index+7
  324. self.ActivityTranslate [ ACT_RANGE_ATTACK1 ]                = index+8
  325.     if t == "normal" then
  326.         self.ActivityTranslate [ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
  327.     end
  328.     if t == "passive" then
  329.         self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = ACT_HL2MP_CROUCH_IDLE
  330.     end
  331.     self:SetupWeaponHoldTypeForAI(t)
  332. end
  333.  
  334. function SWEP:TranslateActivity(act)
  335.  
  336.     if (self.Owner:IsNPC()) then
  337.         if (self.ActivityTranslateAI[act]) then
  338.             return self.ActivityTranslateAI[act]
  339.         end
  340.  
  341.         return -1
  342.     end
  343.  
  344.     if (self.ActivityTranslate[act] != nil) then
  345.         return self.ActivityTranslate[act]
  346.     end
  347.    
  348.     return -1
  349. end
RAW Paste Data