NPC.SetEnemy

From GMod Wiki

Jump to: navigation, search
Function
Syntax NPC:SetEnemy( Entity Enemy[, Boolean  ???] )
Description:
Tells an NPC to attack an enemy
Returns: nil
In Object: Npc
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=NPC.SetEnemy]NPC.SetEnemy [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionExample use of setting an enemy
Used onNewerServer.png
Code
function SWEP:PrimaryAttack()
 
	if CLIENT || (self.NPC == nil) || !self.NPC:IsValid() || !self.NPC:IsNPC() then return end
 
	local trace = self.Owner:GetEyeTrace()
	if !trace.Entity:IsValid() and trace.Entity:IsPlayer() then return end
 
	self.NPC:SetEnemy(trace.Entity)
	self.Owner:PrintMessage( HUD_PRINTTALK, "Enemy set")
end
OutputThe NPC you use this one will be the enemy of self.NPC


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox