NPC.GetEnemy

From GMod Wiki

Revision as of 20:50, 1 June 2011 by Chrisaster (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax NPC:GetEnemy( )
Description:
Returns the entity the NPC is currently targeting.
Returns: Entity entity
In Object: Npc
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=NPC.GetEnemy]NPC.GetEnemy [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionExample use of getting an enemy name, from the server side of my TargetId script
Used onNewerServer.png
Code
 
 if trace.Entity:GetEnemy() != nil then
	if trace.Entity:GetEnemy():IsValid() then
		local wname = "None"
		if trace.Entity:GetEnemy():GetClass() == "player" then
			wname = trace.Entity:GetEnemy():Nick() || "None"
		else
			wname = "#" .. trace.Entity:GetEnemy():GetClass() || "None"
		end
		v:SetNetworkedString("Text2P2", wname )
	else
		v:SetNetworkedString("Text2P2", "None" )
	end
else
	v:SetNetworkedString("Text2P2", "None" )
end
 
 
OutputSets a NetworkedVar containing the targets name
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox