Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.76 KB | None | 0 0
  1. if (SERVER) then
  2.     AddCSLuaFile( "shared.lua" )
  3. end
  4.  
  5. SWEP.PrintName          = "Snowballs! (no damage)" 
  6. SWEP.Slot               = 1
  7. SWEP.Author             = "BlackJackit, Edited from IceAxe Realistic Weapon, Bugs Fixing by Wood, all credits to the creators"
  8. SWEP.DrawAmmo           = true
  9. SWEP.DrawCrosshair      = true
  10. SWEP.ViewModelFOV       = 62
  11. SWEP.ViewModelFlip      = false
  12. SWEP.CSMuzzleFlashes    = false
  13. SWEP.SlotPos            = 1
  14. SWEP.IconLetter         = "S"
  15. SWEP.Weight             = 0 --was 5, to remove all the damage
  16. SWEP.AutoSwitchTo       = false
  17. SWEP.AutoSwitchFrom     = false
  18. SWEP.HoldType           = "pistol"
  19. SWEP.Instructions       = "Left click to launch a snowball \nReload to take another one\nUSE key to change trails color\n"
  20. SWEP.Category           = "Snowballs! (no damage)"
  21. SWEP.Spawnable          = true
  22. SWEP.AdminSpawnable     = true
  23. SWEP.ViewModel          = "models/weapons/v_snowball.mdl"
  24. SWEP.WorldModel         = "models/weapons/w_snowball.mdl"
  25. SWEP.AutoSwitchTo           = false
  26. SWEP.AutoSwitchFrom         = false
  27. SWEP.Primary.ClipSize       = 1
  28. SWEP.Primary.Damage         = 0 -- was 60000, to remove all the damage
  29. SWEP.Primary.Delay          = 0
  30. SWEP.Primary.DefaultClip    = 1
  31. SWEP.Primary.Automatic      = false
  32. SWEP.Primary.Ammo           = "none"
  33. SWEP.Secondary.ClipSize     = 1
  34. SWEP.Secondary.DefaultClip  = 1
  35. SWEP.Secondary.Damage       = 0
  36. SWEP.Secondary.Delay        = 2
  37. SWEP.Secondary.Automatic    = false
  38. SWEP.Secondary.Ammo         = "none"
  39. SWEP.ReloadSound            = "none.wav"
  40. SWEP.DrawSound              = "pinpull.wav"
  41.  
  42. SWEP.IronSightsPos          = Vector(-15, 0, 15) -- Comment out this line of you don't want ironsights.  This variable must be present if your SWEP is to use a scope.
  43. SWEP.IronSightsAng          = Vector(0, 0, 0)
  44. SWEP.IronSightZoom          = 1.0 -- How much the player's FOV should zoom in ironsight mode.
  45.  
  46. function SWEP:Think()
  47. end
  48.  
  49. currentnumber = 0
  50. white = Color(255,255,255,255)
  51. green = Color(50,205,50,255)
  52. blue = Color(72,118,255,255)
  53. red = Color(255,48,48,255)
  54. yellow = Color(255,255,0,255)
  55. pink = Color(255,182,193,255)
  56. damageactivated = 0; -- was 1, default there's no damage
  57. currentcolor = white
  58.    
  59.  
  60. function SWEP:Initialize()
  61.     self:SetWeaponHoldType( self.HoldType )
  62.     self:SetIronsights(false,self.Owner)
  63.     util.PrecacheSound("weapons/iceaxe/iceaxe_swing1.wav")
  64.     util.PrecacheSound("hit.wav")
  65.     hook.Add( "KeyPress", "KeyPressedHook", colorchange )
  66. end
  67.  
  68. function SWEP:Holster()
  69.     hook.Remove("KeyPress", "colorchange")
  70.     return true
  71. end
  72.  
  73.  
  74.  
  75. /*---------------------------------------------------------
  76. SecondaryAttack
  77. ---------------------------------------------------------*/
  78. function SWEP:SecondaryAttack()
  79.  
  80. end
  81.  
  82. /*---------------------------------------------------------
  83. PrimaryAttack
  84. ---------------------------------------------------------*/
  85. function SWEP:PrimaryAttack()
  86.     self.Owner:SetAnimation( PLAYER_ATTACK1 )
  87.     self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
  88.    
  89.     local trace = {}
  90.     trace.start = self.Owner:GetShootPos()
  91.     trace.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 10^14
  92.     trace.filter = self.Owner
  93.     local tr = util.TraceLine(trace)
  94.  
  95.     local vAng = (tr.HitPos-self.Owner:GetShootPos()):GetNormal():Angle()
  96.     --tr.Entity:SetKeyValue("targetname", "disTarg")
  97.    
  98.     if SERVER then
  99.         local Front = self.Owner:GetAimVector();
  100.         local Up = self.Owner:EyeAngles():Up();
  101.        
  102.         if ( SERVER ) then -- only spawn things on server to prevent issues
  103.             local ball = ents.Create("ent_snowball_nodamage");
  104.  
  105.             if IsValid(ball) then
  106.  
  107.                 ball:SetPos(self.Owner:GetShootPos() + Front * 10 + Up * 10 * -1);
  108.                 ball:SetAngles(Front:Angle());
  109.                 ball:Spawn();
  110.                 ball:Activate();
  111.                 ball:SetOwner(self.Owner)
  112.                 local Physics = ball:GetPhysicsObject();
  113.  
  114.                 if IsValid(Physics) then
  115.        
  116.                 local Random = Front:Angle();
  117.                        
  118.                     Random = Random:Forward();
  119.                     Physics:ApplyForceCenter(Random * 850); -- Fixes masive throw (wood)
  120.                 end
  121.             end
  122.         end
  123.     end
  124.     self:SetIronsights(true,self.Owner)
  125.     self:Remove()
  126. end
  127.  
  128. function SWEP:Reload()
  129.     self:SetIronsights(false,self.Owner)
  130.     self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
  131.     return true
  132. end
  133.  
  134. local IRONSIGHT_TIME = 0.1 -- How long it takes to raise our rifle
  135. function SWEP:SetIronsights(b,player)
  136.  
  137. if CLIENT or (not player) or player:IsNPC() then return end
  138.     -- Send the ironsight state to the client, so it can adjust the player's FOV/Viewmodel pos accordingly
  139.     self.Weapon:SetNetworkedBool("Ironsights", b)
  140. end
  141.  
  142. function SWEP:OnRemove()
  143.     return true
  144. end
  145.  
  146. function SWEP:Holster()
  147.     return true
  148. end
  149.  
  150. function SWEP:ShootEffects()
  151. end
  152.  
  153. -- mostly garry's code
  154. function SWEP:GetViewModelPosition(pos, ang)
  155.  
  156.     if not self.IronSightsPos then return pos, ang end
  157.  
  158.     local bIron = self.Weapon:GetNetworkedBool("Ironsights")
  159.     if bIron ~= self.bLastIron then -- Are we toggling ironsights?
  160.    
  161.         self.bLastIron = bIron
  162.         self.fIronTime = CurTime()
  163.        
  164.         if bIron then
  165.             self.SwayScale  = 0.3
  166.             self.BobScale   = 0.1
  167.         else
  168.             self.SwayScale  = 1.0
  169.             self.BobScale   = 1.0
  170.         end
  171.    
  172.     end
  173.    
  174.     local fIronTime = self.fIronTime or 0
  175.  
  176.     if not bIron and (fIronTime < CurTime() - IRONSIGHT_TIME) then
  177.         return pos, ang
  178.     end
  179.    
  180.     local Mul = 1.0 -- we scale the model pos by this value so we can interpolate between ironsight/normal view
  181.    
  182.     if fIronTime > CurTime() - IRONSIGHT_TIME then
  183.    
  184.         Mul = math.Clamp((CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1)
  185.         if not bIron then Mul = 1 - Mul end
  186.    
  187.     end
  188.  
  189.     local Offset    = self.IronSightsPos
  190.    
  191.     if self.IronSightsAng then
  192.    
  193.         ang = ang*1
  194.         ang:RotateAroundAxis(ang:Right(),       self.IronSightsAng.x * Mul)
  195.         ang:RotateAroundAxis(ang:Up(),          self.IronSightsAng.y * Mul)
  196.         ang:RotateAroundAxis(ang:Forward(),     self.IronSightsAng.z * Mul)
  197.    
  198.     end
  199.    
  200.     local Right     = ang:Right()
  201.     local Up        = ang:Up()
  202.     local Forward   = ang:Forward()
  203.  
  204.     pos = pos + Offset.x * Right * Mul
  205.     pos = pos + Offset.y * Forward * Mul
  206.     pos = pos + Offset.z * Up * Mul
  207.  
  208.     return pos, ang
  209.    
  210. end
  211.  
  212. -- This function handles player FOV clientside.  It is used for scope and ironsight zooming.
  213. function SWEP:TranslateFOV(current_fov)
  214.  
  215.     local fScopeZoom = self.Weapon:GetNetworkedFloat("ScopeZoom")
  216.     if self.Weapon:GetNetworkedBool("Scope") then return current_fov/fScopeZoom end
  217.    
  218.     local bIron = self.Weapon:GetNetworkedBool("Ironsights")
  219.     if bIron ~= self.bLastIron then -- Do the same thing as in CalcViewModel.  I don't know why this works, but it does.
  220.    
  221.         self.bLastIron = bIron
  222.         self.fIronTime = CurTime()
  223.  
  224.     end
  225.    
  226.     local fIronTime = self.fIronTime or 0
  227.  
  228.     if not bIron and (fIronTime < CurTime() - IRONSIGHT_TIME) then
  229.         return current_fov
  230.     end
  231.    
  232.     local Mul = 1.0 -- More interpolating shit
  233.    
  234.     if fIronTime > CurTime() - IRONSIGHT_TIME then
  235.    
  236.         Mul = math.Clamp((CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1)
  237.         if not bIron then Mul = 1 - Mul end
  238.    
  239.     end
  240.  
  241.     current_fov = current_fov*(1 + Mul/self.IronSightZoom - Mul)
  242.  
  243.     return current_fov
  244.  
  245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement