Hey guys, quick question. I was wondering how I would have it when you look at a team it will make a noise globally to symbolize someone has seen the other team.
Something like this
[CODE]
LocalPlayer():GetEyeTrace() if Team() == 0 then sound.Play( "jijo/thud.wav" )
[/CODE]
Honest to god I really don't know what I'd do. Never used GetEyeTrace. Thanks for all the help
:GetEyeTrace().Entity returns entity player is looking at.
If you look at the [URL="http://wiki.garrysmod.com/page/Structures/TraceResult"]TraceResult Structure[/URL] you'll see that you can get the entity the player is looking at by doing Trace.Entity. Then, you can check the entity to see if it's [URL="http://wiki.garrysmod.com/page/Global/IsValid"]valid[/URL], if it's a [URL="http://wiki.garrysmod.com/page/Entity/IsPlayer"]player[/URL], and if the player is from the other [URL="http://wiki.garrysmod.com/page/Player/Team"]team[/URL]. If it passes all of the checks, play the sound. It may be better to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/PlaySound]surface.PlaySound[/url] instead of sound.Play too.
Thank you Neth for the support on exactly what it does, and thank you AK to Spray for spending the time to help me out. I will try these out.
[editline]26th September 2015[/editline]
Just a recap, is this what it should look like?
[CODE]
function Thud()
LocalPlayer():GetEyeTrace().Entity and if Entity:IsValid( true ) and Team() == 0 then surface.PlaySound( "jijo/thud.wav" ) end
end
[/CODE]
[QUOTE=CGHippo;48765668]
[CODE]
function Thud()
LocalPlayer():GetEyeTrace().Entity and if Entity:IsValid( true ) and Team() == 0 then surface.PlaySound( "jijo/thud.wav" ) end
end
[/CODE][/QUOTE]
I'm really confused as to what you're doing... try this:
[CODE]
function Thud()
local ent = LocalPlayer():GetEyeTrace().Entity
if ent ~= nil and ent:IsPlayer() and ent:Team() == 0 then -- If it's a player, it's valid (right)?
surface.PlaySound( "jijo/thud.wav" )
end
end
[/CODE]
By the way, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/Team]Player:Team[/url] doesn't return a number, so don't check for 0!
snip
[QUOTE=MPan1;48765720]I'm really confused as to what you're doing... try this:
[CODE]
function Thud()
local ent = LocalPlayer():GetEyeTrace().Entity
if ent:IsPlayer() and ent:Team() == 0 then -- If it's a player, it's valid (right)?
surface.PlaySound( "jijo/thud.wav" )
end
end
[/CODE]
By the way, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/Team]Player:Team[/url] doesn't return a number, so don't check for 0![/QUOTE]
This would pop error btw, due to ent being nil.
[QUOTE=Netheous;48765884]This would pop error btw, due to ent being nil.[/QUOTE]
Fixed it (I think).
Sorry, you need to Log In to post a reply to this thread.