HL2 Weapon Functions

How do I make a weapon have the HL2 Weapon functions? Like if I wanted one gun to have the Combine Ball Launcher or one gun to have the Grenade Launcher or another to have the 2 round shotgun burst? I would I make that?

No easy way; I remember someone working to recreate the HL2 weapons in Lua.

Really? Ugh.

However, some of the projectiles from the weapons are actually point entities, so maybe you can replicate those functions via ent:create or something.

I found this addon: http://steamcommunity.com/sharedfiles/filedetails/?id=271434382&searchtext=HL2+Weapons

It seems to be fine for all the HL2 Weapons, EXCEPT the AR2, as the Combine Energy Ball Projectile moves at 2x the speed of light it seems.


function SWEP:DelayedAttack()

--- COPIRIGHT ME

	self.m_bShotDelayed = false

	if ( !IsValid( self.Owner ) ) then return end

	// Deplete the clip completely
	self:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
	//m_flNextSecondaryAttack = self.Owner->m_flNextAttack = CurTime() + SequenceDuration();

	// Register a muzzleflash for the AI
	self.Owner:MuzzleFlash();

	self:PlaySound( self.Secondary.Sound2 );
	//WeaponSound( WPN_DOUBLE );

	local MAX_TRACE_LENGTH = 16368

	// Fire the bullets
	local vecSrc	 = self.Owner:GetShootPos()//Weapon_ShootPosition( );
	local vecAiming = self.Owner:GetAimVector()//GetAutoaimVector( AUTOAIM_2DEGREES );
	local impactPoint = vecSrc + ( vecAiming * MAX_TRACE_LENGTH );

	// Fire the bullets
	local vecVelocity = vecAiming * 1000

	if ( SERVER ) then
		local pBall = ents.Create( "prop_combine_ball" )
		pBall:EmitSound( "NPC_CombineBall.Launch" )

		//pBall:StartWhizSoundThink()
		//pBall:StartLifetime( 4 )

		pBall:PhysicsInit( SOLID_VPHYSICS )
		pBall:SetSolid( SOLID_VPHYSICS)
		pBall:SetMoveType( MOVETYPE_VPHYSICS )
		pBall:SetCollisionGroup( 24 )
		pBall:SetPos( self.Owner:GetShootPos() )
		pBall:SetOwner( self.Owner )
		pBall:SetAbsVelocity( vecVelocity ) // pBall:SetVelocity( vecVelocity )
		pBall:SetSaveValue( "m_flRadius", 10 ) // pBall:SetRadius( 10 )
		pBall:SetSaveValue( "m_vecAbsVelocity", vecVelocity )
		pBall:Spawn()

		pBall:SetSaveValue( "m_bWeaponLaunched", true ) //pBall:SetWeaponLaunched( true )
		pBall:SetSaveValue( "m_flSpeed", vecVelocity:Length() ) // pBall:SetSpeed( vecVelocity.Length() )
		pBall:SetSaveValue( "m_bLaunched", true )
		pBall:SetSaveValue( "m_nState", 2 ) // pBall:SetState( "CPropCombineBall::STATE_THROWN" )

		local phys = pBall:GetPhysicsObject()
		if IsValid( phys ) then
			phys:AddGameFlag( FVPHYSICS_WAS_THROWN ) // PhysSetGameFlags( pBall->VPhysicsGetObject(), FVPHYSICS_WAS_THROWN )
			phys:SetMass( 150 ) // pBall:GetPhysicsObject():SetMass( 150 )
			phys:SetInertia( Vector( 500, 500, 500 ) )
		end

		// Uuuuuugly workaround
		timer.Simple( 4, function() if IsValid( pBall ) then pBall:Fire("Explode") end end )

		self.Owner:ScreenFade( SCREENFADE.IN, Color( 255, 255, 255, 64 ), 0.1, 0 )

		//Disorient the player
		local angles = self.Owner:EyeAngles()

		angles.p = angles.p + math.random( -4, 4 )
		angles.y = angles.y + math.random( -4, 4 )
		angles.r = 0;

		self.Owner:SetEyeAngles( angles )
	end
	self.Owner:ViewPunch( Angle( /*SharedRandomInt( "ar2pax",*/math.random( -8, -12 ), /*SharedRandomInt( "ar2pay", */math.random(1, 2 ), 0 ) );

	// Decrease ammo
	self.Owner:RemoveAmmo( 1, self.Secondary.Ammo )

	// Can shoot again immediately
	self:SetNextPrimaryFire( CurTime() + 0.5 )

	// Can blow up after a short delay (so have time to release mouse button)
	self:SetNextSecondaryFire( CurTime() + 1 )
