• make poison grenade only damage Inno&D
    13 replies, posted
I am trying to get a T weapon poison gas grenade more specifically [CODE]function Poison(ent) if plymeta.IsTraitor or plymeta.IsDetective ent:TakeDamage(5, self.Owner, "weapon_ttt_pixiegasgrenade") end end[/CODE] 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.
[QUOTE=markusmarkusz;50891696]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.[/QUOTE] 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 [CODE]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[/CODE] Any help on why this would be returning attempt to index global 'ENT' a nil value?
[QUOTE=pants73;50898354]new method working aside from the damage [CODE]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[/CODE] Any help on why this would be returning attempt to index global 'ENT' a nil value?[/QUOTE] I'm assuming it's causing that because this is a SWEP, not an entity.
[QUOTE=Jiwer;50898498]I'm assuming it's causing that because this is a SWEP, not an entity.[/QUOTE] even as SWEP:Think() it returns attempt to compare nil with number
[QUOTE=pants73;50898530]even as SWEP:Think() it returns attempt to compare nil with number[/QUOTE] That doesn't mean that SWEP:Think() isn't correct. The attempt to compare nil with number is it's own error.
[CODE] 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 [/CODE]
Oh man the copy pasta.
[QUOTE=Jiwer;50898813]Oh man the copy pasta.[/QUOTE] 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.
[QUOTE=pants73;50898354]new method working aside from the damage [CODE]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[/CODE] Any help on why this would be returning attempt to index global 'ENT' a nil value?[/QUOTE] I'm doing it wrong and am going to have to use [CODE]function GM:EntityTakeDamage(ent, dmginfo) local inflictor = dmginfo:GetInflictor() local attacker = dmginfo:GetAttacker() local damage = dmginfo:GetDamage() end[/CODE]
[QUOTE=pants73;50899549]I'm doing it wrong and am going to have to use [CODE]function GM:EntityTakeDamage(ent, dmginfo) local inflictor = dmginfo:GetInflictor() local attacker = dmginfo:GetAttacker() local damage = dmginfo:GetDamage() end[/CODE][/QUOTE] [B]No no no no no no no, don't don't don't override EntityTakeDamage![/B] 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 [IMG]https://wiki.garrysmod.com/favicon.ico[/IMG] [URL="https://wiki.garrysmod.com/page/ents/FindInSphere"]ents.FindInSphere[/URL] and [IMG]https://wiki.garrysmod.com/favicon.ico[/IMG] [URL="https://wiki.garrysmod.com/page/Entity/IsPlayer"]Entity:IsPlayer[/URL]. 2) Once you got the players you want to affect, use [IMG]http://www.turshija.com/signature/github.png[/IMG] [URL="https://github.com/garrynewman/garrysmod/blob/ff51a59d5a821dec3c8f524631c86150b3e4744d/garrysmod/gamemodes/terrortown/gamemode/player_ext_shd.lua#L8"]terrortown/player_ext_shd.lua[/URL] lines 8,9, 14, 15 to be exact: they show you the way to get player roles. 3) Once you filtered what players to damage, use [IMG]https://wiki.garrysmod.com/favicon.ico[/IMG] [URL="https://wiki.garrysmod.com/page/Entity/TakeDamage"]Entity:TakeDamage[/URL] 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
Sorry, you need to Log In to post a reply to this thread.