Frag Grenade Trouble

I’m trying to make a fragmentation grenades that ACTUALLY sends out lethal fragments. In the grenade’s explosion there are several things like a shake and an env_explosion, but here is the block that creates the bullets. Problem is, the fragments do absolutely no damage and I don’t know why. Help?

[lua]
local fragmentsreleased=0 //right here is why MY frag grenade is the best
while(fragmentsreleased<360)do
local bullet = {}
bullet.Src = self:GetPos()
bullet.Attacker = self.Owner
bullet.Dir = Angle(math.random(-360,360),math.random(-360,360),math.random(-360,360))
bullet.Spread = Vector(0,0,0)
bullet.Num = 1
bullet.Damage = 50
bullet.Force = 10
bullet.Tracer = 1
bullet.TracerName = “Tracer”
self:FireBullets(bullet)
fragmentsreleased=fragmentsreleased+1
end
[/lua]


(User was banned for this post ("Wrong section" - mahalis))

This may or may not be related to your problem, but bullet.Dir takes a vector, not an angle, for that you should use VectorRand(). On an unrelated note to the problem, that is also an absurdly high number of bullets to be making in one frame (made worse because bullet.Num is 1 and 360 calls are being made as opposed to one call with bullet.Num 360 with a high spread or something), and you should be using a for-loop instead of manual incrementation.

That makes no difference.

If it’s sending out actual particles it will a lag fest when someone throws 20

@Ghor

Yes I realize that that is an absurd number of bullets. There’s a story behind it, too.

At first, I tried to fire just one bullet with bullet.Num=20, but since that didn’t work, I made it instead run the code 20 times, firin one bullet each time. When I tested it, I found that the bullets weren’t killing anything, so I concluded that there weren’t enough of them to get a decent hit probability. So I increased the number of bullets, tested, it failed, increased, tested, it failed, et cetera et cetera. Evevtually I said “that’s just too many damn bullets there must be something else wrong” so I removed the blast damage from the grenade’s explosion function and sure enough, the bullets were doing absolutely NO damage to me or any NPCs. I’m going to take your advice and rewrite this with a for loop, vectorrand and i will decrease the number down to my original 20, but I don’t think it will fix the problem… let me get back to you

[editline]28th December 2010[/editline]

This is what I have right now. The bullets aren’t spreading properly, but that’s ok cause it’s just a math issue. From what I can tell, the bullets STILL aren’t doing any damage.

[lua]
local bullet = {}
bullet.Src = self:GetPos()
bullet.Attacker = self.Owner
bullet.Dir = VectorRand()
bullet.Spread = VectorRand()
bullet.Num = 20
bullet.Damage = 50
bullet.Force = 10
bullet.Tracer = 1
bullet.TracerName = “Tracer”
self:FireBullets(bullet)
[/lua]

[editline]28th December 2010[/editline]

Alright, so I changed around some math stuff and now they’re spreading properly, but STILL NO DAMAGE HELP



local ENT = {}
ENT.Type = "anim"
ENT.Base = "base_anim"

if SERVER then
	function ENT:Initialize()
		self:SetModel("models/weapons/w_eq_fraggrenade_thrown.mdl")
		self:SetSolid(SOLID_VPHYSICS)
		self:PhysicsInit(SOLID_VPHYSICS)
		self:SetMoveType(MOVETYPE_VPHYSICS)
		timer.Simple(2,self.Explode,self)
	end

	function ENT:Explode()
		if !ValidEntity(self) then
			return
		end
		local bullet        = {}
		bullet.Src          = self:GetPos()
		bullet.Attacker     = self.Owner
		bullet.Dir          = VectorRand()
		bullet.Spread       = Vector(360,360,360)
		bullet.Num          = 20
		bullet.Damage       = 50
		bullet.Force        = 10
		bullet.Tracer       = 1 
		bullet.TracerName   = "Tracer"
		self:FireBullets(bullet)
		self:Remove()
	end
end
scripted_ents.Register(ENT,"grenadethingy",true)


This code works fine for me when I spawn the entity with



lua_run a = ents.Create("grenadethingy") a:SetOwner(Entity(1)) a.Owner = Entity(1) a:SetPos(there+Vector(0,0,8)) a:Spawn()


Don’t mind the “there” bit in setpos, it’s just a var I set up for the player’s eye trace hit position. In any case, even though my spread is wrong, I tested with zombies and headcrabs and was able to kill both with the grenade.

Well, alright then. Thanks for the help.

My gmod must be f*cked because I copied what you did there exactly and the bullets fire, they hit but they seem to completely ignore npcs and players. Just like before. Maybe I’ll try re-installing gmod. Again, thanks.

Check if you had godmode enabled.

As far as I know Godmode has no effect on NPCs.

I doubt a bad gmod install would be responsible for something like that, I could be wrong, but I’d be more inclined to check for a conflicting addon or script.