How would I go about making an entity only take damage from a certain weapon? I'm currently using a basic function (ENT:OnTakeDamage) and setting the health of the entity and a bunch of other iffy stuff.
function ENT:OnTakeDamage( dmginfo )
-- Goal is to basically have a if statement here stating if you have this weapon you can damage the entity.
self:SetHealth( self:Health() - dmginfo:GetDamage())
if self:Health() <=0 then
self:Remove()
end
end
dmginfo:GetAttacker()
dmginfo:GetInflictor()
If the weapon is hold by a player the attacker and inflictor might be a player entity, so just check for GetActiveWeapon.
Could you show me how you would go about doing that? Cause I already tried that and had issues with the GetInflictor part.
Print yourself what GetInflictor and GetAttacker returns.
If both returns a player for your "weapon".
Check for validity with IsValid, call IsPlayer to check for the player class and then call GetActiveWeapon (+ validity) and check for the weapon class.
Return false if one of these is false.
Use a more descriptive title next time.
Got it to work, I'm re-learning GLua and had a bit of brainlag, thanks, these answers helped a ton!
Sorry, you need to Log In to post a reply to this thread.