Writing a votegag command for ULX. I'm very new to lua and need help!

First off, I’ve searched the internet and read everything on this website relevant to the “gag” command and how to stop players from voice chatting in Gmod. Unfortunately I was not able to find anything helpful, at least for my skill level.

I decided to try and write a votegag command for my server. I can get the entire voting process working up until I actually need to execute the gagging on the player. I can’t figure out how to do that. Can anyone help?

Here’s what I’ve written so far:


local function voteGagDone2( t, target, time, ply, reason )
	local shouldGag = false

	if t.results[ 1 ] and t.results[ 1 ] > 0 then
		ulx.logUserAct( ply, target, "#A approved the votegag against #T (" .. (reason or "") .. ")" )
		shouldGag = true
	else
		ulx.logUserAct( ply, target, "#A denied the votegag against #T" )
	end

	if shouldGag then
		ULib.tsay( _, "Player " .. target:Nick() .. " has been gagged." ) -- This is where the command is actually executed on the player.
	end
end



local function voteGagDone( t, target, time, ply, reason )
	local results = t.results
	local winner
	local winnernum = 0
	for id, numvotes in pairs( results ) do
		if numvotes > winnernum then
			winner = id
			winnernum = numvotes
		end
	end

	local ratioNeeded = GetConVarNumber( "ulx_votegagSuccessratio" )
	local minVotes = GetConVarNumber( "ulx_votegagMinvotes" )
	local str
	if winner ~= 1 or winnernum < minVotes or winnernum / t.voters < ratioNeeded then
		str = "Vote results: User will not be gagged. (" .. (results[ 1 ] or "0") .. "/" .. t.voters .. ")"
	else
		str = "Vote results: User will now be gagged, pending approval. (" .. winnernum .. "/" .. t.voters .. ")"
		ulx.doVote( "Accept result and gag " .. target:Nick() .. "?", { "Yes", "No" }, voteGagDone2, 30000, { ply }, true, target, time, ply, reason )
	end



function ulx.votegag( calling_ply, target_ply, reason )
	if voteInProgress then
		ULib.tsayError( calling_ply, "There is already a vote in progress. Please wait for the current one to end.", true )
		return
	end

	local msg = "Gag " .. target_ply:Nick() .. "?"
	if reason and reason ~= "" then
		msg = msg .. " (" .. reason .. ")"
	end

	ulx.doVote( msg, { "Yes", "No" }, voteGagDone, _, _, _, target_ply, time, calling_ply, reason )
	ulx.fancyLogAdmin( calling_ply, "#A started a votegag against #T", target_ply )
end
local votekick = ulx.command( CATEGORY_NAME, "ulx votegag", ulx.votegag, "!votegag" )
votekick:addParam{ type=ULib.cmds.PlayerArg }
votekick:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine }
votekick:defaultAccess( ULib.ACCESS_ADMIN )
votekick:help( "Starts a public gag vote against target." )
if SERVER then ulx.convar( "votegagSuccessratio", "0", _, ULib.ACCESS_ADMIN ) end -- The ratio needed for a votegag to succeed
if SERVER then ulx.convar( "votegagMinvotes", "1", _, ULib.ACCESS_ADMIN ) end -- Minimum votes needed for votegag



Edit for more info: Everything runs correctly and there are no errors, I simply cannot figure out how to get the actual ULX gag command to run on the player. I will get errors like “attempt to get length of local ‘target_plys’ (a nil value)” and I haven’t even been able to find any kind of documentation for that error online.

Anyone have any ideas? I’m dyin’ here

[editline]29th September 2013[/editline]

Never mind. I’ve figured it out, an admin can close this thread if they so desire.