Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: Lua  |  size: 5.38 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. if SERVER then
  2.         AddCSLuaFile("shared.lua")
  3. end
  4.  
  5. if CLIENT then
  6.         SWEP.PrintName = "Stun Stick"
  7.         SWEP.Slot = 0
  8.         SWEP.SlotPos = 5
  9.         SWEP.DrawAmmo = false
  10.         SWEP.DrawCrosshair = false
  11. end
  12.  
  13. SWEP.Base = "weapon_cs_base2"
  14.  
  15. SWEP.Author = "Rick Darkaliono, philxyz"
  16. SWEP.Instructions = "Left click to discipline, right click to kill"
  17. SWEP.Contact = ""
  18. SWEP.Purpose = ""
  19. SWEP.IconLetter = ""
  20.  
  21. SWEP.ViewModelFOV = 62
  22. SWEP.ViewModelFlip = false
  23. SWEP.AnimPrefix = "stunstick"
  24.  
  25. SWEP.Spawnable = false
  26. SWEP.AdminSpawnable = true
  27.  
  28. SWEP.NextStrike = 0
  29.  
  30. SWEP.ViewModel = Model("models/weapons/v_stunbaton.mdl")
  31. SWEP.WorldModel = Model("models/weapons/w_stunbaton.mdl")
  32.  
  33. SWEP.Sound = Sound("weapons/stunstick/stunstick_swing1.wav")
  34.  
  35. SWEP.Primary.ClipSize = -1
  36. SWEP.Primary.DefaultClip = 0
  37. SWEP.Primary.Automatic = false
  38. SWEP.Primary.Ammo = ""
  39.  
  40. SWEP.Secondary.ClipSize = -1
  41. SWEP.Secondary.DefaultClip = 0
  42. SWEP.Secondary.Automatic = false
  43. SWEP.Secondary.Ammo = ""
  44.  
  45. function SWEP:Deploy()
  46.         if CLIENT then return end
  47.         self:SetColor(0,0,255,255)
  48.         self:SetMaterial("models/shiny")
  49.         SendUserMessage("StunStickColour", self:GetOwner(), 0,0,255, "models/shiny")
  50.         return true
  51. end
  52.  
  53. function SWEP:Holster()
  54.         if CLIENT then return end
  55.         SendUserMessage("StunStickColour", self:GetOwner(), 255, 255, 255, "")
  56.         return true
  57. end
  58.  
  59. function SWEP:OnRemove()
  60.         if SERVER then
  61.                 SendUserMessage("StunStickColour", self:GetOwner(), 255, 255, 255, "")
  62.         end
  63. end
  64.  
  65. usermessage.Hook("StunStickColour", function(um)
  66.         local viewmodel = LocalPlayer():GetViewModel()
  67.         local r,g,b,a = um:ReadLong(), um:ReadLong(), um:ReadLong(), 255
  68.         viewmodel:SetColor(r,g,b,a)
  69.         viewmodel:SetMaterial(um:ReadString())
  70. end)
  71.  
  72. function SWEP:Initialize()
  73.         self:SetWeaponHoldType("normal")
  74.  
  75.         self.Hit = {
  76.                 Sound("weapons/stunstick/stunstick_impact1.wav"),
  77.                 Sound("weapons/stunstick/stunstick_impact2.wav")
  78.         }
  79.  
  80.         self.FleshHit = {
  81.                 Sound("weapons/stunstick/stunstick_fleshhit1.wav"),
  82.                 Sound("weapons/stunstick/stunstick_fleshhit2.wav")
  83.         }
  84. end
  85.  
  86. function SWEP:DoFlash(ply)
  87.         if not ValidEntity(ply) or not ply:IsPlayer() then return end
  88.         umsg.Start("StunStickFlash", ply)
  89.         umsg.End()
  90. end
  91.  
  92. function SWEP:PrimaryAttack()
  93.         if CurTime() < self.NextStrike then return end
  94.        
  95.         self:SetWeaponHoldType("melee")
  96.         timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self)
  97.        
  98.         self.Owner:SetAnimation(PLAYER_ATTACK1)
  99.         self.Weapon:EmitSound(self.Sound)
  100.         self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
  101.  
  102.         self.NextStrike = CurTime() + .3
  103.  
  104.         if CLIENT then return end
  105.        
  106.         local trace = self.Owner:GetEyeTrace()
  107.  
  108.         if not ValidEntity(trace.Entity) or (self.Owner:EyePos():Distance(trace.Entity:GetPos()) > 100) then return end
  109.  
  110.         if not trace.Entity:IsDoor() then
  111.                 trace.Entity:SetVelocity((trace.Entity:GetPos() - self.Owner:GetPos()) * 7)
  112.         end
  113.  
  114.         if trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:IsVehicle() then
  115.                 self.DoFlash(self, trace.Entity)
  116.                 self.Owner:EmitSound(self.FleshHit[math.random(1,#self.FleshHit)])
  117.         else
  118.                 self.Owner:EmitSound(self.Hit[math.random(1,#self.Hit)])
  119.                 if FPP and FPP.PlayerCanTouchEnt(self.Owner, self, "EntityDamage", "FPP_ENTITYDAMAGE") then
  120.                         trace.Entity:TakeDamage(1000, self.Owner, self) -- for illegal entities
  121.                 end
  122.         end
  123. end
  124.  
  125. function SWEP:SecondaryAttack()
  126.         if CurTime() < self.NextStrike then return end
  127.  
  128.         self.Owner:SetAnimation(PLAYER_ATTACK1)
  129.         self.Weapon:EmitSound(self.Sound)
  130.         self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
  131.  
  132.         self.NextStrike = CurTime() + .3
  133.        
  134.         self:SetWeaponHoldType("melee")
  135.         timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self)
  136.  
  137.         if CLIENT then return end
  138.        
  139.         local trace = self.Owner:GetEyeTrace()
  140.  
  141.         if (not ValidEntity(trace.Entity) or (self.Owner:EyePos():Distance(trace.Entity:GetPos()) > 100)) then return end
  142.  
  143.         if SERVER then
  144.                 if not trace.Entity:IsDoor() then
  145.                         trace.Entity:SetVelocity((trace.Entity:GetPos() - self.Owner:GetPos()) * 7)
  146.                 end
  147.                
  148.                 trace.Entity:TakeDamage(10, self.Owner, self)
  149.                
  150.                 if trace.Entity:IsPlayer() or trace.Entity:IsVehicle() then
  151.                         self.DoFlash(self, trace.Entity)
  152.                         self.Owner:EmitSound(self.FleshHit[math.random(1,#self.FleshHit)])
  153.                 elseif trace.Entity:IsNPC() then
  154.                         self.Owner:EmitSound(self.FleshHit[math.random(1,#self.FleshHit)])
  155.                 else
  156.                         self.Owner:EmitSound(self.Hit[math.random(1,#self.Hit)])
  157.                         if FPP and FPP.PlayerCanTouchEnt(ply, self, "EntityDamage", "FPP_ENTITYDAMAGE") then
  158.                                 trace.Entity:TakeDamage(990, self.Owner, self)
  159.                         end
  160.                 end
  161.         end
  162. end
  163.  
  164. function SWEP:Reload()
  165.         self:SetWeaponHoldType("melee")
  166.         timer.Destroy("rp_stunstick_threaten")
  167.         timer.Create("rp_stunstick_threaten", 1, 1, function() self:SetWeaponHoldType("normal") end)
  168.        
  169.         if not SERVER then return end
  170.        
  171.         if self.LastReload and self.LastReload > CurTime() - 0.1 then self.LastReload = CurTime() return end
  172.         self.LastReload = CurTime()
  173.         self.Owner:EmitSound("weapons/stunstick/spark"..math.random(1,3)..".wav")
  174. end
  175.  
  176. if CLIENT then
  177.         local function StunStickFlash()
  178.                 local alpha = 255
  179.                 hook.Add("HUDPaint", "RP_StunstickFlash", function()
  180.                         alpha = Lerp(0.05, alpha, 0)
  181.                         surface.SetDrawColor(255,255,255,alpha)
  182.                         surface.DrawRect(0,0,ScrW(), ScrH())
  183.  
  184.                         if math.Round(alpha) == 0 then
  185.                                 hook.Remove("HUDPaint", "RP_StunstickFlash")
  186.                         end
  187.                 end)
  188.         end
  189.         usermessage.Hook("StunStickFlash", StunStickFlash)
  190. end