*Quicky* Aiming sound.

Hi guys I have a quick question regarding a small piece of code which would really help me out.

Is it possible to code something that when you hover over another player via an iron sight, or just looking at them you can play a sound.

So an example of this would be a ‘target required’ sound is played when you look at another player.

Thanks for any help advice or code you can give me.

-Duby

Yes, they way I would personally do it is by using a trace and then checking to see if it hits a player.

A trace. Hmm do you have any links to show me what sort of thing you are on about? This will be the first time I have come across tracers you see. :slight_smile:



local trac = {}
trac.start = ent:GetShootPos()
trac.endpos = trac.start + (ent:GetAimVector() * 99999)
trac.filter = { ent }
local tra = util.TraceLine( trac )


But how would this work and where on earth where would this go? Could you possibly explain in more detail about this?



	local trac = {}
	trac.start = ent:GetShootPos()
	trac.endpos = trac.start + (ent:GetAimVector() * 99999)
	trac.filter = { ent }
	local tra = util.TraceLine( trac )

	if tra.Entity:IsPlayer() then
		-- make sound here
	end


Hmm right this seems interesting. I kinda understand the syntax, but where would this be placed? Within a Swep file or something?

Yes, in a SWEP file.

Hmmm ok thanks! I will use this and perhaps mod it as I go. Thanks for the head start!