Hi, I am trying to make a SWEP where a user can click on another user while holding it and have something about the other player show up e.g. their health or armor.
Something like this:
[CODE]
function SWEP:PrimaryAttack()
if localplayer is looking at another player then
print("Health: "..otherPlayer:Health().." Armor: "..otherPlayer:Armor())
end
end[/CODE]
If anyone could help me with this it'd be great.
Use eyetrace
[code]local otherPlayer = self.Owner:GetEyeTrace().Entity
if ( IsValid( otherPlayer ) and otherPlayer:IsPlayer() ) then
print("Health: "..otherPlayer:Health().." Armor: "..otherPlayer:Armor())
end[/code]
[url]http://wiki.garrysmod.com/page/Player/GetEyeTrace[/url]
and
[url]http://wiki.garrysmod.com/page/Entity/IsPlayer[/url]
Edit: damn ninjas
[QUOTE=code_gs;49599973][code]local otherPlayer = self.Owner:GetEyeTrace().Entity
if ( IsValid( otherPlayer ) and otherPlayer:IsPlayer() ) then
print("Health: "..otherPlayer:Health().." Armor: "..otherPlayer:Armor())
end[/code][/QUOTE]
Thank you!
Sorry, you need to Log In to post a reply to this thread.