FireBullets Example?

i’m trying to find an example of how the FireBullets function works, so i can eventually get Bots to shoot guns.
I’ve tried an example bot, this is the code:


local bullet = {}
		bullet.Num =  1
		bullet.Src = eye
		bullet.Dir = ENT:GetAimVector() 
		bullet.Spread = Vector( 1 , 1, 0)
		bullet.Tracer = 1
		bullet.TracerName	=  "Tracer"
		bullet.Force = 50
		bullet.Damage =  3
		bullet.AmmoType = "Pistol"
		bullet.Attacker = self

	self.Weapon:FireBullets(bullet)

But the weapon doesn’t fire any bullets. Is there something wrong with the above?
The bot doesn’t have burst fire code, and it has the ability to track its target, so if the above code is working correctly, it should be dying in a few seconds to the bot, but i don’t take any damage, nor do i see any tracers being fired.

It should be self.Owner, not self.Weapon. As for an example, consider weapon_base.


function SWEP:ShootBullet( damage, num_bullets, aimcone )
	
	local bullet = {}
	bullet.Num 		= num_bullets
	bullet.Src 		= self.Owner:GetShootPos()			-- Source
	bullet.Dir 		= self.Owner:GetAimVector()			-- Dir of bullet
	bullet.Spread 	= Vector( aimcone, aimcone, 0 )		-- Aim Cone
	bullet.Tracer	= 5									-- 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


So you’re doing it pretty much right - just using the wrong entity.

There is also a callback function which is called when the bullet hits something. You can use the callback to cause ricochets, penetration, generate evidence to be searched, etc… It is very useful.

I use a helper function to create the bullet, then another to handle the callback which decides ricochet or penetration.


function SWEP:GenerateBullet( _bullet, src, dir, _refract, _tracername, _ammotype )
	local bullet = {
		Num = self.Primary.NumShots or 1; // Check bullet table for how many pellets or projectiles come from each round.
		Src = src;
		Dir = dir;
		Spread = Vector( 0.03, 0.03, 0.06 ); // Check bullet table for spread information
		Tracer = 1; // Check bullet table for tracer information
		TracerName = _tracername or "Ar2Tracer"; // Check bullet table for tracer type, ricochet and penetration use override //""; //"Ar2Tracer"; // "AirboatGunHeavyTracer"; "ToolTracer"//
		Force = ( 10 / _refract ) * 0.5; // Check bullet table for force information
		Damage = 10 / _refract; // Check bullet table for damage information
		AmmoType = _ammotype or "Pistol"; // Check bullet table for ammo "type" which correlates to damage.
		Callback = function( attacker, tr, dmginfo )
			return self:BulletCallback( attacker, tr, dmginfo, _bullet, _refract );
		end;
	};

	return bullet;
end

But, I am ditching the whole FireBullet system as I created my own theoretical bullet simulator…

Basically, the client renders the projectile as it is flying through the air, it actually travels as fast as the bullet would in real life ( the realistic bullet mods / physical bullet mods are limited to a max speed that entities can travel meaning bullets go slow… with mine, since it is theoretical / simulated, it doesn’t have the problem ) with all of the effects. It’ll tie into my weather system for humidity, wind affecting drift, drag, gravity affecting drop, plus rotation of the earth ( will be included )…

https://dl.dropboxusercontent.com/u/14265905/share/2014-08/bullet.webm
https://dl.dropboxusercontent.com/u/14265905/share/2014-08/bullet2.webm

Wanna swap?

Swap? How do you mean?

What’s wrong with firing bullets from the weapon?