Weapon Script Problems

I made a SWEP, using the bullets and props pack, but when the right fire action is pressed, (it shoots a prop) I get an error like “Vector excpected got userdata #1

This is my SWEP Script.

function SWEP:Initialize()
	if ( SERVER ) then
		self:SetWeaponHoldType( self.HoldType )

function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	local bullet = {}
		bullet.Num = self.Primary.NumberofShots
		bullet.Src = self.Owner:GetShootPos()
		bullet.Dir = self.Owner:GetAimVector()
		bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
		bullet.Tracer = 0
		bullet.Force = self.Primary.Force
		bullet.Damage = self.Primary.Damage
		bullet.AmmoType = self.Primary.Ammo
	local rnda = self.Primary.Recoil * -1
	local rndb = self.Primary.Recoil * math.random(-1, 1)
	self.Owner:FireBullets( bullet )
	self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )

function SWEP:SecondaryAttack()
	self:Throw_Attack (self.Secondary.Model, self.Secondary.Sound, self.Secondary.AngVelocity)
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay )
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )

//SWEP:Throw_Attack(Model, Sound, Angle)\\
function SWEP:Throw_Attack (Model, Sound, Angle)
	local tr = self.Owner:GetEyeTrace()
	self.Weapon:EmitSound (Sound)
	self.BaseClass.ShootEffects (self)
	if (!SERVER) then return end
	local ent = ents.Create ("prop_physics")
	ent:SetModel (Model)
	ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
	ent:SetAngles (self.Owner:EyeAngles())
	local phys = ent:GetPhysicsObject()
	local shot_length = tr.HitPos:Length()
	phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 7))
	cleanup.Add (self.Owner, "props", ent)
	undo.Create ("Thrown model")
	undo.AddEntity (ent)
	undo.SetPlayer (self.Owner)
//Throw_Attack(Model, Sound, Angle)\\


Please help :saddowns:

If we knew what line it was erroring on that would be dandy.

Without looking at any code and just your error explanation I’m going to assume you put an angle in a spot where it wanted a vector.

I’m most likely assuming it’s this:

ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
ent:SetAngles (self.Owner:EyeAngles())

[editline]13th September 2015[/editline]

You haven’t provided the information for me to know exactly what’s happening, but it means that your secondary fire is expecting a vector that it never receives.

The full error would be useful otherwise; it will provide us with the line number where it broke.


PhysObj:AddAngleVelocity( Vector velocity )

Got it, so what do I replace this with?


What goes in the parenthases if I want it to shoot forward?

[editline]14th September 2015[/editline]

Bump :pudge:

[editline]14th September 2015[/editline]

Bump Again :ohno: Halp please

didnt take the time to read the entire post

Cool. Thanks.

I’ll try it…

It doesnt work.

Also bump :blaze: :blaze:


Wrong topic XD derp

it doesnt work or there are errors?

AddAngleVelocity adds angular momentum to the physics object, so unless you’re shooting a ball, there’s no way to add angles untils it moves forward because you are changings its angular velocity and not directional velocity. ApplyForceCenter or SetVelocity is what you’re looking for if you wanna increase the velocity in a set direction. If you still need AddAngleVelocity the arguments follow like this:
AddAngleVelocity( Vector( Roll, Pitch, Yaw ) )


Thanks. Very, very, very detailed.
Mind blown