I am trying to make it so when my entity touches someone it takes a certain amount of health away.
I am using Ent:PhysicsCollide to make it bounce and when i try to use Ent:Touch or Ent:StartTouch it makes my Swep error saying i am using a Null entity here is the code i used
[lua]function ENT:StartTouch(targ)
if (targ:IsValid() and targ:IsPlayer() or targ:IsNPC) then
targ:AddDamage(10)
end
end[/lua]
Any help please
What is the exact error?
Also, AddDamage is a method for CTakeDamageInfo's, you need to use [b][url=http://wiki.garrysmod.com/?title=Entity.TakeDamage]Entity.TakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
okay, it says tryin to use NULL Entity or something like that from my SWEP file
[editline]11:37PM[/editline]
Attempted to create unknown entity type air_ball!
weapons\weapon_whiteball\shared.lua:28: Tried to use a NULL entity!
[editline]11:38PM[/editline]
Line 28:
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
[QUOTE=WhiTAkeR;21821720]okay, it says tryin to use NULL Entity or something like that from my SWEP file
[editline]11:37PM[/editline]
Attempted to create unknown entity type air_ball!
weapons\weapon_whiteball\shared.lua:28: Tried to use a NULL entity!
[editline]11:38PM[/editline]
Line 28:
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))[/QUOTE]
[lua]ent:SetPos(self.Owner:GetEyeTrace().HitPos)
[/lua]
[QUOTE=Cubar;21839054][lua]ent:SetPos(self.Owner:GetEyeTrace().HitPos)
[/lua][/QUOTE]
That has nothing to do with this at all,
WhiTAkeR, your entity is not being created because there is an error. Look for another error in your console about the entity.
New problem
[lua]function ENT:Touch(targ)
if targ:GetOwner() then return end
if (targ:IsValid() and targ:IsPlayer() or targ:IsNPC()) then
targ:TakeDamage(10,self.Entity:GetOwner())
print("working")
end
end[/lua]
Atm the ball wont do any damage to anything, if i swap then the ball kills everything including the owner.
Im probably doin silly mistake but its late and im tired ^^
[code]
function ENT:Touch( what )
if what ~= self:GetOwner( ) then
what:TakeDamage( 10, self:GetOwner( ) )
end
end
[/code]
Something like that, I'd imagine.
That didn't work it damaged both me and the npc :S
jus tried
[lua]function ENT:Touch(targ)
if !targ:GetOwner() then
if (targ:IsValid() and targ:IsPlayer() or targ:IsNPC()) then
targ:TakeDamage(10,self.Entity:GetOwner())
print("working")
end
end
end[/lua]
That didnt work either
noone ? :(
[lua]function ENT:StartTouch(e)
if ValidEntity(e) and e:IsPlayer() or e:IsNPC() then
e:TakeDamage(self.Damage, self.Owner) -- You need to set self.Owner to the player that fires the pellet yourself
end
end[/lua]
Sorry, you need to Log In to post a reply to this thread.