AddRelationship NPC with Player

Hello,

I try to use this:
**[NPC.AddRelationship

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=NPC.AddRelationship)**

[lua]
NPC:AddRelationship(“player D_HT 999”)
[/lua]

But it doesn’t work. It write the “player” it doesn’t a existing class.
I try with “players” too and return the same problem !

Could you help me, please ?

How are you using it?

Can you post your code please.

It actually worked for me at the time I added that example to the wiki page…

[lua]
TOOL.Category = “Pulp MMORPG Tools”
TOOL.Name = “NPC Auto Spawner”
TOOL.Command = nil
TOOL.ConfigName = nil

local selected_npc = ents.GetByIndex(1);
local doMove = false;

if CLIENT then
language.Add( “Tool_NPCSpawner_name”, “NPC Auto Spawner” )
language.Add( “Tool_NPCSpawner_desc”, “Utiliser pour creer un npc qui reapparait quand il meurt.” );
language.Add( “Tool_NPCSpawner_0”, “Clique-gauche : (De)Selectionner/Coller un npc. Double-clique: Déplacer le npc” );
end

function TOOL:LeftClick( trace )
if(trace.Entity:IsNPC()) then
if(doMove) then
doMove = false;
end

    if(selected_npc == trace.Entity) then
        doMove = true
    end
   
    selected_npc = trace.Entity;              
            
    return true;                
end
    
if(!trace.Entity:IsNPC()) then
    selected_npc = nil;
    
    if(doMove) then
        doMove = false;            
    end
            
    return true;
end   

end

function TOOL:RightClick( trace )
end

– Construire pour la première fois le panneau de contrôle
function TOOL.BuildCPanel( panel )
end

– Reconstruction du panel
local type_npc = 0;

function TOOL.BuildCPanel( panel )
panel:ClearControls();

local options = {};
options["Allie"] = {type_npc = 3};
options["Ennemi neutre"] = {type_npc = 4};
options["Ennemi total"] = {type_npc = 1};

panel:AddControl("ListBox", {
    Label = "Hostilite",
    Description = "Type du npc qui apparaitra.",
    Options = options        
});

end

function TOOL:Think()
local trace = self:GetOwner():GetEyeTrace()

if(doMove and selected_npc != nil and trace.Entity != selected_npc) then        
    selected_npc:SetPos(trace.HitPos);
    selected_npc:SetAngles(Angle(0, self:GetOwner():GetAngles().y+180, 0));
end

if(selected_npc != nil and selected_npc:IsNPC()) then
    for k, v in pairs(player.GetAll()) do
        selected_npc:AddEntityRelationship(v, type_npc, 999 );
    end
end

end
[/lua]

Lawl , part of his code is french. FRENCH FTW :3

–Snip, there’s 2 entries to the wiki.