Welcome, Guest. Please login or register.
Did you miss your activation email?
September 19, 2024, 11:56:39 PM
Home Help Login Register
News: Trouble in Terrorist Town? Site here, forum here.

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Playing sounds if player leaves mid round
Pages: [1]
Author Topic: Playing sounds if player leaves mid round  (Read 9305 times)
Bigcot
Poster

Posts: 15


« on: February 18, 2012, 01:51:59 AM »

I'm not all that familiar with the lua language I was wondering if anyone would even know how to go about making a sound play if someone leaves prior to the round being over.
Mr. Gash
Poster

Posts: 382


www.nonerdsjustgeeks.com


« Reply #1 on: February 18, 2012, 01:59:05 AM »

Gamemode.PlayerDisconnected

Something like this should work,

local function PlaySound( )
if GetRoundState() == ROUND_ACTIVE then
BroadcastLua('surface.PlaySound("your/sound.mp3")')
end
end
hook.Add("PlayerDisconnected", "GuyLeft", PlaySound)


Assuming that's what you meant.
Bigcot
Poster

Posts: 15


« Reply #2 on: February 18, 2012, 02:12:47 AM »

Much appreciated looks like it would do what I need, question is where would I go about putting this? gamemode/terrortown/gamemode/shared.lua?
Mr. Gash
Poster

Posts: 382


www.nonerdsjustgeeks.com


« Reply #3 on: February 18, 2012, 05:31:53 AM »

garrysmod/lua/autorun/server/filename.lua
Bigcot
Poster

Posts: 15


« Reply #4 on: February 19, 2012, 01:36:18 AM »

Many Thanks! :)
Bigcot
Poster

Posts: 15


« Reply #5 on: February 19, 2012, 02:09:24 AM »

Hmm oddly enough it didn't seem to play the sound =/

resource.AddFile("sound/ragequit.mp3")

local function PlaySound( )
if GetRoundState() == ROUND_ACTIVE then
BroadcastLua('surface.PlaySound("sound/ragequit.mp3")')
end
end
hook.Add("PlayerDisconnected", "GuyLeft", PlaySound)

This is what I have
Mr. Gash
Poster

Posts: 382


www.nonerdsjustgeeks.com


« Reply #6 on: February 19, 2012, 02:18:18 AM »

surface.PlaySound already reads from the sound/ directory (meaning it's trying to play the file sound/sound/ragequit.mp3). Just change sound/ragequit.mp3 to ragequit.mp3. (Leave the resource.AddFile as it is.)


resource.AddFile("sound/ragequit.mp3")

local function PlaySound( )
  if GetRoundState() == ROUND_ACTIVE then
      BroadcastLua('surface.PlaySound("ragequit.mp3")')
  end
end
hook.Add("PlayerDisconnected", "GuyLeft", PlaySound)
« Last Edit: February 19, 2012, 02:23:43 AM by Mr. Gash »
Bigcot
Poster

Posts: 15


« Reply #7 on: February 19, 2012, 02:27:41 AM »

Again I can't thank you enough, Still in the process of learning Lua :D
sniperduck
Poster

Posts: 178


|:NxS:| Staff! :D


« Reply #8 on: February 19, 2012, 02:56:28 AM »

surface.PlaySound already reads from the sound/ directory (meaning it's trying to play the file sound/sound/ragequit.mp3). Just change sound/ragequit.mp3 to ragequit.mp3. (Leave the resource.AddFile as it is.)


resource.AddFile("sound/ragequit.mp3")

local function PlaySound( )
  if GetRoundState() == ROUND_ACTIVE then
      BroadcastLua('surface.PlaySound("ragequit.mp3")')
      ChatPrint(Nick().." is a pussy.")

  end
end
hook.Add("PlayerDisconnected", "GuyLeft", PlaySound)



fixed it

Overtime these forums have made me an asshole. ;D (TTT subforum)
|:NxS:| Custom TTT Server: source.nxs-gaming.com:27016
|:NxS:| Vanilla TTT Server: source.nxs-gaming.com:27016
|:NxS:| Fretta: <COMING SOON>
Pages: [1]
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Playing sounds if player leaves mid round « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.007 seconds with 18 queries.