Hello, i'm trying to create a server wide alarm when i specific entity is spawned by a player, alarming all players. How would i go about this?
I've tried something like
self.sound = CreateSound(self, Sound("ambient/levels/labs/machine_moving_loop4.wav"))
for example.
But all that does is player a local sound, i've tried adding a self.sound:SetSoundLevel(99999)
But this just makes the sound louder. Not the radius. Anyone know of how this might be possible? Found an old thread from 8 years ago, didn't do me much good on gmod 13.
EmitSound or something with ents.FindInSphere.
EmitSound did it, anyway i could get it to play the sound once rather than loop?
I am not sure how loop sounds even work but if I'm correct the sound you choosed isn't meant to be used for anything but looping.
Use sound.Add and then stop it with Entity/StopSound.
Are you trying to play the sound for all players on the server?
If so you could do something like below using surface.PlaySound(), player.GetAll(), and SendLua.
for i,v in ipairs(player.GetAll()) do
v:SendLua('surface.PlaySound("ambient/alarms/klaxon1.wav")')
end
That's what i was after, thank you!
I agree with this answer, just wanted to let you know of BroadcastLua which takes care of the for loop for you and looks nicer in the code
It's also much worse on networking since you're sending that whole string.
Yeah, SendLua and BroadcastLua are a bit shit in that regard, but I made a couple of assumptions:
The OP might not know how to use the net library. We could teach him, but if I were him, asking such a simple question (play a sound for all clients) and getting such a complicated answer is a big turn-off.
A sound played for all clients when a certain entity spawns... That probably doesn't happen too frequently. Sending a few extra characters every few minutes isn't going to be noticeable. It's 47 bytes per player. It's fine.
And what do you mean that it's worse on networking? It's the same as the answer I replied to. BroadcastLua is just like using SendLua on all players.
There are wiki tutorials specifically for this
It still adds up, and is a pretty bad habit to get into.
I wasn't familiar with the earlier solution either.
Regarding 1, let me try to explain what I mean with a thread from the fictional forum of the fictional city of NeatVille:
--------------------------------------------
Hey, I wanna read this book, anyone know how I could do that?
----
Sure. You go to the city hall and request a library card. They'll give you an agreement to sign -- make sure you read the whole thing, it's only 4 pages -- and after you sign it they'll give you a library card. Take this card and go to the library, and find your book in the library. Now, the library has replaced some of its employees with this high-tech self-checkout system - it's a bit tricky at first, but you'll get the hang of it pretty soon. There are instructions posted on the walls, but basically it goes like this: take your book and your library card to the checkout system. There are two barcodes on the book - one on the first page, and one on the last page - and your library card has an NFC chip. Put your library card to the scanner first, then scan the barcode from the FIRST page of the book, then the barcode from the LAST page of the book. Don't mess up the order! And then you're done! You can take your book home and read it all you like!
Eventually you'll have to return the book. To do that, first scan your library card, then the LAST page of the book, then the FIRST page of the book. Again, don't mess up the order!
And the best thing is, the library is completely free to use, and you can check out as many books as you want! They have an infinite supply of them. It's really nice.
----
Actually you could just go to the book store and get this book for $10.
--------------------------------------------
Which one would you pick?
KISS is a fair strategy if you were trying to give someone the most minimal, easiest, and fastest solution, but considering this is a developing forum where threads are seen on Google years later by people with the same issue, I would prefer to give the most optimal solution. We should be helping users overcome hurdles with learning GLua by explaining how to do something properly instead of taking an easy workaround.
Much like the book library example, the net library is something you aren't just planning to use once, but in countless scenarios. Although there is a greater learning curve associated with both, the payoff is more net efficient code, applicable skills that can be applied to other general programming structures (the concept of callbacks and reading data in order is pretty crucial in many other languages), and general experience in turning documentation into working code.
I'm not trying to stifle helping users quickly, but rather, meet a medium between fast assistance and useful lessons.
Sorry, you need to Log In to post a reply to this thread.