Healing Players

So I found out that the wiki says that the player object has a lot of the functions an entity has, and the entity object has a TakeDamage function. I am trying to make a sortof “Magic Potion” that will heal players. Here is my code, placed into the Primary Attack function


/--------------------------------------------
// Called when the player Shoots
//--------------------------------------------
function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	if debug then
		print("Primary Attack")
		// Put Your debugging Code in here
	end
 
	// Any Code you want to be executed when the player uses primary attack goes in here
	self.Weapon:EmitSound(self.Sound)
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	if ( SERVER ) then
		self.Owner:TakeDamage(-20,self.Owner, self)
	end
	self:TakePrimaryAmmo(1)
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Delay )
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Delay )
end

So is this correct or no?

self.Owner:SetHealth( self.Owner:Health() + 20 )

[editline]05:31PM[/editline]

Note: it can give the player over 100 health.

Well, if you want to heal the, you should probably use SetHealth instead of TakeDamage. TakeDamage should typically be called only for damage.

Ah, didn’t see that in the wiki. I did edit->find health too =/

Ninja’d!