If I had to guess, I’d start from here:
So when a sound is played it will check if it matches a sound file.
I setup an ambient_generic entity to loop a sound rain.mp3 located in sound/rain.mp3 and I made it print “IT’S RAINING” if the sound is playing (Which it always is) and another to print if it isn’t raining, for some reason it’s printing it’s not raining so my sound check may be wrong.
function SoundCheck()
for k, v in pairs(ents.GetAll()) do
if v:GetClass() == "ambient_generic" && v:EmitSound() == "sound/rain.mp3" then print("IT'S RAINING!") else print("not rain :(") return end
end
end
hook.Add( "EntityEmitSound", "SoundCheck", SoundCheck )
I also tried
if v:GetClass() == "ambient_generic" && v:EmitSound("sound/rain.mp3") then print("IT'S RAINING!") else print("not rain :(") return end
Here’s where it got really confusing, I just made a check if a sound was even playing at all and it always said no, even though there clearly was.
if v:GetClass() == "ambient_generic" && v:EmitSound() then print("IT'S RAINING!") else print("not rain :(") return end
And even more confusing, checking if there’s an ambient_generic always returns false as well, there most definitely is an ambient_generic entity in my map.
if v:GetClass() == "ambient_generic" then print("IT'S RAINING!") else print("not rain :(") return end
If I remove the
else print("not rain :(")
then the game crashes every time.
I am very stuck and would appreciate it if someone could help me out.