I have edited Luk0r's map reset vote to do what I wanted. Basically they just toggle sbox_playergod, sbox_noclip, and sbox_plpldamage. I wish I could condense this code into one file but my knowledge of Lua is very limited. If it was one file, only one vote request could run at a time. For instance, if it was currently a fighting environment (default) only the /votebuild command would work. I would also like it to advertise only the enabled vote command. This way it would be simple and conflicts would be kept to a minimum.
So if you guys can check it out and make suggestions, that would be great! Code below.
/lua/autorun/VoteBuild.lua
/*
Name: Vote Build
Version: 0.0
Author: [atomicspark] - www.atomicsparkonline.net
Original Code: Luk0r - luk0r@luk0r.net
For: Garry's Mod v10
*/
vb = {}; vb.Settings = {}; vb.VotedFor = {}
// Configure these variables to suit your needs, the defaults will probably be fine though
vb.Settings.advertise = false // Advertise the script?
vb.Settings.advdelay = 300 // Delay in seconds between advertising.
vb.Settings.trigger = "/votebuild" // The chat trigger to begin a vote.
vb.Settings.votetrig = "/vote" // Trigger to vote for the map reset (used when a vote is taking place)
vb.Settings.votetimer = 30 // How long players have to vote.
vb.Settings.majority = 60 // The majority of votes required for a reset in percent.
// Main code block
if CLIENT then return nil end
function vb.sendNotify( ply, text, sound, notifytype )
ply:SendLua("GAMEMODE:AddNotify(\"" .. text .. "\", " .. notifytype .. ", 5); surface.PlaySound( \"" .. sound .. "\" )")
end
function vb.checkForVoteTrigger( ply, txt )
if vb.votetakingplace == 0 then
if string.find( txt, vb.Settings.trigger ) then
vb.votetakingplace = 1
vb.votesfor = 1
table.insert( vb.VotedFor, ply:SteamID() )
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vb.sendNotify( plyr, ply:Nick() .. " has requested a building environment!", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
plyr:PrintMessage( HUD_PRINTTALK, "Type " .. vb.Settings.votetrig .. " to vote for the map reset.\n" )
plyr:PrintMessage( HUD_PRINTTALK, "Type nothing if you disagree.\n" )
end
vb.votereminder = vb.Settings.votetimer
vb.votereminderchunk = math.Round( vb.votereminder / 3 )
timer.Create( "vb.RemindPlayersOfVote", vb.votereminderchunk, 3, vb.voteTimerCheck )
timer.Create( "vb.EndOfVote", vb.Settings.votetimer, 1, vb.voteEnded )
return ""
end
else
if string.find( txt, vb.Settings.trigger ) then
vb.sendNotify( ply, "A building environment vote is already running!", "buttons/button2.wav", "NOTIFY_ERROR" )
return ""
else
if string.find( txt, vb.Settings.votetrig ) then
for i, vfornick in ipairs( vb.VotedFor ) do
if vfornick == ply:SteamID() then
vb.sendNotify( ply, "You have already voted!", "buttons/button2.wav", "NOTIFY_ERROR" )
return ""
end
end
vb.votesfor = vb.votesfor + 1
vb.sendNotify( ply, "You have voted for a building environment.", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
table.insert( vb.VotedFor, ply:SteamID() )
local players = player.GetAll()
for i, plyr in ipairs( players ) do
plyr:PrintMessage( HUD_PRINTTALK, ply:Nick() .. " has voted for a building environment.\n" )
end
return ""
end
end
end
end
function vb.voteTimerCheck()
vb.votereminder = vb.votereminder - vb.votereminderchunk
if vb.votereminder > 0 then
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vb.sendNotify( plyr, "Around " .. vb.votereminder .. " seconds remaining on the building environment vote!", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
end
end
end
function vb.voteEnded()
playersonserver = 0
local players = player.GetAll()
for i, v in ipairs( players ) do
playersonserver = playersonserver + 1
end
local majorityplayers = math.ceil( ( playersonserver * vb.Settings.majority ) / 100 )
if vb.votesfor >= majorityplayers then
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vb.sendNotify( plyr, "The building environment vote has succeeded, the map will now reset.", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
end
timer.Simple( 3, vb.enableBuild )
else
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vb.sendNotify( plyr, "The building environment vote has failed.", "buttons/button2.wav", "NOTIFY_ERROR" )
end
vb.VotedFor = {}
vb.votetakingplace = 0
vb.votesfor = 0
end
end
function vb.enableBuild()
// game.ConsoleCommand( "changelevel " .. game.GetMap() .. "\n" )
game.ConsoleCommand( "sbox_playergod " .. "1" .. "\n" )
game.ConsoleCommand( "sbox_noclip " .. "1" .. "\n" )
game.ConsoleCommand( "sbox_plpldamage " .. "1" .. "\n" )
end
function vb.advertise()
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vb.sendNotify( plyr, "To begin a building environment vote, type " .. vb.Settings.trigger .. " in chat.", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
end
end
if vb.Settings.advertise == true then
timer.Create( "vb.Advertise", vb.Settings.advdelay, 0, vb.advertise )
end
vb.votetakingplace = 0 // Don't change these
vb.votesfor = 0
hook.Add( "PlayerSay", "vb.CheckForVoteTrigger", vb.checkForVoteTrigger )
/lua/autorun/VoteFight.lua
/*
Name: Vote Fight
Version: 0.0
Author: [atomicspark] - www.atomicsparkonline.net
Original Code: Luk0r - luk0r@luk0r.net
For: Garry's Mod v10
*/
vf = {}; vf.Settings = {}; vf.VotedFor = {}
// Configure these variables to suit your needs, the defaults will probably be fine though
vf.Settings.advertise = false // Advertise the script?
vf.Settings.advdelay = 300 // Delay in seconds between advertising.
vf.Settings.trigger = "/votefight" // The chat trigger to begin a vote.
vf.Settings.votetrig = "/vote" // Trigger to vote for the map reset (used when a vote is taking place)
vf.Settings.votetimer = 30 // How long players have to vote.
vf.Settings.majority = 60 // The majority of votes required for a reset in percent.
// Main code block
if CLIENT then return nil end
function vf.sendNotify( ply, text, sound, notifytype )
ply:SendLua("GAMEMODE:AddNotify(\"" .. text .. "\", " .. notifytype .. ", 5); surface.PlaySound( \"" .. sound .. "\" )")
end
function vf.checkForVoteTrigger( ply, txt )
if vf.votetakingplace == 0 then
if string.find( txt, vf.Settings.trigger ) then
vf.votetakingplace = 1
vf.votesfor = 1
table.insert( vf.VotedFor, ply:SteamID() )
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vf.sendNotify( plyr, ply:Nick() .. " has requested a fighting environment!", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
plyr:PrintMessage( HUD_PRINTTALK, "Type " .. vf.Settings.votetrig .. " to vote for the map reset.\n" )
plyr:PrintMessage( HUD_PRINTTALK, "Type nothing if you disagree.\n" )
end
vf.votereminder = vf.Settings.votetimer
vf.votereminderchunk = math.Round( vf.votereminder / 3 )
timer.Create( "vf.RemindPlayersOfVote", vf.votereminderchunk, 3, vf.voteTimerCheck )
timer.Create( "vf.EndOfVote", vf.Settings.votetimer, 1, vf.voteEnded )
return ""
end
else
if string.find( txt, vf.Settings.trigger ) then
vf.sendNotify( ply, "A fighting environment vote is already running!", "buttons/button2.wav", "NOTIFY_ERROR" )
return ""
else
if string.find( txt, vf.Settings.votetrig ) then
for i, vfornick in ipairs( vf.VotedFor ) do
if vfornick == ply:SteamID() then
vf.sendNotify( ply, "You have already voted!", "buttons/button2.wav", "NOTIFY_ERROR" )
return ""
end
end
vf.votesfor = vf.votesfor + 1
vf.sendNotify( ply, "You have voted for a fighting environment.", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
table.insert( vf.VotedFor, ply:SteamID() )
local players = player.GetAll()
for i, plyr in ipairs( players ) do
plyr:PrintMessage( HUD_PRINTTALK, ply:Nick() .. " has voted for a fighting environment.\n" )
end
return ""
end
end
end
end
function vf.voteTimerCheck()
vf.votereminder = vf.votereminder - vf.votereminderchunk
if vf.votereminder > 0 then
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vf.sendNotify( plyr, "Around " .. vf.votereminder .. " seconds remaining on the fighting environment vote!", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
end
end
end
function vf.voteEnded()
playersonserver = 0
local players = player.GetAll()
for i, v in ipairs( players ) do
playersonserver = playersonserver + 1
end
local majorityplayers = math.ceil( ( playersonserver * vf.Settings.majority ) / 100 )
if vf.votesfor >= majorityplayers then
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vf.sendNotify( plyr, "The fighting environment vote has succeeded, PvP damage enabled and noclip disabled.", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
end
timer.Simple( 3, vf.enableFight )
else
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vf.sendNotify( plyr, "The fighting environment vote has failed.", "buttons/button2.wav", "NOTIFY_ERROR" )
end
vf.VotedFor = {}
vf.votetakingplace = 0
vf.votesfor = 0
end
end
function vf.enableFight()
game.ConsoleCommand( "sbox_playergod " .. "0" .. "\n" )
game.ConsoleCommand( "sbox_noclip " .. "0" .. "\n" )
game.ConsoleCommand( "sbox_plpldamage " .. "0" .. "\n" )
end
function vf.advertise()
local players = player.GetAll()
for i, plyr in ipairs( players ) do
vf.sendNotify( plyr, "To begin a fighting environment vote, type " .. vf.Settings.trigger .. " in chat.", "ambient/water/drip" .. math.random(1, 4) .. ".wav", "NOTIFY_GENERIC" )
end
end
if vf.Settings.advertise == true then
timer.Create( "vf.Advertise", vf.Settings.advdelay, 0, vf.advertise )
end
vf.votetakingplace = 0 // Don't change these
vf.votesfor = 0
hook.Add( "PlayerSay", "vf.CheckForVoteTrigger", vf.checkForVoteTrigger )