AddEntitRelationship Doesn't work :C


function SWEP:PrimaryAttack()
 
    local eyetr = self.Owner:GetEyeTrace()
    
    for i=1,4 do
    ent = ents.Create( "npc_manhack" )
    ent:SetPos( (eyetr.HitPos+self.Owner:GetPos())/2 + Vector(0,0,i*30))
    ent:SetAngles( eyetr.HitNormal:Angle() )
    ent:Spawn()
    end
    
for _,ply in pairs(player.GetAll()) do 
    if ply:GetModel() == "models/Police.mdl" then
        ent:AddEntityRelationship(ply,"D_NU 999")
    else
        ent:AddEntityRelationship(ply,"D_HT 999")
 end

 end

 
end

Hello!
What’s in this code is not correct?
The menhacks should not attack players with this model, but it does not work

Probably when you check your model, Try first of all printing your model when you get out the weapon, then later on changing what model allows you to add a relation ship.

anyway, it doesn’t work =/

AddEntityRelationship() takes one arg. I don’t think you can make it hate certain players. But players in general?
“player D_HT 999” for example

One arguments used to AddRelationship
For AddEntityRelationship i must use 3 arguments.

bump

[LUA]function SWEP:PrimaryAttack()
local tbPlayersRel = {}
for _,pl in ipairs(player.GetAll()) do
tbPlayersRel[pl] = string.lower(pl:GetModel()) == “models/police.mdl” && D_NU || D_HT
end

local eyetr = self.Owner:GetEyeTrace()
local origin = (eyetr.HitPos +self.Owner:GetPos()) /2
local ang = eyetr.HitNormal:Angle()
for i = 1, 4 do
	local ent = ents.Create("npc_manhack")
	ent:SetPos(origin +Vector(0,0,i *30))
	ent:SetAngles(ang)
	ent:Spawn()
	ent:Activate()
	for pl,disp in pairs(tbPlayersRel) do
		ent:AddEntityRelationship(pl,disp,999)
	end
end

end[/LUA]
Should work. Also cleaned up and optimized your code a bit.

[EDITLINE]-[/EDITLINE]
To clarify:
Entity.AddEntityRelationship takes three arguments: The target entity, the disposition and the intensity. The disposition has to be an enum (D_HT,D_LI,D_NU,D_FR), not a string (In contrary to Entity.AddRelationship).

Thanks, but it doesn’t work too D:

That’s because unless you are a custom player model, the path should be “models/player/police.mdl”.