Getting player that spawned SNPC (also dispositions/relationships)

I need an SNPC to know what player spawned it. ENT:SpawnFunction doesn’t seem to get called, so that’s not working for me.

The actual reason I need the SNPC to know its player is for setting up dispositions. Right now I have this:
[lua]
function ENT:GetRelationship( entity )
if entity:IsPlayer()
then
return D_LI
elseif entity:IsNPC()
then
local entClass = entity:GetClass()

    if entClass == self:GetClass()
    then
        return D_LI
    elseif self.KnownDispositions[entClass]
    then
        return self.KnownDispositions[entClass]
    else
        return D_HT -- ??
    end
else
	return D_NU
end

end
[/lua]

The thing with the line where I return D_HT is that it will make the SNPC hate any NPC it doesn’t know about, including other SNPCs that are friendly with player (specifically, SNPCs that use the same code as this one). I was wanting to replace the line with return entity:Disposition(self.MyPlayer).

Also, I couldn’t find ENT:GetRelationship in the wiki. Should I take that as a sign that I shouldn’t be using it?

Well it seems to be in the code and if it does work feel free to add it to the wiki. :wink: Anyway you’ll be wanting to give this information to the NPC at the time it is spawned. Is this using sandbox?

Also if you give us a bit more info about which NPCs there will be and for what purpose maybe we can come up with a more efficient way to do it. :o

Sandbox. Well, I want it to work in any game mode that allows NPC spawning…

I was overriding SpawnFunction, but it didn’t seem to get called. I even put a print statement in there, and that never showed up in the console.

I wonder if the reason for that is because I’ve set up my SNPC to appear in the NPCs tab instead of the Entities tab.

This SNPC is just a basic one that follows the player around until it sees enemies. I’ve made two SNPCs now that use the same code. If I spawn one of each in-game, though, they fight each other.

[lua]
hook.Add(“PlayerSpawnedNPC”, “NPCDisposition”,function( ply, npc )
npc.MyPlayer = ply
npc:AddEntityRelationship( ply, D_LI, 99 )
end)[/lua]
:eng101:
Gamemode.PlayerSpawnedNPC
NPC.AddRelationship
NPC.AddEntityRelationship