NPC/AddEntityRelationship

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(From Request Tracker [https://github.com/Facepunch/garrysmod-requests/issues/1380 #1380])
 
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=AddEntityRelationship
 
|Parent=NPC
 
 
|Description=Makes the NPC like, hate, feel neutral towards, or fear the entity in question. If you want to setup relationship towards a certain entity ''class'', use {{ClassFunction|NPC|AddRelationship}}.
 
|Description=Makes the NPC like, hate, feel neutral towards, or fear the entity in question. If you want to setup relationship towards a certain entity ''class'', use {{ClassFunction|NPC|AddRelationship}}.
 +
 +
{{Note|NPCs do not see {{Type|NextBot}}s by default. This can be fixed by adding the [[Enums/FL|FL_OBJECT]] flag to the NextBot.}}
 
|Realm=Server
 
|Realm=Server
 
|IsClass=Yes
 
|IsClass=Yes

Latest revision as of 03:36, 25 November 2019

 NPC:AddEntityRelationship( )

Contents

Description

Makes the NPC like, hate, feel neutral towards, or fear the entity in question. If you want to setup relationship towards a certain entity class, use NPC:AddRelationship.

NOTE

NPCs do not see NextBots by default. This can be fixed by adding the FL_OBJECT flag to the NextBot.

Arguments

Entity target

The entity for the relationship to be applied to.

Arguments

number disposition

A D_ Enums representing the relationship type.

Arguments

number priority

How strong the relationship is.

Examples

Example

Spawns a manhack and makes it fear player 1.

local hack = ents.Create( "npc_manhack" )
hack:Spawn()
hack:AddEntityRelationship( player.GetByID(1), D_FR, 99 )


Examples

Example

Find wanted NPC class name and make them hate the entity.

function ENT:Think()
local enemy = ents.FindByClass("npc_*") --Find any spawned entity in map with class beginning at npc
    for _, x in pairs(enemy) do --for every found entity do
       if !x:IsNPC() then return end -- if found entity is not NPC then do nothing 
       if x:GetClass() != self:GetClass() then -- if found entity is not self entity then continue
        x:AddEntityRelationship( self, D_HT, 99 ) -- found entity will hate self entity
        self:AddEntityRelationship( x, D_HT, 99 ) -- self entity will hate found entity          
       end
    end 
end


Personal tools
Navigation