Anthr4x292

MindBlast Server Client Code: Some kind of banning/kick gun

Feb 11th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.01 KB | None | 0 0
  1. if SERVER then
  2.     AddCSLuaFile( "shared.lua" )
  3.  
  4.     SWEP.Weight             = 5
  5.     SWEP.AutoSwitchTo       = false
  6.     SWEP.AutoSwitchFrom     = false
  7. else
  8.     SWEP.DrawAmmo           = false
  9.     SWEP.DrawCrosshair      = false
  10.     SWEP.ViewModelFOV       = 82
  11.     SWEP.ViewModelFlip      = true
  12.     SWEP.CSMuzzleFlashes    = true
  13.    
  14.     surface.CreateFont( "csd", ScreenScale( 30 ), 500, true, true, "CSKillIcons" )
  15.     surface.CreateFont( "csd", ScreenScale( 60 ), 500, true, true, "CSSelectIcons" )
  16. end
  17.  
  18. SWEP.Author                 = "G-Force Connections"
  19. SWEP.Contact                = ""
  20. SWEP.Purpose                = "Remove enemies from play."
  21. SWEP.Instructions           = "Point, click, enjoy."
  22.  
  23. SWEP.Spawnable              = false
  24. SWEP.AdminSpawnable         = false
  25.  
  26. SWEP.Primary.Sound          = Sound( "Weapon_AK47.Single" )
  27. SWEP.Primary.Recoil         = 1.5
  28. SWEP.Primary.Damage         = 40
  29. SWEP.Primary.NumShots       = 1
  30. SWEP.Primary.Cone           = 0.02
  31. SWEP.Primary.Delay          = 0.15
  32.  
  33. SWEP.Primary.ClipSize       = -1
  34. SWEP.Primary.DefaultClip    = -1
  35. SWEP.Primary.Automatic      = false
  36. SWEP.Primary.Ammo           = "none"
  37.  
  38. SWEP.Secondary.ClipSize     = -1
  39. SWEP.Secondary.DefaultClip  = -1
  40. SWEP.Secondary.Automatic    = false
  41. SWEP.Secondary.Ammo         = "none"
  42.  
  43. SWEP.TracerRarity           = 4
  44. SWEP.MaxPenetration         = 4000
  45. SWEP.MaxPenetration_Depth   = 25
  46.  
  47. function SWEP:Initialize()
  48.     if SERVER then
  49.         timer.Simple( 0, function() if IsValid( self ) then self:Holster() end end )
  50.     end
  51.    
  52.     self:SetWeaponHoldType( self.HoldTypeNorm )
  53.    
  54.     self:SetIronsights( false )
  55.     self.bulletNumber = 0
  56. end
  57.  
  58. function SWEP:Reload()
  59.     self:DefaultReload( ACT_VM_RELOAD )
  60.     self:SetIronsights( false )
  61. end
  62.  
  63. function SWEP:PrimaryAttack()
  64.     self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  65.     self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
  66.  
  67.     if not self:CanPrimaryAttack() then return end
  68.     if not self.Weapon:GetDTBool( 0 ) then return end
  69.  
  70.     self.Weapon:EmitSound( self.Primary.Sound )
  71.    
  72.     self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone )
  73.    
  74.     self:TakePrimaryAmmo( 1 )
  75.    
  76.     if self.Owner:IsNPC() then return end
  77.    
  78.     self.Owner:ViewPunch( Angle( math.Rand( -0.2, -0.1 ) * self.Primary.Recoil, math.Rand( -0.1, 0.1 ) * self.Primary.Recoil, 0 ) )
  79. end
  80.  
  81. SWEP.NextSecondaryAttack = 0
  82. function SWEP:SecondaryAttack()
  83.     if not self.IronSightsPos then return end
  84.     if self.NextSecondaryAttack > CurTime() then return end
  85.    
  86.     self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  87.    
  88.     self:SetIronsights( not self.Weapon:GetDTBool( 0 ) )
  89.    
  90.     self.NextSecondaryAttack = CurTime() + 0.3
  91. end
  92.  
  93. usermessage.Hook( "perp_wep_sethold", function( UMsg )
  94.     local ent = UMsg:ReadEntity()
  95.     local holdType = UMsg:ReadString()
  96.    
  97.     if not ent or not ent:IsValid() or not ent.SetWeaponHoldType then return end
  98.    
  99.     ent:SetWeaponHoldType( holdType )
  100. end )
  101.  
  102. function SWEP:SetIronsights( b )
  103.     self.Weapon:SetDTBool( 0, b )
  104.    
  105.     if SERVER then
  106.         if b then
  107.             self:SetWeaponHoldType( self.HoldType )
  108.            
  109.             umsg.Start( "perp_wep_sethold" )
  110.                 umsg.Entity( self )
  111.                 umsg.String( self.HoldType )
  112.             umsg.End()
  113.         else
  114.             self:SetWeaponHoldType( self.HoldTypeNorm )
  115.            
  116.             umsg.Start( "perp_wep_sethold" )
  117.                 umsg.Entity( self )
  118.                 umsg.String( self.HoldTypeNorm )
  119.             umsg.End()
  120.         end
  121.     end
  122. end
  123.  
  124. local function randSign()
  125.     while true do
  126.         local rand = math.random( -1, 1 )
  127.        
  128.         if rand ~= 0 then
  129.             return rand
  130.         end
  131.     end
  132. end
  133.  
  134. function SWEP:CSShootBullet( dmg, recoil, numbul, cone, fireFrom, aimVector, distanceLeft, showTracerOverride )
  135.     numbul  = numbul    or 1
  136.     cone    = cone      or 0.01
  137.     distanceLeft = distanceLeft or self.MaxPenetration
  138.     fireFrom = fireFrom or self.Owner:GetShootPos()
  139.     aimVector = aimVector or self.Owner:GetAimVector()
  140.  
  141.     for i = 1, numbul do
  142.         local showTracer = showTracerOverride or 0
  143.        
  144.         if not showTracerOverride then
  145.             self.bulletNumber = self.bulletNumber + 1
  146.            
  147.             if self.bulletNumber == self.TracerRarity then
  148.                 self.bulletNumber = 0
  149.                 showTracer = 1
  150.             end
  151.         end
  152.        
  153.         local realSpread = Vector( 0, 0, 0 )
  154.        
  155.         if cone ~= 0 then
  156.             realSpread = Vector( math.random() * cone * randSign(), math.random() * cone * randSign(), math.random() * cone * randSign() )
  157.         end
  158.        
  159.         local trueAim = aimVector + realSpread
  160.         local trace = {}
  161.         trace.start = fireFrom
  162.         trace.endpos = trace.start + ( trueAim * 1000000 )
  163.         trace.filter = self.Owner
  164.  
  165.         local traceRes = util.TraceLine( trace )
  166.         local dir = ( traceRes.HitPos - trace.start ):Normalize()
  167.         local hitPosition = traceRes.HitPos
  168.        
  169.         local bullet = {}
  170.         bullet.Num      = 1
  171.         bullet.Src      = fireFrom                              // Source
  172.         bullet.Dir      = dir                                   // Dir of bullet
  173.         bullet.Spread   = Vector( 0, 0, 0 )                     // Aim Cone
  174.         bullet.Tracer   = showTracer                            // Show a tracer on every x bullets
  175.         bullet.Force    = 5                                     // Amount of force to give to phys objects
  176.         bullet.Damage   = dmg
  177.        
  178.         self.Owner:FireBullets( bullet )
  179.  
  180.         if IsValid( traceRes.Entity ) and ( traceRes.Entity:IsPlayer() or traceRes.Entity:GetClass() == "prop_vehicle_jeep" ) then
  181.             if traceRes.Entity:IsPlayer() then
  182.                 if self.GrantExperience_Skill then
  183.                     self.Owner:GiveExperience( self.GrantExperience_Skill, self.GrantExperience_Exp )
  184.                 end
  185.             end
  186.  
  187.             if SERVER and traceRes.Entity:GetClass() == "prop_vehicle_jeep" and traceRes.Entity.CarDamage then
  188.                 if traceRes.Entity:GetModel() ~= "models/swatvan2.mdl" then
  189.                     traceRes.Entity.CarDamage = traceRes.Entity.CarDamage - ( dmg * .5 )
  190.                        
  191.                     if traceRes.Entity.CarDamage <= 0 then
  192.                         traceRes.Entity:DisableVehicle()
  193.                     end
  194.                        
  195.                     local Driver = traceRes.Entity:GetDriver()
  196.                        
  197.                     if Driver and Driver:IsValid() and Driver:IsPlayer() then
  198.                         local NewHealth = Driver:Health() - ( dmg * .4 )
  199.                            
  200.                         if NewHealth <= 0 then
  201.                             Driver:Kill()
  202.                         else
  203.                             Driver:SetHealth( NewHealth )
  204.                             Driver.OnEnteredHealth = NewHealth
  205.                         end
  206.                     end
  207.                 end
  208.             end
  209.         else
  210.             distanceLeft = distanceLeft - hitPosition:Distance( fireFrom )
  211.            
  212.             if distanceLeft > 0 and not traceRes.Entity or not IsValid( traceRes.Entity ) or not traceRes.Entity:IsPlayer() then
  213.                 for i = 1, self.MaxPenetration_Depth do
  214.                     if distanceLeft < ( i * 1000 ) then break else
  215.                         local testPos = hitPosition + ( trueAim * i * 5 )
  216.                        
  217.                         if util.IsInWorld( testPos ) then
  218.                             self:CSShootBullet( dmg * .75, recoil, 1, 0, testPos, aimVector, distanceLeft - ( i * 1000 ), showTracer )
  219.                             self:CSShootBullet( dmg * .75, recoil, 1, 0, testPos + ( trueAim * 5 ), aimVector * -1, -100, showTracer )
  220.                            
  221.                             break
  222.                         end
  223.                     end
  224.                 end
  225.             end
  226.         end
  227.     end
  228.  
  229.     self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )      // View model animation
  230.     self.Owner:MuzzleFlash()                                // Crappy muzzle light
  231.     self.Owner:SetAnimation( PLAYER_ATTACK1 )               // 3rd Person Animation
  232.  
  233.     if self.Owner:IsNPC() then return end
  234.  
  235.     if not showTracerOverride and CLIENT and IsFirstTimePredicted() then
  236.         local eyeang = self.Owner:EyeAngles()
  237.         eyeang.pitch = eyeang.pitch - recoil
  238.         self.Owner:SetEyeAngles( eyeang )
  239.     end
  240. end
  241.  
  242. local IRONSIGHT_TIME = 0.25
  243. function SWEP:GetViewModelPosition( pos, ang )
  244.     if not self.IronSightsPos then return pos, ang end
  245.  
  246.     local bIron = self.Weapon:GetDTBool( 0 )
  247.    
  248.     if bIron ~= self.bLastIron then
  249.         self.bLastIron = bIron
  250.         self.fIronTime = CurTime()
  251.        
  252.         if bIron then
  253.             self.SwayScale  = 0.3
  254.             self.BobScale   = 0.1
  255.         else
  256.             self.SwayScale  = 1.0
  257.             self.BobScale   = 1.0
  258.         end
  259.     end
  260.    
  261.     local fIronTime = self.fIronTime or 0
  262.    
  263.     local Right     = ang:Right()
  264.     local Up        = ang:Up()
  265.     local Forward   = ang:Forward()
  266.    
  267.     local Mul = 1.0
  268.  
  269.     if not bIron and fIronTime < CurTime() - IRONSIGHT_TIME then
  270.         if self.NormalAng then
  271.             ang = ang * 1
  272.             ang:RotateAroundAxis( ang:Right(),      self.NormalAng.x * Mul )
  273.             ang:RotateAroundAxis( ang:Up(),         self.NormalAng.y * Mul )
  274.             ang:RotateAroundAxis( ang:Forward(),    self.NormalAng.z * Mul )
  275.         end
  276.        
  277.         if self.NormalPos then
  278.             pos = pos + self.NormalPos.x * Right * Mul
  279.             pos = pos + self.NormalPos.y * Forward * Mul
  280.             pos = pos + self.NormalPos.z * Up * Mul
  281.         end
  282.    
  283.         return pos, ang
  284.     end
  285.    
  286.     if fIronTime > CurTime() - IRONSIGHT_TIME then
  287.         Mul = math.Clamp( ( CurTime() - fIronTime ) / IRONSIGHT_TIME, 0, 1 )
  288.        
  289.         if not bIron then Mul = 1 - Mul end
  290.     end
  291.  
  292.     local Offset    = self.IronSightsPos
  293.    
  294.     if self.IronSightsAng then
  295.         ang = ang * 1
  296.         ang:RotateAroundAxis( ang:Right(),      self.IronSightsAng.x * Mul )
  297.         ang:RotateAroundAxis( ang:Up(),         self.IronSightsAng.y * Mul )
  298.         ang:RotateAroundAxis( ang:Forward(),    self.IronSightsAng.z * Mul )
  299.     end
  300.    
  301.     if self.NormalAng then
  302.         ang = ang * 1
  303.         ang:RotateAroundAxis( ang:Right(),      self.NormalAng.x * ( 1 - Mul ) )
  304.         ang:RotateAroundAxis( ang:Up(),         self.NormalAng.y * ( 1 - Mul ) )
  305.         ang:RotateAroundAxis( ang:Forward(),    self.NormalAng.z * ( 1 - Mul ) )
  306.     end
  307.  
  308.     pos = pos + Offset.x * Right * Mul
  309.     pos = pos + Offset.y * Forward * Mul
  310.     pos = pos + Offset.z * Up * Mul
  311.    
  312.     if self.NormalPos then
  313.         pos = pos + self.NormalPos.x * Right * (1 - Mul)
  314.         pos = pos + self.NormalPos.y * Forward * (1 - Mul)
  315.         pos = pos + self.NormalPos.z * Up * (1 - Mul)
  316.     end
  317.  
  318.     return pos, ang
  319. end
  320.  
  321. function SWEP:DrawHUD() end
  322.  
  323. function SWEP:OnRestore()
  324.     self.NextSecondaryAttack = 0
  325.     self:SetIronsights( false )
  326. end
  327.  
  328. function SWEP:Holster()
  329.     if SERVER and self.BackHolster then
  330.         self.GunModel = ents.Create( "prop_back_gun" )
  331.         self.GunModel:SetModel( self.WorldModel )
  332.         self.GunModel:SetPos( self.Owner:GetPos() + self.Owner:GetForward() * 10 + self.Owner:GetUp() * 30 )
  333.         self.GunModel:SetAngles( self.Owner:GetAngles() + Angle( 90, 0, 0 ) )
  334.         self.GunModel:SetParent( self.Owner )
  335.         self.GunModel:Spawn()
  336.     end
  337.  
  338.     return true
  339. end
  340.  
  341. function SWEP:Deploy()
  342.     if SERVER and self.GunModel and IsValid( self.GunModel ) then self.GunModel:Remove() end
  343. end
  344.  
  345. function SWEP:OnRemove()
  346.     if SERVER and self.GunModel and IsValid( self.GunModel ) then self.GunModel:Remove() end
  347. end
  348.  
  349. function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
  350.     draw.SimpleText( self.IconLetter, "CSSelectIcons", x + wide / 2, y + tall * 0.2, Color( 255, 210, 0, 255 ), TEXT_ALIGN_CENTER )
  351. end
Advertisement
Add Comment
Please, Sign In to add comment