# Ballistics - Physical bullets.

Sorry to say that, but the method you are creating “randomness” to the bullets (bullet spread) is inefficient.
The spread vector defines the two radius’s of an ellipsis and has nothing todo with a real direction vector.
So your current method destroys e.g. the old behaviour of the shotgun. E.g. when you shoot directly into the air (z-axis) you nearly have no offset, but when doing the same into the x axis, you have massive offset.

Here is my method which is (mathematical) correct - It adds a random offset according to the bullet’s original direction vector and their both elliptic radius’s for the bulletspread cone.

That’s an excerpt of my stargate pack (shield/init.lua)

[lua]if(not StarGate.Entity_FireBullets) then
local meta = FindMetaTable(“Entity”);
if(meta) then
StarGate.Entity_FireBullets = meta.FireBullets;
– My thing here now stops bullets
meta.FireBullets = function(self,t)
if(t) then
local num = t.Num or 1; t.Num = 1; – Just ONE bullet drawn by FireBullets. The others are getting shot by the loop
local direction = (t.Dir or Vector(0,0,0));
local pos = t.Src or self.Entity:GetPos();
local rnd = {};
– Must be in a separate for loop because calling StarGate.Entity_FireBullets(self,t); seems to reset the random generator
for i=1,num do
rnd* = {math.Rand(-1,1),math.Rand(-1,1)};
end
local return_false = false; – This is for one of my own scripts, so I know when to draw inpact smoke or not
–################# FIRE ZEH MISSLES!
for i=1,num do
local dir = Vector(direction.x,direction.y,direction.z); – We need a “new fresh” vector
– Two perpendicular vectors to the direction vector
local v1 = (dir:Cross(Vector(1,1,1))):Normalize();
local v2 = (dir:Cross(v1)):Normalize();
– Instead letting the engine decide to add randomness, we are doing it!
t.Dir = dir;
end
local trace = StarGate.Trace:New(pos,dir161024,{self.Entity,self.Entity:GetParent()});
if(trace.Entity:IsValid() and trace.Entity:GetClass() == “shield”) then
trace.Entity:Hit(self.Entity,trace.HitPos,(t.Damage or 50)/50,-1*trace.Normal);
return_false = true;
else
StarGate.Entity_FireBullets(self,t); – Normal bullet!
end
end
if(return_false) then return false end;
end
end
end
end[/lua]

Have fun

What are you bitching about? the guy he was talking to said

He said “All scripted weapons”

Holy shit, you can do so much with this! I’m thinking invisible wall neo bullet stopping powers.

Well, with this, you can grab the bullets with the gravity gun and even turn them around and send them back at whoever shot it.

I’ll give that a shot.

Could you make your code any messier? :uhoh:

Why do you need a menu for one command?

You should make all kinds of weird settings like bouncy bullets, spread bullets, and hilariously slow bullets.

Does it do this to all sweps? Hmmm… I should try this :3

It overrides the FireBullets function so any script that calls it will work.

Are you using the SMOD bullets?

So… All SWeps… Does that include lasers?

If you mean the model, no.

You should, they’re an actual bullet projectile as a model.

Except that model doesn’t have a physics model.

No… only SWEPs that fire regular bullets.

Yes it does, I’ve used them with the prop cannon.

Could I implement this into my Swep?
Ill be sure to give credit

And If so

Is there any way to just add it to One Swep Instead of all the Sweps able to shoot bullets?

Example:

I have 3 Sweps installed
A Pistol
A Machine Gun
And A Chaingun

I want Only the Chaingun to fire physical bullets, and None of the others

You can always use the old function that’s set in the script:
[lua]Entity:FireBulletsOld[/lua]

Ugh, my host_timescale won’t work. It says it’s set to .1, but it’s still normal.

For me, that’s not really messy. I’m not liking long variable names

I would love to see a video.

You need to enable cheats first.