• Print

Author Topic: Chat Sound  (Read 7457 times)

0 Members and 1 Guest are viewing this topic.

Offline Flinta

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
Chat Sound
« on: April 28, 2010, 04:15:04 am »
Hello!

What could be fun on a server if players writed lol a laughing sound will play that others could hear,
or custom it how you like it.  And when typing an Chat bubble appear over head.

Like use ulx forcedownload or resource.AddFile to add sound clips and a lua code to play them when typing lol on chat.

That would be fun. 

thanks for reading.
« Last Edit: April 28, 2010, 04:29:03 am by Flinta »

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Chat Sound
« Reply #1 on: April 28, 2010, 02:00:30 pm »
I thought of this when I first started coding in lua, and yes it was fun until you got like 4 or more people on the server, especially once someone realizes that the sound plays everytime they "lol". I already have a pending request tonight, but it's small. So if you want I can make it for you, but you'll have to provide the .wav file.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat Sound
« Reply #2 on: April 28, 2010, 04:43:52 pm »
Indeed. A module perhaps, but, definitely not a suggestion to include in ULX by default.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Chat Sound
« Reply #3 on: April 28, 2010, 05:09:08 pm »
Here's the code I used to do it at some point...

Code: Lua
  1. -- Sounds
  2. local soundPrefix = "-" -- prefix to use for chat sounds
  3. local soundsBase = "../sound/chat"
  4.  
  5.  
  6. function checkChat( ply, txt )
  7.         if txt:sub( 1, soundPrefix:len() ) == soundPrefix then
  8.                 local folder = soundsBase .. "/" .. txt:sub( soundPrefix:len() + 1 )
  9.                 if file.IsDir( folder ) then -- If we have sounds
  10.                         local files = file.Find( folder .. "/*" )
  11.  
  12.                         if #files < 1 then return end
  13.                         local f = files[ math.random( 1, #files ) ]
  14.                         while file.IsDir( folder .. "/" .. f ) do -- Make sure it's not a folder
  15.                                 f = files[ math.random( 1, #files ) ]
  16.                         end
  17.  
  18.                         umsg.Start( "ulib_sound" )
  19.                                 umsg.String( folder .. "/" .. f )
  20.                         umsg.End()
  21.                 end
  22.         end
  23. end
  24. hook.Add( "PlayerSay", "SoundsCheckChat", checkChat )

This code was written roughly four years back, I think, but I don't see anything offhand that garry broke between then and now. You just create folders under sound/chat for each word you want a sound for, like sound/chat/lol, sound/chat/hi, etc. It picks a random file from each of those directories to play to everyone. In this case, the words need to be prefixed by '-', but you could easily modify this code to pick up chat sounds some other way. You'll need ULib installed to use this or you'll need to make your own sound receiving function. To install this script, stick it in autorun on your server.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat Sound
« Reply #4 on: April 28, 2010, 07:20:31 pm »
(Disclaimer - I didn't look at the code!)
Wow Megiddo, independent folders for each sound?
Surely Garry had a random number selection 4 years ago.
If possible I'd used. /sound/myrandomwordsound/
hi01
hi02
hi03
lol01
lol02
lol03...
Allows for 99 sounds per word. Evan that in my opinion would have been too much.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Chat Sound
« Reply #5 on: April 28, 2010, 09:34:18 pm »
(Disclaimer - I didn't look at the code!)
Wow Megiddo, independent folders for each sound?
Surely Garry had a random number selection 4 years ago.
If possible I'd used. /sound/myrandomwordsound/
hi01
hi02
hi03
lol01
lol02
lol03...
Allows for 99 sounds per word. Evan that in my opinion would have been too much.


It's one folder per word, the files in there are chosen at random when the word is used.
Experiencing God's grace one day at a time.

Offline Flinta

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
Re: Chat Sound
« Reply #6 on: April 29, 2010, 07:54:56 am »
yay! Works perfecly , Thanks alot :D

Now only anti-world/prop noclip left , and have an complete build server :D

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat Sound
« Reply #7 on: April 29, 2010, 07:04:59 pm »
Oops. I meant to say one folder per word, not sound.
Still, the archives you have that come out of the woodwork always entertain me.
<Some obscure rarely asked for idea>... oh, I've done that...here's the code.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Chat Sound
« Reply #8 on: April 29, 2010, 07:29:39 pm »
Still, the archives you have that come out of the woodwork always entertain me.
<Some obscure rarely asked for idea>... oh, I've done that...here's the code.

<shifty eyes> ULX isn't a cover for a top secret government lua script, honest! :P
Experiencing God's grace one day at a time.

Offline Frrz

  • Jr. Member
  • **
  • Posts: 65
  • Karma: 0
    • Youtube ftw
Re: Chat Sound
« Reply #9 on: April 30, 2010, 03:13:40 am »
<shifty eyes> ULX isn't a cover for a top secret government lua script, honest! :P

Liar, that's what you all want us to think.  :o





  • Print