Hey. I'm trying to make the banid command play a sound when it is used. I am having trouble figuring out how to do that.
Here is the code for the default command found in the ULX files.
[CODE]function ulx.banid( calling_ply, steamid, minutes, reason )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end
local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end
local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A banned steamid #s "
displayid = steamid
if name then
displayid = displayid .. "(" .. name .. ") "
end
str = str .. time
if reason and reason ~= "" then str = str .. " (#4s)" end
ulx.fancyLogAdmin( calling_ply, str, displayid, minutes ~= 0 and minutes or reason, reason )
-- Delay by 1 frame to ensure any chat hook finishes with player intact. Prevents a crash.
ULib.queueFunctionCall( ULib.addBan, steamid, minutes, reason, name, calling_ply )
end
local banid = ulx.command( CATEGORY_NAME, "ulx banid", ulx.banid )
banid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
banid:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
banid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
banid:defaultAccess( ULib.ACCESS_SUPERADMIN )
banid:help( "Bans steamid." )[/CODE]
My apologies for being a complete Lua Noob.
[CODE]
local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end
[/CODE]
Paste this:
[CODE] for k, v in pairs(plys) do
v:SendLua([[surface.PlaySound("REPLACEME.mp3")]])
end[/CODE]
[B]Of course replace the "REPLACEME.mp3" with the directory of the sound you are wanting to play[/B]. If someone else has a better way of playing sounds directly and server sided, [U]hit me with some knowledge brotha[/U].
Complete Code:
[CODE]function ulx.banid( calling_ply, steamid, minutes, reason )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end
local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end
for k, v in pairs(plys) do
v:SendLua([[surface.PlaySound("REPLACEME.mp3")]])
end
local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A banned steamid #s "
displayid = steamid
if name then
displayid = displayid .. "(" .. name .. ") "
end
str = str .. time
if reason and reason ~= "" then str = str .. " (#4s)" end
ulx.fancyLogAdmin( calling_ply, str, displayid, minutes ~= 0 and minutes or reason, reason )
-- Delay by 1 frame to ensure any chat hook finishes with player intact. Prevents a crash.
ULib.queueFunctionCall( ULib.addBan, steamid, minutes, reason, name, calling_ply )
end
local banid = ulx.command( CATEGORY_NAME, "ulx banid", ulx.banid )
banid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
banid:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
banid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
banid:defaultAccess( ULib.ACCESS_SUPERADMIN )
banid:help( "Bans steamid." )[/CODE]
*EDIT*: Lel I got rated [I]Dumb[/I] for helping? That's a first xD
Thank you a ton. Worked like a charm.
[QUOTE=DrunkSquirrel;46622245][CODE]
local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end
[/CODE]
Paste this:
[CODE] for k, v in pairs(plys) do
v:SendLua([[surface.PlaySound("REPLACEME.mp3")]])
end[/CODE]
[B]Of course replace the "REPLACEME.mp3" with the directory of the sound you are wanting to play[/B]. If someone else has a better way of playing sounds directly and server sided, [U]hit me with some knowledge brotha[/U].
Complete Code:
[CODE]function ulx.banid( calling_ply, steamid, minutes, reason )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end
local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end
for k, v in pairs(plys) do
v:SendLua([[surface.PlaySound("REPLACEME.mp3")]])
end
local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A banned steamid #s "
displayid = steamid
if name then
displayid = displayid .. "(" .. name .. ") "
end
str = str .. time
if reason and reason ~= "" then str = str .. " (#4s)" end
ulx.fancyLogAdmin( calling_ply, str, displayid, minutes ~= 0 and minutes or reason, reason )
-- Delay by 1 frame to ensure any chat hook finishes with player intact. Prevents a crash.
ULib.queueFunctionCall( ULib.addBan, steamid, minutes, reason, name, calling_ply )
end
local banid = ulx.command( CATEGORY_NAME, "ulx banid", ulx.banid )
banid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
banid:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
banid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
banid:defaultAccess( ULib.ACCESS_SUPERADMIN )
banid:help( "Bans steamid." )[/CODE][/QUOTE]
So this works like a charm. I am trying to add the code to play sounds to other commands but it seems to not be working.
Probably because he re-used plys as it was already there.
use player.GetAll() instead of plys
[QUOTE=Blasteh;46627441]Probably because he re-used plys as it was already there.
use player.GetAll() instead of plys[/QUOTE]
I'm trying to add a new sound for Gag.
[CODE]function ulx.gag( calling_ply, target_plys, should_ungag )
local players = player.GetAll()
for i=1, #target_plys do
local v = target_plys[ i ]
v.ulx_gagged = not should_ungag
v:SetNWBool("ulx_gagged", v.ulx_gagged)
end
if not should_ungag then
ulx.fancyLogAdmin( calling_ply, "#A gagged #T", target_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys )
end
end
local gag = ulx.command( CATEGORY_NAME, "ulx gag", ulx.gag, "!gag" )
gag:addParam{ type=ULib.cmds.PlayersArg }
gag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
gag:defaultAccess( ULib.ACCESS_ADMIN )
gag:help( "Gag target(s), disables microphone." )
gag:setOpposite( "ulx ungag", {_, _, true}, "!ungag" )
local function gagHook( listener, talker )
if talker.ulx_gagged then
return false
end
end
hook.Add( "PlayerCanHearPlayersVoice", "ULXGag", gagHook )[/CODE]
I tried to add what you said but It doesn't seem to be working. I'm trying to add it after this part:
[CODE]function ulx.gag( calling_ply, target_plys, should_ungag )
local players = player.GetAll()
for i=1, #target_plys do
local v = target_plys[ i ]
v.ulx_gagged = not should_ungag
v:SetNWBool("ulx_gagged", v.ulx_gagged)
end
if not should_ungag then
ulx.fancyLogAdmin( calling_ply, "#A gagged #T", target_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys )
end
end[/CODE]
I am getting this error
[ERROR] addons/ulx/lua/ulx/modules/sh/chat.lua:242: bad argument #1 to 'pairs' (table expected, got nil)
1. pairs - [C]:-1
2. unknown - addons/ulx/lua/ulx/modules/sh/chat.lua:242
Okay bruh, it seems like you don't understand the example above. [U]Please[/U] check out the [B][URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index69db.html"]Garry's Mod Lua wiki[/URL][/B] (that links to the [B]OLD OLD WIKI[/B], [U]but it has valuable information to you[/U]!)
Example:
[code]
for k, v in pairs(player.GetAll()) do --Get all the players in no particular sequence
v:SendLua([[surface.PlaySound("PATH/TO/SOUND.mp3")]]) --For every player, send lua to client and play "PATH/TO/SOUND.mp3"
end
[/code]
[QUOTE=DrunkSquirrel;46629881]Okay bruh, it seems like you don't understand the example above. [U]Please[/U] check out the [B][URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index69db.html"]Garry's Mod Lua wiki[/URL][/B] (that links to the [B]OLD OLD WIKI[/B], [U]but it has valuable information to you[/U]!)
Example:
[code]
for k, v in pairs(player.GetAll()) do --Get all the players in no particular sequence
v:SendLua([[surface.PlaySound("PATH/TO/SOUND.mp3")]]) --For every player, send lua to client and play "PATH/TO/SOUND.mp3"
end
[/code][/QUOTE]
I'm just having troubles on where to add it in the commands. It seems when I try to add it elsewhere even changing it to player.GetAll() I either break the command or get a lua error for pairs.
[QUOTE=aeliann;46629920]I'm just having troubles on where to add it in the commands. It seems when I try to add it elsewhere even changing it to player.GetAll() I either break the command or get a lua error for pairs.[/QUOTE]
If you are doing this on a server, after making any changes, be safe and restart the map to continue to check your progressive errors.
You must add it in the order the function is executed.. kind of like reading from top to bottom. For example:
[code]
function ulx.gag( calling_ply, target_plys, should_ungag )
local players = player.GetAll()
for i=1, #target_plys do
local v = target_plys[ i ]
v.ulx_gagged = not should_ungag
v:SetNWBool("ulx_gagged", v.ulx_gagged)
end
for k, v in pairs(player.GetAll()) do
v:SendLua([[surface.PlaySound("REPLACEME.mp3")]])
end
if not should_ungag then
ulx.fancyLogAdmin( calling_ply, "#A gagged #T", target_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys )
end
end
[/code]
The above would be [U]executed[/U] whether the person was already [B]gagged[/B] or not.
[QUOTE=DrunkSquirrel;46629992]If you are doing this on a server, after making any changes, be safe and restart the map to continue to check your progressive errors.
You must add it in the order the function is executed.. kind of like reading from top to bottom. For example:
[code]
function ulx.gag( calling_ply, target_plys, should_ungag )
local players = player.GetAll()
for i=1, #target_plys do
local v = target_plys[ i ]
v.ulx_gagged = not should_ungag
v:SetNWBool("ulx_gagged", v.ulx_gagged)
end
for k, v in pairs(player.GetAll()) do
v:SendLua([[surface.PlaySound("REPLACEME.mp3")]])
end
if not should_ungag then
ulx.fancyLogAdmin( calling_ply, "#A gagged #T", target_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys )
end
end
[/code]
The above would be [U]executed[/U] whether the person was already [B]gagged[/B] or not.[/QUOTE]
I'm starting to see where I have been going wrong now. Thank you very much.
Will the REPLACEME.mp3
be in material?
[QUOTE=Chokitu;46631087]Will the REPLACEME.mp3
be in material?[/QUOTE]
Elaborate please.
[QUOTE=Chokitu;46631087]Will the REPLACEME.mp3
be in material?[/QUOTE]
Path to the sound, like "item/cart_explode.wav" (this is just an example)
[QUOTE=Chokitu;46631087]Will the REPLACEME.mp3
be in material?[/QUOTE]
No, it will be in sound/
[QUOTE=MeepDarknessM;46636017]No, it will be in sounds/
(or sound I forget which so correct me if i am wrong)[/QUOTE]
it's [B]"sound/"[/B], yep... I make the same mistake a lot when im actually writing code out
Sorry, you need to Log In to post a reply to this thread.