Make him hate a prop?

Is there a way to modify this:
http://redirectingat.com/?id=629X1198&url=http%3A%2F%2Fwiki.garrysmod.com%2F%3Ftitle%3DNPC.AddEntityRelationship

into a command that I could bind to a key that makes selected NPCs attack the entity in my crosshairs when I hit a button, and make it the highest priority?

I don’t know if you can use something like this but if you can make a basic swep put these in the primary/secondary functions and then first primary a npc then secondary a entity

[cpp]
Primary

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld && trace.Entity:IsNPC then
npc = trace.Entity
end

Secondary :

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
target = trace.Entity
npc:AddEntityRelationship(target, 1, 99 )
end

[/cpp]

or somebody could fix it, I don’t have gmod here I just copied and pasted shit from wiki

Well, I can’t lua code, I tried setting up, heres what I have, it doesnt work.

[lua]

Swep.Printname = “The Prop-hater”
Swep.Description = "LC - Choose NPC,

RC, Choose prop."
Swep.Category = “Admin Stuff”
Swep.Spawnable = false
Swep.Adminspawnable = true \I’m not sure if thats a real command…

Swep.Primary.Automatic = false

Primary

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld &&

trace.Entity:IsNPC then
npc = trace.Entity
end

Secondary :

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
target = trace.Entity
npc:AddEntityRelationship(target, 1, 99 )
end

Primary

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld &&

trace.Entity:IsNPC then
npc = trace.Entity
end

Secondary :

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
target = trace.Entity
npc:AddEntityRelationship(target, 1, 99 )
end
[/lua]

and, for wizey!



Swep.Printname	= "The  Prop-hater"
Swep.Description	= "LC - Choose NPC, 

RC, Choose prop."
Swep.Category	= "Admin Stuff"
Swep.Spawnable	= false	
Swep.Adminspawnable	= true

Swep.Primary.Automatic	= false



Primary

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld && 

trace.Entity:IsNPC then
   npc = trace.Entity
end

Secondary :

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
   target = trace.Entity
   npc:AddEntityRelationship(target, 1, 99 )
end













Primary

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld && 

trace.Entity:IsNPC then
   npc = trace.Entity
end

Secondary :

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
   target = trace.Entity
   npc:AddEntityRelationship(target, 1, 99 )
end


You do realise quincy was only giving you snippets, And you were ment to place them within the right functions?.. Go have a look at a swep on GMod.org.

And also, Stop posting the code in code tags just for one person; I know a huge majority of FP can see lua tags.

Yea, I was just hoping it would work…I’ll change somethin now…

[editline]07:47PM[/editline]

Well, Tried it what I thought would work…
[lua]
Swep.Printname = “The Prop-hater”
Swep.Description = “LC - Choose NPC, RC, Choose prop.”
Swep.Category = “Admin Stuff”
Swep.Spawnable = false
Swep.Adminspawnable = true

Swep.Primary.Automatic = false

function SWEP:PrimaryAttack()
local Player = self.Owner

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld && trace.Entity:IsNPC then
npc = trace.Entity
end

function SWEP:PrimaryAttack()
local Player = self.Owner

local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*10000000)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
target = trace.Entity
npc:AddEntityRelationship(target, 1, 99 )
end

[/lua]

…I thought wrong…

You cant “Hate props” , I dont think.

And also, You have set out the weapon wrong at the top.

Remove the top primaryfire function and add an end to the bottom one.

What lines the top primaryfire function on? I can’t find it…

You have 2 primaryfire functions. Remove the top one

Lines 11 - 23

Thats what i get for copy and pasting…

I did try my hand at it but found it impossible to make an npc hate a prop with AddEntityRelationship

Well, is there any way to make a swep like that? prop hating? i know you can make NPCs hate props, theres a garrysmod.org prophate script, but a swep would be more interesting.

I think you would have to make a snpc.

think again :v:

Of course I knew that. I was just giving you one way of doing it.

:3

Well, i have no idea how to make SNPCs…so…