make poison grenade only damage Inno&D

I am trying to get a T weapon poison gas grenade

more specifically


function Poison(ent)
					if plymeta.IsTraitor or plymeta.IsDetective
					ent:TakeDamage(5, self.Owner, "weapon_ttt_pixiegasgrenade")
					end
				end

to only effect innocents and detectives but have failed over and over again. Could anyone help?

EDIT:removed now un relevant code

Going about it a different way now

You’re not getting the role from any entity.

poison gas damage would need to be entity damage, no?

You define “tr“ as a global var.
You try to check if plymeta.IsTraitor and plymeta.IsDetective exists. But you don’t check if a player is a traitor or a detective.
You try to use a collision group as mask for your TraceLine.
And there are more things which are wrong.

Thank you for the informative response, I want to apologize as this isn’t my code and I only tested in game to see if it worked and it did so I didn’t bother trying to clean anything up.
I was just trying to alter a workshop item to add a feature I wanted. I’m going to give it a few more attempts and if nothing then I will start something from scratch to save the hassle.

new method working aside from the damage


function ENT:Think()
	if GetRoundState() == ROUND_POST then return end
	if( CurTime() >= self.Timer )then
		for _,v in ipairs(ents.FindInSphere(self:GetPos(),128)) do
			if v:IsPlayer() && !v:IsDetective() then
				v:SetHealth(v:Health() - Dmg);
				self.Timer = CurTime() + .50;
				if( v:Health() <= 0 ) then
					v:Kill();
				end
			end
		end
	end
end

Any help on why this would be returning attempt to index global ‘ENT’ a nil value?

I’m assuming it’s causing that because this is a SWEP, not an entity.

even as SWEP:Think() it returns attempt to compare nil with number

That doesn’t mean that SWEP:Think() isn’t correct. The attempt to compare nil with number is it’s own error.



if SERVER then
   AddCSLuaFile("shared.lua")
end

ENT.Type = "anim"
ENT.Base = "ttt_pinkbasegrenade_proj"
ENT.Model = Model("models/weapons/w_eq_smokegrenade_thrown.mdl")


AccessorFunc( ENT, "radius", "Radius", FORCE_NUMBER )

function ENT:Initialize()
   if not self:GetRadius() then self:SetRadius(20) end

   return self.BaseClass.Initialize(self)
end

if CLIENT then

   local smokeparticles = {
      Model("particle/particle_smokegrenade"),
      Model("particle/particle_noisesphere")
   };

   function ENT:CreateSmoke(center)
      local em = ParticleEmitter(center)

      local r = self:GetRadius()
      for i=1, 20 do
         local prpos = VectorRand() * r
         prpos.z = prpos.z + 32
         local p = em:Add(table.Random(smokeparticles), center + prpos)
         if p then
            local red = math.random(250, 255)
            local green = math.random(250, 255)
            local blue = math.random(250, 255)
            p:SetColor(red, 0, blue)
            p:SetStartAlpha(255)
            p:SetEndAlpha(200)
            p:SetVelocity(VectorRand() * math.Rand(900, 1300))
            p:SetLifeTime(0)
            
            p:SetDieTime(math.Rand(50, 70))

            p:SetStartSize(math.random(140, 150))
            p:SetEndSize(math.random(1, 40))
            p:SetRoll(math.random(-180, 180))
            p:SetRollDelta(math.Rand(-0.1, 0.1))
            p:SetAirResistance(600)

            p:SetCollide(true)
            p:SetBounce(0.4)

            p:SetLighting(false)
         end
      end

      em:Finish()
   end
end


function ENT:Explode(tr)
   if SERVER then
      self:SetNoDraw(true)
      self:SetSolid(SOLID_NONE)

      -- pull out of the surface
      if tr.Fraction != 1.0 then
         self:SetPos(tr.HitPos + tr.HitNormal * 0.6)
      end

      local pos = self:GetPos()

      self:Remove()
   else
      local spos = self:GetPos()
      local trs = util.TraceLine({start=spos + Vector(0,0,64), endpos=spos + Vector(0,0,-128), filter=self})
      util.Decal("SmallScorch", trs.HitPos + trs.HitNormal, trs.HitPos - trs.HitNormal)      

      self:SetDetonateExact(0)

      if tr.Fraction != 1.0 then
         spos = tr.HitPos + tr.HitNormal * 0.6
      end

      -- Smoke particles can't get cleaned up when a round restarts, so prevent
      -- them from existing post-round.
      if GetRoundState() == ROUND_POST then return end

      self:CreateSmoke(spos)
   end
end


Oh man the copy pasta.

you don’t have to respond if you don’t want to help. I’m trying to provide relevant information. Just need a push down the right path to get it working.

I’m doing it wrong and am going to have to use


function GM:EntityTakeDamage(ent, dmginfo)
	local inflictor = dmginfo:GetInflictor()
	local attacker = dmginfo:GetAttacker()
	local damage = dmginfo:GetDamage()
end

No no no no no no no, don’t don’t don’t override EntityTakeDamage!

You’d need to do this:

  1. Upon the usage of the SWEP (primary fire, or thrown entity, idk what are you trying to use), you need to get the players around the SWEP or the thrown entity. This can be done using

ents.FindInSphere and

Entity:IsPlayer.

  1. Once you got the players you want to affect, use

terrortown/player_ext_shd.lua lines 8,9, 14, 15 to be exact: they show you the way to get player roles.

  1. Once you filtered what players to damage, use

Entity:TakeDamage to apply damage. Once again, do NOT use the function GM:EntityTakeDamage, unless you really know what you are doing: it’s a global GM hook which you shouldn’t override.

I hope this gives you a bit of insight on how to solve this, we don’t want to write the whole script for you <3