Advertisement
cmddy

flashbang arccw

Aug 11th, 2021
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. ENT.Type = "anim"
  2. ENT.Base = "base_entity"
  3. ENT.PrintName = "Flash Grenade"
  4. ENT.Author = ""
  5. ENT.Information = ""
  6. ENT.Spawnable = false
  7. ENT.AdminSpawnable = false
  8.  
  9. ENT.Model = "models/weapons/arccw_go/w_eq_flashbang_thrown.mdl"
  10. ENT.FuseTime = 2.5
  11. ENT.ArmTime = 0
  12. ENT.ImpactFuse = false
  13. ENT.Armed = true
  14.  
  15. AddCSLuaFile()
  16.  
  17. function ENT:Initialize()
  18.     if SERVER then
  19.         self:SetModel( self.Model )
  20.         self:SetMoveType( MOVETYPE_VPHYSICS )
  21.         self:SetSolid( SOLID_VPHYSICS )
  22.         self:PhysicsInit( SOLID_VPHYSICS )
  23.         self:DrawShadow( true )
  24.  
  25.         local phys = self:GetPhysicsObject()
  26.         if phys:IsValid() then
  27.             phys:Wake()
  28.             phys:SetBuoyancyRatio(0)
  29.         end
  30.  
  31.         self.SpawnTime = CurTime()
  32.  
  33.         if self.FuseTime <= 0 then
  34.             self:Detonate()
  35.         end
  36.  
  37.         timer.Simple(0, function()
  38.             if !IsValid(self) then return end
  39.             self:SetCollisionGroup(COLLISION_GROUP_PROJECTILE)
  40.         end)
  41.     end
  42. end
  43.  
  44. function ENT:PhysicsCollide(data, physobj)
  45.     if SERVER then
  46.         if data.Speed > 75 then
  47.             self:EmitSound(Sound("physics/metal/metal_grenade_impact_hard" .. math.random(1,3) .. ".wav"))
  48.         elseif data.Speed > 25 then
  49.             self:EmitSound(Sound("physics/metal/metal_grenade_impact_soft" .. math.random(1,3) .. ".wav"))
  50.         end
  51.  
  52.         if (CurTime() - self.SpawnTime >= self.ArmTime) and self.ImpactFuse then
  53.             self:Detonate()
  54.         end
  55.     end
  56. end
  57.  
  58. function ENT:Think()
  59.     if SERVER and CurTime() - self.SpawnTime >= self.FuseTime then
  60.         self:Detonate()
  61.     end
  62. end
  63.  
  64. function ENT:FlashBang()
  65.     if !self:IsValid() then return end
  66.     self:EmitSound("arccw_go/flashbang/flashbang_explode1.wav", 100, 100, 1, CHAN_ITEM)
  67.     self:EmitSound("arccw_go/flashbang/flashbang_explode1_distant.wav", 140, 100, 1, CHAN_WEAPON)
  68.  
  69.     local attacker = self
  70.  
  71.     if self:GetOwner():IsValid() then
  72.         attacker = self:GetOwner()
  73.     end
  74.  
  75.     util.BlastDamage(self, attacker, self:GetPos(), 64, 10)
  76.  
  77.     local effectdata = EffectData()
  78.     effectdata:SetOrigin( self:GetPos() )
  79.  
  80.     util.Effect( "arccw_flashexplosion", effectdata)
  81.  
  82.     local flashorigin = self:GetPos()
  83.  
  84.     local flashpower = 1024
  85.     local targets = ents.FindInSphere(flashorigin, flashpower)
  86.  
  87.     for _, k in pairs(targets) do
  88.         if k:IsPlayer() then
  89.             local dist = k:EyePos():Distance(flashorigin)
  90.             local dp = (k:EyePos() - flashorigin):Dot(k:EyeAngles():Forward())
  91.  
  92.             local time = Lerp( dp, 2.5, 0.25 )
  93.  
  94.             time = Lerp( dist / flashpower, time, 0 )
  95.  
  96.             if k:VisibleVec( flashorigin ) then
  97.                 k:ScreenFade( SCREENFADE.IN, Color( 255, 255, 255, 255 ), 2.5, time )
  98.             end
  99.  
  100.             k:SetDSP( 37, false )
  101.  
  102.         elseif k:IsNPC() then
  103.  
  104.             k:SetNPCState(NPC_STATE_PLAYDEAD)
  105.  
  106.             if timer.Exists( k:EntIndex() .. "_arccw_flashtimer" ) then
  107.                 timer.Remove( k:EntIndex() .. "_arccw_flashtimer" )
  108.             end
  109.  
  110.             timer.Create( k:EntIndex() .. "_arccw_flashtimer", 10, 1, function()
  111.                 if !k:IsValid() then return end
  112.                 k:SetNPCState(NPC_STATE_ALERT)
  113.             end)
  114.  
  115.         end
  116.     end
  117. end
  118.  
  119. function ENT:Detonate()
  120.     if !self:IsValid() or self:WaterLevel() > 2 then return end
  121.     if !self.Armed then return end
  122.  
  123.     self.Armed = false
  124.  
  125.     self:FlashBang()
  126.  
  127.     self:Remove()
  128. end
  129.  
  130. function ENT:DrawTranslucent()
  131.     self:Draw()
  132. end
  133.  
  134. function ENT:Draw()
  135.     self:DrawModel()
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement