SWEP.PrintName = "Gas Can"
SWEP.Slot = 5
SWEP.SlotPos = 5
SWEP.DrawCrosshair = true
SWEP.Instructions = "Left click to pour gas, right click to throw a match."
SWEP.ViewModel = "models/props_junk/gascan001a.mdl"
SWEP.WorldModel = "models/props_junk/gascan001a.mdl"
SWEP.Primary.ClipSize = 400
SWEP.Primary.DefaultClip = 200
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "pistol"
SWEP.Secondary.ClipSize = 400
SWEP.Secondary.DefaultClip = 200
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "pistol"
SWEP.Fires = { }
SWEP.MaxFires = 265
SWEP.Matches = { }
SWEP.MaxMatches = 3
SWEP.Pouring = false
PrecacheParticleSystem( "fire_verysmall_01" )
PrecacheParticleSystem( "water_splash_01_surface1" )
util.PrecacheSound( "ambient/water/water_spray1.wav" )
util.PrecacheSound( "ambient/water/water_spray2.wav" )
util.PrecacheSound( "ambient/water/water_spray3.wav" )
util.PrecacheSound( "weapons/slam/throw.wav" )
if not util.IsValidModel( "models/props/de_inferno/Splinter_Damage_01.mdl" ) then
SWEP.MatchModel = Model( "models/props_debris/wood_splinters01a.mdl" )
SWEP.MatchOffset = Vector( -.012, -.163, 3.065 )
else
SWEP.MatchModel = Model( "models/props/de_inferno/Splinter_Damage_01.mdl" )
SWEP.MatchOffset = Vector( .3, 4.5, .3 )
end
SWEP.Irons = {
Normal = {
Pos = Vector( 68.67, -30, -35 ),
Ang = Vector( 3.95, 86.76, -24.98 ),
},
Pour = {
Pos = Vector( 68.67, -30, -55 ),
Ang = Vector( 3.95, 86.76, -34.98 ),
},
}
SWEP.Offset = {
Pos = {
Right = 1,
Forward = -4,
Up = 0,
},
Ang = {
Right = 0,
Forward = 0,
Up = 0,
},
Scale = Vector( .5, .5, .5 ),
}
function SWEP:Initialize( )
self:SetWeaponHoldType( "slam" )
end
function SWEP:PrimaryAttack( )
if self.Weapon:Clip1() < 1 then return end
local fire, tr
self:SetNextPrimaryFire( CurTime( ) + .05 )
if CLIENT then
return
end
tr = util.TraceLine{
start = self.Owner:GetShootPos( ),
endpos = self.Owner:GetShootPos( ) + self.Owner:GetAimVector( ) * 160,
filter = self.Owner
}
if not tr.Hit then
return
end
fire = ents.Create( "env_fire" )
fire:SetKeyValue( "health", 20 )
fire:SetKeyValue( "firesize", 36 )
fire:SetKeyValue( "fireattack", .01 )
fire:SetKeyValue( "ignitionpoint", 6 )
fire:SetKeyValue( "damagescale", 25 )
fire:Fire( "AddOutput", "OnExtinguished !self,Kill", 0 )
fire:SetKeyValue( "spawnflags", 2 + ( ValidEntity( tr.Entity ) and 16 or 0 ) + 32 + 256 )
fire:SetPos( tr.HitPos )
fire:Spawn( )
fire:SetPhysicsAttacker( self.Owner )
if ValidEntity( tr.Entity ) then
fire:SetParent( tr.Entity )
end
SafeRemoveEntity( table.remove( self.Fires, self.MaxFires ) )
table.insert( self.Fires, 1, fire )
SafeRemoveEntityDelayed( fire, 45 )
self.Owner:EmitSound( "ambient/water/water_spray" .. math.random( 3 ) .. ".wav", 50, 75 )
util.Decal( "BeerSplash", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal )
ParticleEffect( "water_splash_01_surface1", tr.HitPos, tr.HitNormal:Angle( ) )
self.Weapon:TakePrimaryAmmo( 1 )
end
function SWEP:SecondaryAttack( )
if self.Weapon:Clip2() < 1 then return end
local match, heat, att, phys, tr, particle
self.Owner:AnimRestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_ITEM_PLACE )
self:SetNextSecondaryFire( CurTime( ) + 1 )
if CLIENT then
return
end
self.Owner:EmitSound( "weapons/slam/throw.wav" )
self.Hand = self.Hand or self.Owner:LookupAttachment( "anim_attachment_lh" )
match = ents.Create( "prop_physics" )
match:SetModel( self.MatchModel )
match:SetOwner( self.Owner )
match:SetSolid( SOLID_NONE )
if self.Hand == -1 then
att = self.Owner:GetAttachment( self.Hand )
match:SetPos( att.Pos )
else
match:SetPos( self.Owner:GetShootPos( ) )
end
match:Spawn( )
heat = ents.Create( "env_firesource" )
heat:SetPos( match:GetPos( ) )
heat:SetParent( match )
heat:SetLocalPos( self.MatchOffset )
heat:SetKeyValue( "fireradius", 36 )
heat:SetKeyValue( "firedamage", 50 )
heat:Spawn( )
heat:Input( "Enable" )
phys = match:GetPhysicsObject( )
tr = util.TraceLine{
start = self.Owner:GetShootPos( ),
endpos = self.Owner:GetShootPos( ) + self.Owner:GetAimVector( ) * 512,
filter = { match, heat, self.Owner, particle },
}
SafeRemoveEntityDelayed( match, 30 )
particle = ents.Create( "info_particle_system" )
particle:SetKeyValue( "start_active", 1 )
particle:SetKeyValue( "effect_name", "fire_verysmall_01" )
particle:Spawn( )
particle:SetPos( match:GetPos( ) )
particle:SetParent( match )
particle:SetLocalPos( self.MatchOffset )
particle:Activate( )
if ValidEntity( phys ) then
phys:SetVelocity( ( tr.HitPos - match:GetPos( ) ):GetNormal( ) * 128 * phys:GetMass( ) )
end
SafeRemoveEntity( table.remove( self.Matches, self.MaxMatches ) )
table.insert( self.Matches, 1, match )
self.Weapon:TakeSecondaryAmmo( 1 )
end
function SWEP:Think( )
if CLIENT then
self.Pouring = self.Owner:KeyDown( IN_ATTACK )
end
end
function SWEPrawWorldModel( )
if not ValidEntity( self.Owner ) then
return selfrawModel( )
end
local offset, hand
self.Hand2 = self.Hand2 or self.Owner:LookupAttachment( "anim_attachment_rh" )
hand = self.Owner:GetAttachment( self.Hand2 )
if not hand then
return
end
offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up
hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )
self:SetRenderOrigin( hand.Pos + offset )
self:SetRenderAngles( hand.Ang )
self:SetModelScale( self.Offset.Scale )
selfrawModel( )
end
function SWEP:GetViewModelPosition( pos, ang )
local b, r, u, f, n, x, y, z, to, from
b = self.Pouring
if b == nil then
b = false
end
if b ~= self.LastIron then
self.BlendProgress = 0
self.LastIron = b
end
self.SwayScale = 1.0
self.BobScale = 1.0
if b then
to = self.Irons.Pour
from = self.Irons.Normal
else
to = self.Irons.Normal
from = self.Irons.Pour
end
self.BlendProgress = math.Approach( self.BlendProgress, 1, FrameTime( ) * 2 )
n = 1 - self.BlendProgress
r, u, f = ang:Right( ), ang:Up( ), ang:Forward( )
x = to.Ang.x * self.BlendProgress + from.Ang.x * n
y = to.Ang.y * self.BlendProgress + from.Ang.y * n
z = to.Ang.z * self.BlendProgress + from.Ang.z * n
ang:RotateAroundAxis( r, x )
ang:RotateAroundAxis( u, y )
ang:RotateAroundAxis( f, z )
r, u, f = ang:Right( ), ang:Up( ), ang:Forward( )
x = to.Pos.x * self.BlendProgress + from.Pos.x * n
y = to.Pos.y * self.BlendProgress + from.Pos.y * n
z = to.Pos.z * self.BlendProgress + from.Pos.z * n
pos = pos + x * r
pos = pos + y * f
pos = pos + z * u
return pos, ang
end