"Throwing" code not working/random sound table

Couple of issues I’m having with a swep in progress. Firstly, I copied and played with a bit of code from Garry’s chair throwing gun tutorial, which worked for part of the weapon, but not another for some reason.
The throwing works correctly for the primary fire, but not the secondary fire.

The second issue I’m having deals with the table I made in the primary fire code. I found on another thread that using table.Random would be an ideal way of making the swep play one of few set sounds when clicking, but when I tried it, no sound plays (aside from the crowbar swing, which I wrote separate from the table for obvious reasons.)

[lua]function SWEP:PrimaryAttack()

self:EmitSound( "weapons/iceaxe/iceaxe_swing1.wav" )

local psound = { "mcmanager/ziggs_p1.wav","mcmanager/ziggs_p2.wav","mcmanager/ziggs_p3.wav","mcmanager/ziggs_p4.wav" }
self:EmitSound( table.Random(psound) )

self:SendWeaponAnim( ACT_VM_THROW )

self:SetNextPrimaryFire( CurTime() + 0.8 )
self:ShootEffects( self )

local ent = ents.Create( "grenade_ar2" ) -- this and the next four lines are garry's
	ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 50 ) )
ent:SetAngles( self.Owner:EyeAngles() )

ent:SetVelocity(self.Owner:GetForward() * 500 + Vector(0,0,250))


function SWEP:SecondaryAttack()

self:EmitSound( “weapons/iceaxe/iceaxe_swing1.wav” )
self:SendWeaponAnim( ACT_VM_THROW )

local c4 = ents.Create( “prop_physics” ) – same as above, minus the SetModel
c4:SetModel( “models/weapons/w_slam.mdl” )
c4:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 50 ) )
c4:SetAngles( self.Owner:EyeAngles() )

c4:SetVelocity(self.Owner:GetForward() * 500 + Vector(0,0,250))


All feedback dearly appreciated.

When you say not working correctly, do you mean not working at all?

The slam model spawns, as desired, but it’s not “thrown.” It just kind of appears in front of the user.

When you replace “prop_physics” in your secondary attack with “grenade_ar2” does it throw correctly?

Also, typically when I want to play a random sound file I do something like this:

--Put this at the top of your file

SWEP.WeaponSounds = {

--access it like this:

self.Player:EmitSound(self.WeaponSounds[math.random(1,#self.WeaponSounds)], 100, 100)

Yup, replacing “prop_physics” with “grenade_ar2” works, as did your table (thanks for which). I still don’t understand what to do about the throwing issue. Why does it work for the grenade but not the prop?

Because some entities use physics and others don’t. The SMG grenade does not use physics, it simply uses cheap movement that simulates gravity, that’s why its velocity is handled by SetVelocity. Props however use physics, so changing their velocity is just a little bit more complicated. You need to get its “physics object” (which is the object that controls everything that’s physics related), and apply the velocity to it.

Relevant links:

In your case, all you need to do is this:

[lua]c4:GetPhysicsObject():SetVelocity(self.Owner:GetForward() * 500 + Vector(0,0,250))[/lua]

I thought it may have something like that, I just wasn’t sure exactly how to type it in. Thank you both very much.