[lua]function MoveToPosition( npc, ent )
if ( !IsValid( npc ) or !IsValid( ent ) ) then return end npc:SetSaveValue( "m_vecLastPosition", ent:GetPos() ) npc:SetSchedule( SCHED_FORCED_GO_RUN )
function GM:EntityEmitSound( tbl )
if tbl.Entity:IsPlayer() then for k, v in pairs( ents.GetAll() ) do if v:IsNPC() then MoveToPosition( v, tbl.Entity ) print( "NPC heard a sound!" ) end end end
Hey there. I want to make Combine move towards players whenever a sound is played in a certain radius. However, this code doesn’t seem to be working. “NPC has heard a sound!” is working fine, but the NPC isn’t moving, and “NPC has heard a sound!” is played far beyond 100 units. What’s going wrong?