Author Topic: Writing a votegag command. I'm very new to lua and need help!  (Read 3160 times)

0 Members and 1 Guest are viewing this topic.

Offline CallMePyro

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
Writing a votegag command. I'm very new to lua and need help!
« on: September 29, 2013, 10:31:54 AM »
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:

Code: [Select]
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

Code: [Select]
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


Code: [Select]
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. 
« Last Edit: September 29, 2013, 10:33:35 AM by CallMePyro »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Writing a votegag command. I'm very new to lua and need help!
« Reply #1 on: September 29, 2013, 12:50:08 PM »
Just need to do "target.ulx_gagged = true".
Experiencing God's grace one day at a time.

Offline CallMePyro

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
Re: Writing a votegag command. I'm very new to lua and need help!
« Reply #2 on: September 29, 2013, 02:16:22 PM »
Thank you very much! I was looking for a solution and you gave me one :) many thanks

Offline HazCP

  • Newbie
  • *
  • Posts: 13
  • Karma: 0
  • Founder of KGN
Re: Writing a votegag command. I'm very new to lua and need help!
« Reply #3 on: September 17, 2014, 09:54:05 AM »
Where would one put "target.ulx_gagged = true" in the code, for it to work?

Thanks