Nextbots- Gets bullets to fire from Weapon.

Trying to get a Bot to shoot bullets, and i can, but they always spawn from the Model’s Hand, rather than the Weapon itself, which is wierd,because nowhere in my code did i set the Source position to the hand.

The shoot Bullets function from the SWEP i’m using with my bot:


function SWEP:ShootBullet( damage, num_bullets, aimcone )
	local dir = nil
	local scr = nil
	local muzzle = self:LookupAttachment("muzzle")
	local obj = self:GetAttachment(muzzle)
	--print(self.Owner)
	if self.Owner:IsPlayer() then
		dir = self.Owner:GetAimVector()
		scr = self.Owner:GetShootPos()		
	else
		local orig = (self.Owner:GetEnemy():GetPos() - self.Owner:GetPos()):GetNormalized():Angle()
		dir = orig:Forward()
		scr= obj.Pos
		--scr = self:GetPos()
	end
	
	local bullet = {}

	bullet.Num 	= num_bullets
	bullet.Src 	= scr --self:GetPos() --self.Owner:GetShootPos() -- Source
	bullet.Dir 	=  dir --self.Owner:EyePos() --self.Owner:GetAimVector() -- Dir of bullet
	bullet.Spread 	= Vector( aimcone, aimcone, 0 )	 -- Aim Cone
	bullet.Tracer	= 1 -- Show a tracer on every x bullets 
	bullet.Force	= 1 -- Amount of force to give to phys objects
	bullet.Damage	= damage
	bullet.AmmoType = "Pistol"
	
	self.Owner:FireBullets( bullet )
	
	self:ShootEffects()
	
end

This is what the Bot itself uses to shoot the gun:


function ENT:ShootGun()
if self.HasGun == false then
self:GiveGun()

end

self.Weapon:PrimaryAttack()
end

Yet, the bullets spawn from the bot’s hand (the one that ISNT holding the gun), not the Muzzle attachment

Am i missing something crucial?

Haha, this sure is a pickle.
I tried this a while back and it’s quite frustrating.

What you need to do is grab the attachment of the model that the nextbot is holding, rather than the right hand itself, and use that for your tracer.

[editline]20th February 2015[/editline]

oh, since it’s a real weapon, you could just use self:GetAttachment in that case.

Nowhere in my code did i set the Scr position to my Bot’s hand, i set it the Muzzle position of the Gun, yet the bullets are coming from his hand

Bump because this is annoyingly frustrating

Is it a standard gmod model or custom?

Standard. It’s the Combine Soldier Model