end

This. I remade the HL2 weapons for myself with my base, so I am not posting all of the code.

Alright, I’m trying to change the firing sound for one of the weapons, but I get this error in the console



Failed to load sound "sound\weapons\ar2\fire1.wav", file probably missing from disk/repository


this is whats in the swep file



SWEP.Primary.Sound			= Sound( "sound/weapons/ar2/fire1.wav" )


Remove ‘sound/’ from the path name as it already searches relative to that folder: Sound( “weapons/ar2/fire1.wav” )

i changed it to what you said, and it worked, but it used the ar2 sound, so I just changed the title of the sound file, and now this happens in the console



Failed to load sound "weapons\ar2\ar151.wav", file probably missing from disk/repository


this is what i changed it to



SWEP.Primary.Sound			= Sound( "weapons/ar2/ar151.wav" )


Try some of these AR2 sounds and see which one you want to use:



Weapon_AR2.Double
Weapon_AR2.Empty
Weapon_AR2.NPC_Double
Weapon_AR2.NPC_Reload
Weapon_AR2.NPC_Single
Weapon_AR2.Reload
Weapon_AR2.Reload_Push
Weapon_AR2.Reload_Rotate
Weapon_AR2.Single
Weapon_AR2.Special1
Weapon_AR2.Special2


Example usage: SWEP.Primary.Sound = Sound( “Weapon_AR2.Single” )

Yeah but the thing is i’m trying to use a custom sound, not an AR2 Sound.

Well based off the error, the sound you gave it doesn’t exist. Are you sure it’s actually in that folder?

exact directory

C:\Program Files (x86)\Steam\SteamApps\common\GarrysMod\garrysmod\addons\More Weapons + Better Weapons HL2\lua\sound\weapons\ar2\ar151.wav

Take it out of your lua folder.

I. Am. F-king. Retarded.

[editline]20th August 2014[/editline]

How do I put the sounds in this format, that may sound like nonsense, but I don’t know the correct word for it. Like how do I get weapons/ar2/ar2_(wateversound) to be like Weapon_A15.(blabla).(blabla)

You’d use this function.

You don’t have to do this.

Didn’t work. here’s what i put in the SWEP file



sound.Add({
	name = "Weapon_A15.Reload_Rotate",
	channel = CHAN_STATIC,
	volume = 1.0,
	level = 80,
	pitch = {95, 110},
	sound = "weapons/ar2/a15_reload_rotate.wav"
} )

sound.Add({
	name = "Weapon_A15.Reload_Push",
	channel = CHAN_STATIC,
	volume = 1.0,
	level = 80,
	pitch = {95, 110},
	sound = "weapons/ar2/ar2_reload_push.wav"
} )

sound.Add({
	name = "Weapon_A15.Reload",
	channel = CHAN_STATIC,
	volume = 1.0,
	level = 80,
	pitch = {95, 110},
	sound = "weapons/ar2/a15_reload.wav"
} )


[editline]20th August 2014[/editline]

Hey Robotboy, explain how do I make the reload sounds without it please?

Just play the sound with self:EmitSound( “path”) or something.

The reload sound is multiple sounds