Hello everyone, Im actually working on a simple Nextbot based NPC, and for lua learning purposes, I experiment around setting targets.
The problem I have is the following :
I would like to make it so the player that presses E on the NPC becomes the npc's target.
Since ENT:Use don't seem to work with NPCs, I am actually using the ENT:AcceptInput function.
How could I reference the NPC in this function ?
self: doesn't work, here is the part of the code that causes problem.
function ENT:AcceptInput( Name, Activator, Called)if( Name == "Use") and CurTime() >= (Activator.LastUse or0) + 3then
Activator.LastUse = CurTime()
if (angry == nil ) or (angry == false) then angry = true
else angry = false
end
self:SetTarget(Activator) --
print(Activator) -- This is working and returns the player perfectly
print (angry) -- This is working as well
And this is the error I'm getting :
lua/entities/npc_douglastest.lua:25: attempt to call method 'SetTarget' (a nil value)
Thanks for taking the time to read / comment / help
Okay okay haha I get it
As I'm the most beginning beginner ou there, I don't think it is a good way to do it, so sharing it might not be for the best of the the reader. But NVM, those who would encounter the same problem, I fixed it by sending a net message from the server to the client in the AcceptInput function ( which is sent to the client when he presses "e" on the entity ) and instantly returning it back to the server, which sets the player returned in the net message as a " target", without using the SetTarget function.
It basically looks like this :
net.Receive("angrytest2",function(len,ply)
playertotarget = ply
end)
Then worked around this playertotarget in the npc movements / logic.
Hope it makes sens, as a not native english speaker this might be a bit confusing.
Sorry, you need to Log In to post a reply to this thread.