Sounds when banning players.

I’ve been trying to get a answer for this for a while now. I’m trying to make it where a URL song plays or a .wav plays when a player is banned. This is the current code I have. Any idea how to get this to do as I want it to be?

local meta = FindMetaTable( “Player” )
local song = “siege/jihad.wav”

meta._ban = meta._ban or meta.Ban
meta._kick = meta._kick or meta.Kick

local function playSound( )
BroadcastLua ( “sound.PlayURL ( '” … song … “’, ‘’, function() end” )
end

function meta:Ban( minutes, kick )
playSound()
self._ban( minutes, kick )
end

function meta:Kick( reason )
playSound()
self._kick( reason )
end

You’re using a .wav with PlayURL, which is for web URLs.

Just for the heads up, wrap your code in


 tags.

Anyways, just override the original ban function;



local meta = FindMetaTable( “Player” )
local OldBan = meta:Ban

local function playSound( )
BroadcastLua ( “sound.PlayURL ( '” … song … “’, ‘’, function() end” )
end

function meta:Ban(min, kick)
playSound()

 OldBan(min, kick)

end


Like this?

local song = “siege/jihad.wav”

meta._ban = meta._ban or meta.Ban
meta._kick = meta._kick or meta.Kick

local meta = FindMetaTable( “Player” )
local OldBan = meta:Ban

local function playSound( )
BroadcastLua ( “sound.PlayURL ( '” … song … “’, ‘’, function() end” )
end

function meta:Ban(min, kick)
playSound()

 OldBan(min, kick)

end

meta:Ban will error since you’re sending in a player argument with :

[editline]6th April 2015[/editline]

You should use surface.PlaySound instead

I got this error [ERROR] lua/autorun/ban.lua:8: function arguments expected near ‘local’

  1. unknown - lua/autorun/ban.lua:0

[editline]5th April 2015[/editline]

Here’s my current code

local song = “https://www.youtube.com/watch?v=IGQBtbKSVhY

meta._ban = meta._ban or meta.Ban

local meta = FindMetaTable( “Player” )
local OldBan = meta:Ban

local function playSound( )
BroadcastLua ( “sound.PlayURL ( '” … song … “’, ‘’, function() end” )
end

function meta:Ban(min, kick)
playSound()

 OldBan(min, kick)

end

Here’s my current issue -

[ERROR] lua/autorun/ban.lua:8: function arguments expected near ‘local’

  1. unknown - lua/autorun/ban.lua:0

Like I said, don’t use the OldBan thing

Can you just code what I need to put into the file? Because I’m quite confused being 1:12AM.


local song = "https://www.youtube.com/watch?v=IGQBtbKSVhY" -- Test with http and https

local RunSong = "sound.PlayURL( '" .. song .. "', '', function() end )"

local meta = FindMetaTable( "Player" )

meta.OldBan = meta.OldBan or meta.Ban

local function playSound()
   BroadcastLua( RunSong )
end

function meta:Ban( min, kick )
   playSound()

   meta.OldBan( min, kick )
end

You’re lucky code_gs is so nice.
Next time don’t be so lazy - this is Developer Discussion, not Developer Slaves (although sometimes it doesn’t feel that way :suicide:).

Considering I provided the code he posted, I might as well make sure he doesnt use it wrong.

This code works by having the siege/jihad in GarrysMod/garrysmod/sound/siege/jihad.wav

[lua]local meta = FindMetaTable( “Player” )
local sound = “siege/jihad.wav”

meta._ban = meta._ban or meta.Ban
meta._kick = meta._kick or meta.Kick

local function playSound( )
BroadcastLua ( “surface.PlaySound ( '” … sound … “’)” )
end

function meta:Ban( minutes, kick )
playSound()
self._ban( minutes, kick )
end

function meta:Kick( reason )
playSound()
self._kick( reason )
end[/lua]

Thank you Code_gs and Author, I’m trying them out now to see which will work. You guys really helped. c:

Both will work; depends if you want to use a file or URL.

The URL one didn’t work for me. I tried it and it doesn’t play the URL. After that I changed the https to a http and it didn’t work again. And for the File one, It plays the noise when banning some one. But it doesn’t ban them.

In his other thread, he stated that he was using ULX. Note that if he’s using ULX, the ULib.addban function does not use Player:Ban(). It adds the ban to its own data file, puts it in a table, and bans the ID by using game.ConsoleCommand('banid '…ply:SteamID()). Therefore, overridding the Player:Ban() function to play a sound when somebody is banned will not work when people use the !ban or !banid command.

To make this work, you’d have to put it into the commands or the actual ban functions. The commands are located in lua/ulx/modules/sh/util.lua, and the ban functions are all located in lua/ulib/server/player.lua. I would add this to the ULib.addban function myself, but you can also add it to the ban commands.

Erm, I’m trying to figure this out xD. Sorry I’m new at lua and what not.

Well, Author and code_gs gave you some code that plays a sound to everyone in the server, right? I gave you the location of the file that has the ban function, and told you which function would be called whenever someone is banned via ULX. The player.lua file I told you about is run serverside , so BroadcastLua will still work. Let’s put two and two together here and put the code to play a sound in the function that adds the player to the bans list.

That’s because the url is a video, not an MP3

Yea, I know it is code. But It still didn’t work for me. and it’s <dir> is in Garrysmod/lua/autorun

My code overwrote both Kick and Ban, and ULX runs kick on the player.