For my SNPC base, I've been (trying) to work on a system by which certain SNPCs can hear sounds created by other NPCs via EmitSound...
To do this, I did this (and I really don't like overriding base functions, but here you go.):
[B]The meta file:[/B]
[LUA]meta.fcEmitSound = meta.EmitSound
function meta:EmitSound(sound, ...)
meta:NPCEmitSound()
return meta.fcEmitSound(self, sound, ...)
end
function meta:NPCEmitSound()
util.AddNetworkString("NPCEmitSound")
net.Start("NPCEmitSound") //Net may be inefficient at times, but hooks seemed to cause crashes, the worst
net.WriteEntity(meta) // net messages will do is cause lag, I believe.
net.Broadcast()
end[/LUA]
[B]The SNPC's init:[/B]
[CODE]net.Receive("NPCEmitSound",function(len)
local meta = net.ReadEntity()
for k,v in ipairs(ents.GetAll()) do
if v.m_bOrbSNPC && v:GetPos():Distance(v:GetPos()) <= v.m_flHearDistance then
v:OnHearSound(meta)
end
end
end)
function ENT:OnHearSound(ent)
print("test")
end[/CODE]
ENT.m_flHearDistance is a real variable, and m_bOrbSNPC is also a boolean in my code, both of these are valid.
The game doesn't crash and close the entire window, but rather keeps the window active as if it is loading something for an infinite amount of time.
And I DO realize that replacing core functions is incredibly risky (or atleast that's how I see it, given their wide use.)
Sorry, you need to Log In to post a reply to this thread.