LambdaHidden

gmod gas mask base

Feb 21st, 2022 (edited)
2,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.55 KB | None | 0 0
  1. SWEP.Base = "weapon_bo1_gasmask"
  2.  
  3. if SERVER then
  4.     SWEP.Weight             = 1
  5.     SWEP.AutoSwitchTo       = false
  6.     SWEP.AutoSwitchFrom     = true
  7. end
  8.  
  9. if CLIENT then
  10.     SWEP.Category           = "Gas Masks" -- You can change everything in this first area.
  11.     SWEP.PrintName          = "Gas Mask"
  12.     SWEP.Author             = "Hidden"
  13.     SWEP.Contact            = "Steam, /LambdaHidden. Have a reason to talk and be nice <3."
  14.     SWEP.Instructions       = "Equip to put on/take off. Can be damaged."
  15.     SWEP.Purpose            = "Protects against hazardous gases."
  16.     SWEP.Slot               = 5
  17.     SWEP.SlotPos            = 7
  18.     SWEP.ViewModelFOV       = 62
  19.     SWEP.WepSelectIcon      = surface.GetTextureID("vgui/entities/weapon_bo1_gasmask" )
  20.     SWEP.BounceWeaponIcon   = false
  21.     SWEP.DrawWeaponInfoBox  = true
  22.     SWEP.DrawCrosshair      = false
  23.     SWEP.DrawAmmo           = true
  24.     SWEP.SwayScale          = 0
  25.     SWEP.BobScale           = 0
  26.    
  27.     function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha ) -- This function lets you use a square texture for the weapon selection menu. If you're using a rectangle, delete it.
  28.         -- Set us up the texture
  29.         surface.SetDrawColor( 255, 255, 255, alpha )
  30.         surface.SetTexture( self.WepSelectIcon )
  31.        
  32.         local size = tall/2
  33.         local halfsize = tall/4
  34.        
  35.         -- Draw that mother
  36.         surface.DrawTexturedRect( x+wide/2 - halfsize, y+halfsize, size, size )
  37.        
  38.         -- Draw weapon info box
  39.         self:PrintWeaponInfo( x + wide + 20, y + tall * 0.95, alpha )
  40.     end
  41. end
  42.  
  43. SWEP.Spawnable              = true -- Makes the mask appear in the spawn menu.
  44. SWEP.AdminOnly              = false -- Restricts the weapon to only be spawnable by admins.
  45. SWEP.ViewModel              = "models/weapons/black_ops_1/c_gasmask.mdl" -- The first person view model. Needs to have ACT_VM_DRAW, ACT_VM_HOLSTER and ACT_VM_IDLE.
  46. SWEP.WorldModel             = "models/weapons/black_ops_1/w_gasmask.mdl" -- This is the model that will be drawn on the player's head.
  47. SWEP.UseHands               = true -- If your viewmodel supports it, set this to "true" to use your playermodel's hands in first person view.
  48.  
  49. SWEP.BreathSound            = "Weapon_BO1_GasMask.Breath" -- Breathing sound effect. Will loop as long as the mask is on.
  50. SWEP.BreathSoundMedium      = nil -- This sound will replace the one above when the filter is half expired. Delete this line if you don't want it.
  51. SWEP.BreathSoundLow         = nil -- This sound will replace the one above when the filter is 3/4 expired. Delete this line if you don't want it.
  52. SWEP.ScreenOverlay          = "black_ops_1/screenoverlays/hazmatmask_00" -- Visor image that goes over your screen. If you have textures for damage, give them all the same name with a number in the end (higher means more damage).
  53. SWEP.DamageTypes            = bit.bor(DMG_POISON, DMG_ACID, DMG_NERVEGAS, DMG_RADIATION, DMG_DROWN) -- These are what the mask will protect against. Change this to suit yours. Full list here: https://wiki.facepunch.com/gmod/Enums/DMG
  54. SWEP.FilterWarnSound        = "" -- This sound plays when your filter is close to running out.
  55.  
  56. SWEP.Primary.Ammo           = "none" -- Changing this to "filter" gives you the ability to change filters. If you don't want that, keep this as "none".
  57. SWEP.Primary.DefaultClip    = -1 -- The amount of filters you get when you pick the mask up. -1 disables this entirely.
  58.  
  59. SWEP.FilterDurability       = 0 -- Amount of chemical damage this mask's filter can take before expiring. Set to 0 for infinite.
  60. SWEP.Integrity              = 50 -- Mask's health. Set to 0 for unbreakable.
  61. SWEP.IntegrityTextures      = 4 -- As your mask takes damage, the screen overlay texture changes. This is the amount of textures it'll go through.
  62. SWEP.IntegritySkins         = 0 -- Same as above, but for the model's skins.
  63.  
  64.  
  65. SWEP.NZHudIcon = Material("vgui/entities/weapon_bo1_gasmask") -- nZombies Rezzurrection HUD icons.
  66. SWEP.NZHudIcon_t7 = Material("vgui/entities/weapon_bo1_gasmask")
  67. SWEP.NZHudIcon_t7zod = Material("vgui/entities/weapon_bo1_gasmask")
  68. SWEP.NZHudIcon_t7tomb = Material("vgui/entities/weapon_bo1_gasmask")
  69.  
  70. --[[
  71. VIEWMODEL ACT LIST, FOR YOUR QC
  72.  
  73. ACT_VM_IDLE             - idle, mask off
  74. ACT_VM_IDLE_DEPLOYED    - idle, mask on
  75. ACT_VM_DRAW             - put on
  76. ACT_VM_HOLSTER          - take off
  77. ACT_VM_RELOAD           - change filters, mask off
  78. ACT_VM_RELOAD_DEPLOYED  - change filters, mask on
  79. ]]
  80.  
  81.  
  82.  
  83. -- FROM THIS POINT ON, DON'T CHANGE ANYTHING UNLESS YOU REALLY KNOW WHAT YOU'RE DOING. This is here just so you understand what's going on under the hood.
  84.  
  85. if JMod then
  86.     JMod.AdditionalArmorTable = JMod.AdditionalArmorTable or {}
  87.  
  88.     JMod.AdditionalArmorTable["gasmask_rebirth"] = {
  89.         PrintName = "\"Rebirth\" gas mask",
  90.         mdl = "models/weapons/black_ops_1/w_gasmask.mdl",
  91.         slots = {
  92.             eyes = 1,
  93.             mouthnose = 1
  94.         },
  95.         def = {
  96.             [DMG_NERVEGAS] = 1,
  97.             [DMG_RADIATION] = .75
  98.         },
  99.         dur = 50,
  100.         chrg = {
  101.             chemicals = SWEP.FilterDurability > 0 and SWEP.FilterDurability/20 or 2147483640
  102.         },
  103.         bon = "",
  104.         siz = Vector(1, 1, 1),
  105.         pos = Vector(0, .1, 0),
  106.         ang = Angle(100, 180, 90),
  107.         wgt = 5,
  108.         mskmat = "",
  109.         sndlop = "",
  110.         ent = "weapon_bo1_gasmask",
  111.         tgl = {
  112.             pos = Vector(3, 3, 0),
  113.             ang = Angle(190, 180, 90),
  114.             eff = {},
  115.             mskmat = "",
  116.             sndlop = "",
  117.             def = NonArmorProtectionProfile,
  118.             slots = {
  119.                 eyes = 0,
  120.                 mouthnose = 0
  121.             }
  122.         }
  123.     }
  124. end
  125.  
  126. local BA2 = file.IsDir( "ba2", "LUA" )
  127. local filterName = BA2 and "BA2_GasmaskFilterPct" or "GasMaskFilter"
  128.  
  129. game.AddAmmoType({
  130.     name = "filter",
  131.     force = 0
  132. })
  133.  
  134. if SERVER then
  135.     util.AddNetworkString("DrawGasMaskWM")
  136. end
  137.  
  138. CreateConVar( "cl_gasmask_drawthirdperson", "1", bit.bor(FCVAR_ARCHIVE, FCVAR_USERINFO), "Determines if the gas mask model should be drawn on your head or not.", 0, 1 )
  139. CreateConVar( "cl_gasmask_preventswapiffresh", "1", bit.bor(FCVAR_ARCHIVE, FCVAR_USERINFO), "Prevent accidentally swapping filters if the one you have on is still fresh.", 0, 1 )
  140. CreateConVar( "cl_gasmask_filterwarning", "1", bit.bor(FCVAR_ARCHIVE, FCVAR_USERINFO), "Display a warning when the filter is close to running out.", 0, 1 )
  141.  
  142.  
  143. SWEP.NZPreventBox = true -- nZombies support.
  144. SWEP.NZSpecialCategory = "shield"
  145. SWEP.NZSpecialWeaponData = {MaxAmmo = 0, AmmoType = "none"}
  146.  
  147. SWEP.Primary.Automatic      = false
  148. SWEP.Primary.ClipSize       = -1
  149.  
  150. SWEP.Secondary.ClipSize     = -1
  151. SWEP.Secondary.DefaultClip  = -1
  152. SWEP.Secondary.Automatic    = false
  153. SWEP.Secondary.Ammo         = "none"
  154.  
  155. function SWEP:SetupDataTables()
  156.     self:NetworkVar("Float", 0, "RemainingFilter")
  157.     self:NetworkVar("Int", 0, "Integrity")
  158.     self:NetworkVar("Bool", 0, "Reloading")
  159.     self:NetworkVar("Int", 1, "BreathSoundActual")
  160.    
  161.     self:NetworkVarNotify("Integrity", self.UpdateWorldModelDamage)
  162.     self:NetworkVarNotify("RemainingFilter", self.OnFiltering)
  163. end
  164.  
  165. function SWEP:Initialize()
  166.     self:SetHoldType( "normal" )
  167.     self.ActionDelay = CurTime()
  168.     self:SetRemainingFilter(self.FilterDurability)
  169.     self:SetIntegrity(self.Integrity)
  170.     self:SetBreathSoundActual(-1)
  171. end
  172.  
  173. function SWEP:EquipAmmo(newown)
  174.     local wep = newown:GetWeapon(self:GetClass())
  175.    
  176.     --wep:SetIntegrity(math.max(self:GetIntegrity(), wep:GetIntegrity()))
  177.     wep:SetIntegrity(math.max(self:GetIntegrity(), newown:GetNWInt( "GasMaskHealth", wep:GetIntegrity() )))
  178.     newown:SetNWInt( "GasMaskHealth", wep:GetIntegrity() )
  179.    
  180.     if SERVER and self.IntegritySkins > 0 and newown:GetNWEntity("GasMaskOnFace") == wep then
  181.         net.Start("DrawGasMaskWM")
  182.             net.WriteEntity(newown)
  183.             net.WriteString("update")
  184.             net.WriteUInt(math.Remap(wep:GetIntegrity(), self.Integrity, 0, 0, self.IntegritySkins - 1), 8)
  185.         net.Broadcast()
  186.     end
  187.     --self:TakePrimaryAmmo(1)
  188. end
  189.  
  190. function SWEP:SwitchToLastWep()
  191.     local own = self:GetOwner()
  192.     if CLIENT then
  193.         local prevswep = own:GetPreviousWeapon()
  194.         if prevswep:IsWeapon() and prevswep:IsValid() then
  195.             input.SelectWeapon( prevswep )
  196.         else
  197.             local weps = own:GetWeapons()
  198.             input.SelectWeapon( weps[math.random(1, #weps)] )
  199.         end
  200.     end
  201. end
  202.  
  203. function SWEP:Deploy()
  204.     local own = self:GetOwner()
  205.    
  206.     local maskOnFace = own:GetNWEntity("GasMaskOnFace")
  207.     local maskIsOn = own:GetNWBool("GasMaskIsOn")
  208.    
  209.     if self.Primary.Ammo == "none" and IsValid(maskOnFace) and maskOnFace != self then
  210.         self:SendWeaponAnim(ACT_VM_IDLE)
  211.         timer.Simple(0.1, function()
  212.             own:PrintMessage( HUD_PRINTCENTER, "Take your current mask off first" )
  213.             --own:ConCommand( "lastinv" )
  214.             self:CallOnClient("SwitchToLastWep")
  215.             --own:SelectWeapon(maskOnFace:GetClass())
  216.         end)
  217.         return true
  218.     end
  219.    
  220.     self:SendWeaponAnim( maskIsOn and ACT_VM_IDLE_DEPLOYED or ACT_VM_IDLE ) -- This is so viewmodel anims work correctly.
  221.    
  222.     if self.Primary.Ammo == "none" then -- If this mask's filter can't expire, all you can do is put it on or take it off. Do that right away.
  223.         if maskIsOn then
  224.             self:TakeOff()
  225.         else
  226.             self:PutOn()
  227.         end
  228.     end
  229.    
  230.     if BA2 then
  231.         own:SetAmmo(own:GetNWInt("BA2_GasmaskFilters"), "filter")
  232.     end
  233.    
  234.     return true
  235. end
  236.  
  237. function SWEP:PutOn()
  238.     local own = self:GetOwner()
  239.    
  240.     -- FIRSTPERSON STUFF
  241.     self:SendWeaponAnim(ACT_VM_DRAW) -- Play viewmodel animation for putting the mask on.
  242.     self.ActionDelay = CurTime() + self:SequenceDuration()
  243.  
  244.     timer.Simple( self:SequenceDuration() + 0.1, function()
  245.         if !IsValid(self) then return end
  246.        
  247.         --own:ConCommand( "pp_mat_overlay "..(self.ScreenOverlay) )
  248.         own:SetNWString("GasMaskOverlay", self.ScreenOverlay) -- Draw screen overlay.
  249.        
  250.         if table.Count(own:GetWeapons()) != 1 and self.Primary.Ammo == "none" then -- If there's more to do with the mask than just putting it on, don't swap to another weapon.
  251.             --own:ConCommand( "lastinv" )
  252.             self:CallOnClient("SwitchToLastWep")
  253.             if engine.ActiveGamemode() == "nzombies" and SERVER then -- Switch to last weapon.
  254.                 own:EquipPreviousWeapon()
  255.                 own:SetUsingSpecialWeapon(false)
  256.             end
  257.         end
  258.     end )
  259.    
  260.     if !IsValid(self) then return end
  261.     timer.Simple( self:SequenceDuration() + 0.1, function()
  262.         if !IsValid(self) then return end
  263.         if SERVER then -- The sound plays twice in third person if I don't do this check.
  264.             if !BA2 then
  265.                 --own:EmitSound(self.BreathSound)
  266.                 --self.BreathSoundActual = own:StartLoopingSound(self.BreathSound)
  267.                 self:SetBreathSoundActual(own:StartLoopingSound(self.BreathSound))
  268.             end -- Start breathing sound.
  269.         end
  270.     end )
  271.    
  272.     -- THIRDPERSON STUFF
  273.     self:SetHoldType( "normal" ) -- No good anim for putting on a mask, so instead we play with holdtypes.
  274.     timer.Simple(self:SequenceDuration()*0.25, function()
  275.         if !IsValid(self) then return end
  276.         self:SetHoldType( "melee2" )
  277.     end)
  278.     timer.Simple(self:SequenceDuration()*0.4, function()
  279.         if !IsValid(self) then return end
  280.         self:SetHoldType( "camera" )
  281.         if own:GetInfoNum("cl_gasmask_drawthirdperson", 1) > 0 then
  282.        
  283.             net.Start("DrawGasMaskWM")
  284.                 net.WriteEntity(own)
  285.                 net.WriteString(self.WorldModel)
  286.                 net.WriteUInt(self.IntegritySkins > 0 and math.Remap(self:GetIntegrity(), self.Integrity, 0, 0, self.IntegritySkins - 1) or 0, 8)
  287.             if SERVER then
  288.                 net.Broadcast()
  289.             else
  290.                 net.SendToServer()
  291.             end
  292.            
  293.         end
  294.        
  295.         if SERVER then
  296.             own:SetNWInt("GasMaskDamageTypes", self.DamageTypes) -- Add protective effects.
  297.             if self.FilterDurability > 0 then
  298.                 if self:GetRemainingFilter() > 0 then
  299.                     own:SetNWInt(filterName, self:GetRemainingFilter())
  300.                     if JMod then
  301.                         for k, v in pairs(own.EZarmor.items) do
  302.                             if v.name == "gasmask_rebirth" then
  303.                                 v.chrg.chemicals = self:GetRemainingFilter()/20
  304.                                 break
  305.                             end
  306.                         end
  307.                     end
  308.                     own.gasmasked = true -- GBombs 5 compatibility, doubles up as a variable for checking if the filter works.
  309.                 end
  310.             else
  311.                 own:SetNWInt(filterName, BA2 and 2147483000 or -1)
  312.                 own.gasmasked = true
  313.             end
  314.            
  315.             own:SetNWBool("GasMaskIsOn", true)
  316.             if BA2 then
  317.                 print("Bio-Annihilation 2 is installed, adapting gas masks...")
  318.                 own:SetNWBool("BA2_GasmaskOn", true)
  319.             end
  320.             own:SetNWEntity("GasMaskOnFace", self)
  321.             own:SetNWBool("GasMaskCanBreak", self.Integrity > 0)
  322.             own:SetNWInt("GasMaskHealth", self:GetIntegrity())
  323.             own:SetNWInt("GasMaskMaxHealth", self.Integrity)
  324.             own:SetNWInt("GasMaskHealthTextures", self.IntegrityTextures)
  325.             own:SetNWInt("GasMaskHealthSkins", self.IntegritySkins)
  326.            
  327.             if JMod then JMod.EZ_Equip_Armor(own, "gasmask_rebirth") end -- JMod support.
  328.         end
  329.     end)
  330.     timer.Simple( self:SequenceDuration()*0.75, function()
  331.         if !IsValid(self) then return end
  332.         --own:SetDSP(30, false )
  333.         self:SetHoldType( "normal" )
  334.     end )
  335. end
  336. function SWEP:TakeOff()
  337.     local own = self:GetOwner()
  338.    
  339.     self:SetHoldType( "camera" )
  340.     self:SendWeaponAnim(ACT_VM_HOLSTER) -- Play viewmodel animation for taking the mask off.
  341.     timer.Simple(0.2, function()
  342.         if !IsValid(self) then return end
  343.         self:SetHoldType( "melee2" )
  344.         own:SetNWInt("GasMaskDamageTypes", 0) -- Remove protective effects.
  345.         self:SetIntegrity(own:GetNWInt("GasMaskHealth"))
  346.        
  347.         net.Start("DrawGasMaskWM")
  348.             net.WriteEntity(own)
  349.             net.WriteString("")
  350.             net.WriteUInt(0, 8)
  351.         if SERVER then
  352.             net.Broadcast()
  353.         else
  354.             net.SendToServer()
  355.         end
  356.        
  357.     end)
  358.     timer.Simple(0.4, function()
  359.         if !IsValid(self) then return end
  360.         self:SetHoldType( "normal" )
  361.     end)
  362.     self.ActionDelay = CurTime() + self:SequenceDuration()
  363.     own:SetNWString("GasMaskOverlay", "") -- Remove screen overlay.
  364.     if SERVER then
  365.         timer.Simple( self.ActionDelay - CurTime(), function()
  366.             if !IsValid(self) or own:GetActiveWeapon() != self then return end
  367.            
  368.             --[[if timer.Exists("GasMaskFilterTime"..own:EntIndex()) then
  369.                 print( "takeoff", timer.TimeLeft("GasMaskFilterTime"..own:EntIndex()) )
  370.                 self:SetRemainingFilter(timer.TimeLeft("GasMaskFilterTime"..own:EntIndex()))
  371.                 timer.Remove("GasMaskFilterTime"..own:EntIndex())
  372.             end]]
  373.             self:SetRemainingFilter( own:GetNWInt(filterName) )
  374.            
  375.             if table.Count(own:GetWeapons()) != 1 and self.Primary.Ammo == "none" then
  376.                 --own:ConCommand( "lastinv" )
  377.                 self:CallOnClient("SwitchToLastWep")
  378.                 if engine.ActiveGamemode() == "nzombies" then -- Switch to last weapon.
  379.                     own:EquipPreviousWeapon()
  380.                     own:SetUsingSpecialWeapon(false)
  381.                 end
  382.             end
  383.         end )
  384.     end
  385.     own:SetNWBool( "GasMaskIsOn", false )
  386.     if BA2 then own:SetNWBool("BA2_GasmaskOn", false) end
  387.     own:SetNWEntity("GasMaskOnFace", NULL)
  388.     if JMod and SERVER then
  389.         for k, v in pairs(own.EZarmor.items) do
  390.             if v.name == "gasmask_rebirth" then
  391.                 JMod.RemoveArmorByID(own, k)
  392.                 break
  393.             end
  394.         end
  395.     end
  396.     own.gasmasked = false
  397.     --own:StopSound(self.BreathSound)
  398.     --own:StopLoopingSound(self.BreathSoundActual)
  399.     own:StopLoopingSound(self:GetBreathSoundActual())
  400.     self:SetBreathSoundActual(-1)
  401.     if BA2 then BA2_GasmaskSound(own) end
  402.     --own:SetDSP(0, false )
  403. end
  404.  
  405. function SWEP:FireAnimationEvent(pos, ang, event, options) -- Animation events in the viewmodel toggle the sound muffling.
  406.     local own = self:GetOwner()
  407.     if event == 9001 then
  408.         own:SetDSP(30, false )
  409.     elseif event == 9011 then
  410.         own:SetDSP(0, false )
  411.     end
  412. end
  413.  
  414. function SWEP:Holster(wep)
  415.     if self.ActionDelay > CurTime() then
  416.         return false
  417.     end
  418.     return true
  419. end
  420.  
  421. function SWEP:NZSpecialHolster(wep)
  422.     return true
  423. end
  424.  
  425.  
  426. function SWEP:PrimaryAttack()
  427.     if self:GetNextPrimaryFire() > CurTime() then return end -- Prevent overlapping actions.
  428.     if self.Primary.Ammo != "none" or table.Count(self.Owner:GetWeapons()) == 1 then
  429.         local maskIsOn = self.Owner:GetNWBool("GasMaskIsOn")
  430.         if maskIsOn then
  431.             if self.Owner:GetNWEntity("GasMaskOnFace") != self then
  432.                 self.Owner:PrintMessage( HUD_PRINTCENTER, "Take your current mask off first" )
  433.                 self:SetNextPrimaryFire(CurTime() + 1)
  434.                 return
  435.             end
  436.             self:TakeOff()
  437.         else
  438.             self:PutOn()
  439.         end
  440.         self:SetNextPrimaryFire(CurTime() + self:SequenceDuration() + 0.1)
  441.     end
  442. end
  443.  
  444. function SWEP:SecondaryAttack()
  445.     return false
  446. end
  447.  
  448. function SWEP:Reload()
  449.     if self:GetReloading() or self:Ammo1() <= 0 then return end
  450.     local own = self:GetOwner()
  451.    
  452.     if own:GetInfoNum("cl_gasmask_preventswapiffresh", 0) > 0 and self:GetRemainingFilter() > self.FilterDurability/4 then
  453.         own:PrintMessage( HUD_PRINTCENTER, "The filter is still fresh" )
  454.         return
  455.     end
  456.    
  457.     local maskOnFace = own:GetNWEntity("GasMaskOnFace")
  458.     local act = ACT_VM_RELOAD
  459.     if maskOnFace == self then
  460.         act = ACT_VM_RELOAD_DEPLOYED
  461.        
  462.         own:SetNWInt(filterName, self.FilterDurability)
  463.         if JMod then
  464.             for k, v in pairs(own.EZarmor.items) do
  465.                 if v.name == "gasmask_rebirth" then
  466.                     v.chrg.chemicals = self.FilterDurability/20
  467.                     break
  468.                 end
  469.             end
  470.         end
  471.         own.gasmasked = true -- GBombs 5 compatibility.
  472.     end
  473.    
  474.     own:StopLoopingSound(self:GetBreathSoundActual())
  475.     self:SetBreathSoundActual(-1)
  476.     if BA2 then BA2_GasmaskSound(own) end
  477.    
  478.     self:SendWeaponAnim(act)
  479.     self:SetReloading(true)
  480.     self.ActionDelay = CurTime() + self:SequenceDuration()
  481.    
  482.     self:TakePrimaryAmmo(1)
  483.     if BA2 then
  484.         own:SetNWInt("BA2_GasmaskFilters", own:GetAmmoCount("filter"))
  485.     end
  486.     self:SetRemainingFilter(self.FilterDurability)
  487.    
  488.     timer.Create("GasMaskChangeFilter"..own:EntIndex(), self:SequenceDuration()+0.1, 1, function()
  489.         if !IsValid(self) or !IsValid(own) or own:GetActiveWeapon() !=self then return end
  490.         self:SetReloading(false)
  491.         if maskIsOn then
  492.             if BA2 then
  493.                 BA2_GasmaskSound(own, "ba2/gasmask/mask_breathe_light.wav")
  494.             else
  495.                 --own:EmitSound(self.BreathSound)
  496.                 --self.BreathSoundActual = own:StartLoopingSound(self.BreathSound)
  497.                 if SERVER then self:SetBreathSoundActual(own:StartLoopingSound(self.BreathSound)) end
  498.             end
  499.         end
  500.     end)
  501. end
  502.  
  503. SWEP.BreathingDifficulty = 0
  504. function SWEP:OnFiltering(name, old, new)
  505.     if new == self.FilterDurability then
  506.         self.FilterWarningGiven = false
  507.         self.BreathingDifficulty = 0
  508.     end
  509.    
  510.     if new <= self.FilterDurability/2 and self.BreathingDifficulty == 0 and self.BreathSoundMedium != nil and SERVER then
  511.         self.BreathingDifficulty = 1
  512.         ---self:StopLoopingSound(self.BreathSoundActual)
  513.         self:StopLoopingSound(self:GetBreathSoundActual())
  514.         --self.BreathSoundActual = self:StartLoopingSound(self.BreathSoundMedium)
  515.         self:SetBreathSoundActual(self:StartLoopingSound(self.BreathSoundMedium))
  516.     end
  517.    
  518.     local own = self:GetOwner()
  519.  
  520.     if new <= self.FilterDurability/4 then
  521.         if IsValid(own) and own:GetInfoNum("cl_gasmask_filterwarning", 1) and !self.FilterWarningGiven then
  522.             self.FilterWarningGiven = true
  523.             if self.BreathSoundLow != nil and SERVER then
  524.                 self.BreathingDifficulty = 2
  525.                 --self:StopLoopingSound(self.BreathSoundActual)
  526.                 self:StopLoopingSound(self:GetBreathSoundActual())
  527.                 --self.BreathSoundActual = self:StartLoopingSound(self.BreathSoundLow)
  528.                 self:SetBreathSoundActual(self:StartLoopingSound(self.BreathSoundLow))
  529.             end
  530.             --own:PrintMessage( HUD_PRINTCENTER, "Filter low" )
  531.             if CLIENT then
  532.                 if self.FilterWarnSound then surface.PlaySound(self.FilterWarnSound) end
  533.                 notification.AddLegacy( "Filter low", NOTIFY_HINT, 4 )
  534.             end
  535.         end
  536.     end
  537. end
  538.  
  539. function SWEP:OnRemove()
  540.     local own = self.OwnerHack
  541.     if IsValid(own) then
  542.         timer.Remove("GasMaskChangeFilter"..own:EntIndex())
  543.         own:SetNWBool( "GasMaskIsOn", false )
  544.         if BA2 then own:SetNWBool("BA2_GasmaskOn", false) end
  545.         own:SetNWEntity("GasMaskOnFace", NULL)
  546.         own:SetNWInt(filterName, 0)
  547.         own.gasmasked = false
  548.        
  549.         net.Start("DrawGasMaskWM")
  550.             net.WriteEntity(own)
  551.             net.WriteString("")
  552.             net.WriteUInt(0, 8)
  553.         if SERVER then
  554.             net.Broadcast()
  555.         else
  556.             net.SendToServer()
  557.         end
  558.        
  559.         --own:StopSound(self.BreathSound)
  560.         --own:StopLoopingSound(self.BreathSoundActual)
  561.         own:StopLoopingSound(self:GetBreathSoundActual())
  562.         self:SetBreathSoundActual(-1)
  563.         if BA2 then BA2_GasmaskSound(own) end
  564.         --own:ConCommand( "pp_mat_overlay ()" )
  565.         own:SetNWInt("GasMaskDamageTypes", 0)
  566.         own:SetNWString("GasMaskOverlay", "")
  567.         own:SetDSP(0, false )
  568.     end
  569. end
  570.  
  571. function SWEP:OwnerChanged()
  572.     if !IsValid(self:GetOwner()) then
  573.         if !IsValid(self.OwnerHack) then return end
  574.        
  575.         timer.Remove("GasMaskChangeFilter"..self.OwnerHack:EntIndex())
  576.        
  577.         if self.OwnerHack:GetNWBool("GasMaskIsOn") then
  578.             --[[if timer.Exists("GasMaskFilterTime"..self.OwnerHack:EntIndex()) then
  579.                 --print( "ownerchanged", timer.TimeLeft("GasMaskFilterTime"..self.OwnerHack:EntIndex()) )
  580.                 self:SetRemainingFilter(timer.TimeLeft("GasMaskFilterTime"..self.OwnerHack:EntIndex()))
  581.                 timer.Remove("GasMaskFilterTime"..self.OwnerHack:EntIndex())
  582.             end]]
  583.            
  584.             self:SetRemainingFilter( self.OwnerHack:GetNWInt(filterName) )
  585.             self:SetIntegrity(self.OwnerHack:GetNWInt("GasMaskHealth"))
  586.         end
  587.         self:OnRemove()
  588.     else
  589.         self.OwnerHack = self:GetOwner()
  590.     end
  591. end
  592.  
  593. function SWEP:UpdateWorldModelDamage(name, old, new)
  594.     if self.IntegritySkins > 0 then
  595.         self:SetSkin( math.Remap(new, self.Integrity, 0, 0, self.IntegritySkins - 1) )
  596.     end
  597.     local own = self:GetOwner()
  598.    
  599.     if IsValid(own) and IsValid(own.GasMask) then
  600.         own.GasMask:SetSkin(self:GetSkin())
  601.     end
  602. end
  603.  
  604. function SWEP:DrawWorldModel( flags )
  605.     if !IsValid(self:GetOwner()) then
  606.         self:DrawModel(flags)
  607.     end
  608. end
Add Comment
Please, Sign In to add comment