drop custom changes
- ulx votemap timer can break at times and cause instant map change - switched to ulx github so chat modifications would have to be applied there
This commit is contained in:
parent
1af71252f9
commit
7f7819b3a9
@ -1,26 +0,0 @@
|
||||
|
||||
local function svotemap()
|
||||
local votemap = GetConVar("ulx_votemapminvotes")
|
||||
local votemap2 = GetConVar("ulx_votemap2minvotes")
|
||||
|
||||
if ((votemap ~= nil) and (votemap2 ~= nil)) then
|
||||
local plys = player.GetHumans()
|
||||
|
||||
if #plys == 2 then
|
||||
votemap:SetInt(2)
|
||||
votemap2:SetInt(2)
|
||||
elseif #plys <= 1 then
|
||||
votemap:SetInt(1)
|
||||
votemap2:SetInt(1)
|
||||
else
|
||||
votemap:SetInt(3)
|
||||
votemap2:SetInt(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
gameevent.Listen("player_connect")
|
||||
gameevent.Listen("player_disconnect")
|
||||
|
||||
hook.Add("player_connect", "edshot_svotemap_connect", function() svotemap() end)
|
||||
hook.Add("player_disconnect", "edshot_svotemap_disconnect", function() svotemap() end)
|
@ -1,331 +0,0 @@
|
||||
-- This module holds any type of chatting functions
|
||||
CATEGORY_NAME = "Chat"
|
||||
|
||||
------------------------------ Psay ------------------------------
|
||||
function ulx.psay( calling_ply, target_ply, message )
|
||||
if calling_ply:GetNWBool( "ulx_muted", false ) then
|
||||
ULib.tsayError( calling_ply, "You are muted, and therefore cannot speak! Use asay for admin chat if urgent.", true )
|
||||
return
|
||||
end
|
||||
|
||||
ulx.fancyLog( { target_ply, calling_ply }, "#P to #P: " .. message, calling_ply, target_ply )
|
||||
end
|
||||
local psay = ulx.command( CATEGORY_NAME, "ulx psay", ulx.psay, "!p", true )
|
||||
psay:addParam{ type=ULib.cmds.PlayerArg, target="!^", ULib.cmds.ignoreCanTarget }
|
||||
psay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
|
||||
psay:defaultAccess( ULib.ACCESS_ALL )
|
||||
psay:help( "Send a private message to target." )
|
||||
local psay2 = ulx.command( CATEGORY_NAME, "ulx psay", ulx.psay, "!pm", true )
|
||||
psay2:addParam{ type=ULib.cmds.PlayerArg, target="!^", ULib.cmds.ignoreCanTarget }
|
||||
psay2:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
|
||||
psay2:defaultAccess( ULib.ACCESS_ALL )
|
||||
psay2:help( "Send a private message to target." )
|
||||
local psay3 = ulx.command( CATEGORY_NAME, "ulx psay", ulx.psay, "!psay", true )
|
||||
psay3:addParam{ type=ULib.cmds.PlayerArg, target="!^", ULib.cmds.ignoreCanTarget }
|
||||
psay3:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
|
||||
psay3:defaultAccess( ULib.ACCESS_ALL )
|
||||
psay3:help( "Send a private message to target." )
|
||||
|
||||
------------------------------ Asay ------------------------------
|
||||
local seeasayAccess = "ulx seeasay"
|
||||
if SERVER then ULib.ucl.registerAccess( seeasayAccess, ULib.ACCESS_OPERATOR, "Ability to see 'ulx asay'", "Other" ) end -- Give operators access to see asays echoes by default
|
||||
|
||||
function ulx.asay( calling_ply, message )
|
||||
local format
|
||||
local me = "/me "
|
||||
if message:sub( 1, me:len() ) == me then
|
||||
format = "(ADMINS) *** #P #s"
|
||||
message = message:sub( me:len() + 1 )
|
||||
else
|
||||
format = "#P to admins: #s"
|
||||
end
|
||||
|
||||
local players = player.GetAll()
|
||||
for i=#players, 1, -1 do
|
||||
local v = players[ i ]
|
||||
if not ULib.ucl.query( v, seeasayAccess ) and v ~= calling_ply then -- Calling player always gets to see the echo
|
||||
table.remove( players, i )
|
||||
end
|
||||
end
|
||||
|
||||
ulx.fancyLog( players, format, calling_ply, message )
|
||||
end
|
||||
local asay = ulx.command( CATEGORY_NAME, "ulx asay", ulx.asay, "@", true, true )
|
||||
asay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
|
||||
asay:defaultAccess( ULib.ACCESS_ALL )
|
||||
asay:help( "Send a message to currently connected admins." )
|
||||
|
||||
------------------------------ Tsay ------------------------------
|
||||
function ulx.tsay( calling_ply, message )
|
||||
ULib.tsay( _, message )
|
||||
|
||||
if ULib.toBool( GetConVarNumber( "ulx_logChat" ) ) then
|
||||
ulx.logString( string.format( "(tsay from %s) %s", calling_ply:IsValid() and calling_ply:Nick() or "Console", message ) )
|
||||
end
|
||||
end
|
||||
local tsay = ulx.command( CATEGORY_NAME, "ulx tsay", ulx.tsay, "@@", true, true )
|
||||
tsay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
|
||||
tsay:defaultAccess( ULib.ACCESS_ADMIN )
|
||||
tsay:help( "Send a message to everyone in the chat box." )
|
||||
|
||||
------------------------------ Csay ------------------------------
|
||||
function ulx.csay( calling_ply, message )
|
||||
ULib.csay( _, message )
|
||||
|
||||
if ULib.toBool( GetConVarNumber( "ulx_logChat" ) ) then
|
||||
ulx.logString( string.format( "(csay from %s) %s", calling_ply:IsValid() and calling_ply:Nick() or "Console", message ) )
|
||||
end
|
||||
end
|
||||
local csay = ulx.command( CATEGORY_NAME, "ulx csay", ulx.csay, "@@@", true, true )
|
||||
csay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
|
||||
csay:defaultAccess( ULib.ACCESS_ADMIN )
|
||||
csay:help( "Send a message to everyone in the middle of their screen." )
|
||||
|
||||
------------------------------ Thetime ------------------------------
|
||||
local waittime = 60
|
||||
local lasttimeusage = -waittime
|
||||
function ulx.thetime( calling_ply )
|
||||
if lasttimeusage + waittime > CurTime() then
|
||||
ULib.tsayError( calling_ply, "I just told you what time it is! Please wait " .. waittime .. " seconds before using this command again", true )
|
||||
return
|
||||
end
|
||||
|
||||
lasttimeusage = CurTime()
|
||||
ulx.fancyLog( "The time is now #s.", os.date( "%I:%M %p") )
|
||||
end
|
||||
local thetime = ulx.command( CATEGORY_NAME, "ulx thetime", ulx.thetime, "!thetime" )
|
||||
thetime:defaultAccess( ULib.ACCESS_ALL )
|
||||
thetime:help( "Shows you the server time." )
|
||||
|
||||
|
||||
------------------------------ Adverts ------------------------------
|
||||
ulx.adverts = ulx.adverts or {}
|
||||
local adverts = ulx.adverts -- For XGUI, too lazy to change all refs
|
||||
|
||||
local function doAdvert( group, id )
|
||||
|
||||
if adverts[ group ][ id ] == nil then
|
||||
if adverts[ group ].removed_last then
|
||||
adverts[ group ].removed_last = nil
|
||||
id = 1
|
||||
else
|
||||
id = #adverts[ group ]
|
||||
end
|
||||
end
|
||||
|
||||
local info = adverts[ group ][ id ]
|
||||
|
||||
local message = string.gsub( info.message, "%%curmap%%", game.GetMap() )
|
||||
message = string.gsub( message, "%%host%%", GetConVarString( "hostname" ) )
|
||||
message = string.gsub( message, "%%ulx_version%%", ULib.pluginVersionStr( "ULX" ) )
|
||||
|
||||
if not info.len then -- tsay
|
||||
local lines = ULib.explode( "\\n", message )
|
||||
|
||||
for i, line in ipairs( lines ) do
|
||||
local trimmed = line:Trim()
|
||||
if trimmed:len() > 0 then
|
||||
ULib.tsayColor( _, true, info.color, trimmed ) -- Delaying runs one message every frame (to ensure correct order)
|
||||
end
|
||||
end
|
||||
else
|
||||
ULib.csay( _, message, info.color, info.len )
|
||||
end
|
||||
|
||||
ULib.queueFunctionCall( function()
|
||||
local nextid = math.fmod( id, #adverts[ group ] ) + 1
|
||||
timer.Remove( "ULXAdvert" .. type( group ) .. group )
|
||||
timer.Create( "ULXAdvert" .. type( group ) .. group, adverts[ group ][ nextid ].rpt, 1, function() doAdvert( group, nextid ) end )
|
||||
end )
|
||||
end
|
||||
|
||||
-- Whether or not it's a csay is determined by whether there's a value specified in "len"
|
||||
function ulx.addAdvert( message, rpt, group, color, len )
|
||||
local t
|
||||
|
||||
if group then
|
||||
t = adverts[ tostring( group ) ]
|
||||
if not t then
|
||||
t = {}
|
||||
adverts[ tostring( group ) ] = t
|
||||
end
|
||||
else
|
||||
group = table.insert( adverts, {} )
|
||||
t = adverts[ group ]
|
||||
end
|
||||
|
||||
local id = table.insert( t, { message=message, rpt=rpt, color=color, len=len } )
|
||||
|
||||
if not timer.Exists( "ULXAdvert" .. type( group ) .. group ) then
|
||||
timer.Create( "ULXAdvert" .. type( group ) .. group, rpt, 1, function() doAdvert( group, id ) end )
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------ Gimp ------------------------------
|
||||
ulx.gimpSays = ulx.gimpSays or {} -- Holds gimp says
|
||||
local gimpSays = ulx.gimpSays -- For XGUI, too lazy to change all refs
|
||||
local ID_GIMP = 1
|
||||
local ID_MUTE = 2
|
||||
|
||||
function ulx.addGimpSay( say )
|
||||
table.insert( gimpSays, say )
|
||||
end
|
||||
|
||||
function ulx.clearGimpSays()
|
||||
table.Empty( gimpSays )
|
||||
end
|
||||
|
||||
function ulx.gimp( calling_ply, target_plys, should_ungimp )
|
||||
for i=1, #target_plys do
|
||||
local v = target_plys[ i ]
|
||||
if should_ungimp then
|
||||
v.gimp = nil
|
||||
else
|
||||
v.gimp = ID_GIMP
|
||||
end
|
||||
v:SetNWBool("ulx_gimped", not should_ungimp)
|
||||
end
|
||||
|
||||
if not should_ungimp then
|
||||
ulx.fancyLogAdmin( calling_ply, "#A gimped #T", target_plys )
|
||||
else
|
||||
ulx.fancyLogAdmin( calling_ply, "#A ungimped #T", target_plys )
|
||||
end
|
||||
end
|
||||
local gimp = ulx.command( CATEGORY_NAME, "ulx gimp", ulx.gimp, "!gimp" )
|
||||
gimp:addParam{ type=ULib.cmds.PlayersArg }
|
||||
gimp:addParam{ type=ULib.cmds.BoolArg, invisible=true }
|
||||
gimp:defaultAccess( ULib.ACCESS_ADMIN )
|
||||
gimp:help( "Gimps target(s) so they are unable to chat normally." )
|
||||
gimp:setOpposite( "ulx ungimp", {_, _, true}, "!ungimp" )
|
||||
|
||||
------------------------------ Mute ------------------------------
|
||||
function ulx.mute( calling_ply, target_plys, should_unmute )
|
||||
for i=1, #target_plys do
|
||||
local v = target_plys[ i ]
|
||||
if should_unmute then
|
||||
v.gimp = nil
|
||||
else
|
||||
v.gimp = ID_MUTE
|
||||
end
|
||||
v:SetNWBool("ulx_muted", not should_unmute)
|
||||
end
|
||||
|
||||
if not should_unmute then
|
||||
ulx.fancyLogAdmin( calling_ply, "#A muted #T", target_plys )
|
||||
else
|
||||
ulx.fancyLogAdmin( calling_ply, "#A unmuted #T", target_plys )
|
||||
end
|
||||
end
|
||||
local mute = ulx.command( CATEGORY_NAME, "ulx mute", ulx.mute, "!mute" )
|
||||
mute:addParam{ type=ULib.cmds.PlayersArg }
|
||||
mute:addParam{ type=ULib.cmds.BoolArg, invisible=true }
|
||||
mute:defaultAccess( ULib.ACCESS_ADMIN )
|
||||
mute:help( "Mutes target(s) so they are unable to chat." )
|
||||
mute:setOpposite( "ulx unmute", {_, _, true}, "!unmute" )
|
||||
|
||||
if SERVER then
|
||||
local function gimpCheck( ply, strText )
|
||||
if ply.gimp == ID_MUTE then return "" end
|
||||
if ply.gimp == ID_GIMP then
|
||||
if #gimpSays < 1 then return nil end
|
||||
return gimpSays[ math.random( #gimpSays ) ]
|
||||
end
|
||||
end
|
||||
hook.Add( "PlayerSay", "ULXGimpCheck", gimpCheck, HOOK_LOW )
|
||||
end
|
||||
|
||||
------------------------------ Gag ------------------------------
|
||||
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 )
|
||||
|
||||
-- Anti-spam stuff
|
||||
if SERVER then
|
||||
local chattime_cvar = ulx.convar( "chattime", "1.5", "<time> - Players can only chat every x seconds (anti-spam). 0 to disable.", ULib.ACCESS_ADMIN )
|
||||
local function playerSay( ply )
|
||||
if not ply.lastChatTime then ply.lastChatTime = 0 end
|
||||
|
||||
local chattime = chattime_cvar:GetFloat()
|
||||
if chattime <= 0 then return end
|
||||
|
||||
if ply.lastChatTime + chattime > CurTime() then
|
||||
return ""
|
||||
else
|
||||
ply.lastChatTime = CurTime()
|
||||
return
|
||||
end
|
||||
end
|
||||
hook.Add( "PlayerSay", "ulxPlayerSay", playerSay, HOOK_LOW )
|
||||
|
||||
local function meCheck( ply, strText, bTeam )
|
||||
local meChatEnabled = GetConVarNumber( "ulx_meChatEnabled" )
|
||||
|
||||
if ply.gimp or meChatEnabled == 0 or (meChatEnabled ~= 2 and GAMEMODE.Name ~= "Sandbox") then return end -- Don't mess
|
||||
|
||||
if strText:sub( 1, 4 ) == "/me " then
|
||||
strText = string.format( "*** %s %s", ply:Nick(), strText:sub( 5 ) )
|
||||
if not bTeam then
|
||||
ULib.tsay( _, strText )
|
||||
else
|
||||
strText = "(TEAM) " .. strText
|
||||
local teamid = ply:Team()
|
||||
local players = team.GetPlayers( teamid )
|
||||
for _, ply2 in ipairs( players ) do
|
||||
ULib.tsay( ply2, strText )
|
||||
end
|
||||
end
|
||||
|
||||
if game.IsDedicated() then
|
||||
Msg( strText .. "\n" ) -- Log to console
|
||||
end
|
||||
if ULib.toBool( GetConVarNumber( "ulx_logChat" ) ) then
|
||||
ulx.logString( strText )
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
|
||||
end
|
||||
hook.Add( "PlayerSay", "ULXMeCheck", meCheck, HOOK_LOW ) -- Extremely low priority
|
||||
end
|
||||
|
||||
local function showWelcome( ply )
|
||||
local message = GetConVarString( "ulx_welcomemessage" )
|
||||
if not message or message == "" then return end
|
||||
|
||||
message = string.gsub( message, "%%curmap%%", game.GetMap() )
|
||||
message = string.gsub( message, "%%host%%", GetConVarString( "hostname" ) )
|
||||
message = string.gsub( message, "%%ulx_version%%", ULib.pluginVersionStr( "ULX" ) )
|
||||
|
||||
ply:ChatPrint( message ) -- We're not using tsay because ULib might not be loaded yet. (client side)
|
||||
end
|
||||
hook.Add( "PlayerInitialSpawn", "ULXWelcome", showWelcome )
|
||||
if SERVER then
|
||||
ulx.convar( "meChatEnabled", "1", "Allow players to use '/me' in chat. 0 = Disabled, 1 = Sandbox only (Default), 2 = Enabled", ULib.ACCESS_ADMIN )
|
||||
ulx.convar( "welcomemessage", "", "<msg> - This is shown to players on join.", ULib.ACCESS_ADMIN )
|
||||
end
|
@ -1,188 +0,0 @@
|
||||
------------------
|
||||
--Public votemap--
|
||||
------------------
|
||||
ulx.votemaps = ulx.votemaps or {}
|
||||
local specifiedMaps = {}
|
||||
|
||||
local function init()
|
||||
local mode = GetConVarNumber( "ulx_votemapMapmode" ) or 1
|
||||
if mode == 1 then -- Add all but specified
|
||||
local maps = file.Find( "maps/*.bsp", "GAME" )
|
||||
for _, map in ipairs( maps ) do
|
||||
map = map:sub( 1, -5 ) -- Take off .bsp
|
||||
if not specifiedMaps[ map ] then
|
||||
table.insert( ulx.votemaps, map )
|
||||
end
|
||||
end
|
||||
else
|
||||
for map, _ in pairs( specifiedMaps ) do
|
||||
if ULib.fileExists( "maps/" .. map .. ".bsp" ) then
|
||||
table.insert( ulx.votemaps, map )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Now, let's sort!
|
||||
table.sort( ulx.votemaps )
|
||||
end
|
||||
hook.Add( ulx.HOOK_ULXDONELOADING, "ULXInitConfigs", init ) -- Time for configs
|
||||
|
||||
local userMapvote = {} -- Indexed by player.
|
||||
local mapvotes = {} -- Indexed by map.
|
||||
ulx.timedVeto = nil
|
||||
|
||||
ulx.convar( "votemapEnabled", "1", _, ULib.ACCESS_ADMIN ) -- Enable/Disable the entire votemap command
|
||||
ulx.convar( "votemapMintime", "10", _, ULib.ACCESS_ADMIN ) -- Time after map change before votes count.
|
||||
ulx.convar( "votemapWaittime", "5", _, ULib.ACCESS_ADMIN ) -- Time before a user must wait before they can change their vote.
|
||||
ulx.convar( "votemapSuccessratio", "0.5", _, ULib.ACCESS_ADMIN ) -- Ratio of (votes for map)/(total players) needed to change map. (Rounds up)
|
||||
ulx.convar( "votemapMinvotes", "3", _, ULib.ACCESS_ADMIN ) -- Number of minimum votes needed to change map (Prevents llamas). This supersedes the above convar on small servers.
|
||||
ulx.convar( "votemapVetotime", "30", _, ULib.ACCESS_ADMIN ) -- Time in seconds an admin has after a successful votemap to veto the vote. Set to 0 to disable.
|
||||
ulx.convar( "votemapMapmode", "1", _, ULib.ACCESS_ADMIN ) -- 1 = Use all maps but what's specified below, 2 = Use only the maps specified below.
|
||||
|
||||
function ulx.votemapVeto( calling_ply )
|
||||
if not ulx.timedVeto then
|
||||
ULib.tsayError( calling_ply, "There's nothing to veto!", true )
|
||||
return
|
||||
end
|
||||
|
||||
timer.Remove( "ULXVotemap" )
|
||||
timer.Remove( "ULXVotemapNotice" )
|
||||
ulx.timedVeto = nil
|
||||
hook.Call( ulx.HOOK_VETO )
|
||||
ULib.tsay( _, "Votemap changelevel halted.", true )
|
||||
ulx.logServAct( calling_ply, "#A vetoed the votemap" )
|
||||
end
|
||||
-- The command is defined at the end of vote.lua
|
||||
|
||||
function ulx.votemapAddMap( map )
|
||||
specifiedMaps[ map ] = true
|
||||
end
|
||||
|
||||
function ulx.clearVotemaps()
|
||||
table.Empty( specifiedMaps )
|
||||
end
|
||||
|
||||
function ulx.votemap( calling_ply, map )
|
||||
if not ULib.toBool( GetConVarNumber( "ulx_votemapEnabled" ) ) then
|
||||
ULib.tsayError( calling_ply, "The votemap command has been disabled by a server admin.", true )
|
||||
return
|
||||
end
|
||||
|
||||
if not calling_ply:IsValid() then
|
||||
Msg( "You can't use votemap from the dedicated server console.\n" )
|
||||
return
|
||||
end
|
||||
|
||||
if ulx.timedVeto then
|
||||
ULib.tsayError( calling_ply, "You cannot vote right now, another map has already won and is pending approval.", true )
|
||||
return
|
||||
end
|
||||
|
||||
if not map or map == "" then
|
||||
ULib.tsay( calling_ply, "Map list printed to console", true )
|
||||
ULib.console( calling_ply, "Use \"votemap <id>\" to vote for a map. Map list:" )
|
||||
for id, map in ipairs( ulx.votemaps ) do
|
||||
ULib.console( calling_ply, " " .. id .. " -\t" .. map )
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local mintime = tonumber( GetConVarString( "ulx_votemapMintime" ) ) or 10
|
||||
if CurTime() < mintime * 60 then -- Minutes -> seconds
|
||||
ULib.tsayError( calling_ply, "Sorry, you must wait " .. mintime .. " minutes after a map change before you can vote for another map.", true )
|
||||
local timediff = mintime*60 - CurTime()
|
||||
ULib.tsayError( calling_ply, "That means you must wait " .. string.FormattedTime( math.fmod( timediff, 3600 ), (mintime < 60) and "%02i:%02i" or math.floor( timediff/3600 ) .. " hour(s) and %02i:%02i" ) .. " more minutes.", true )
|
||||
return
|
||||
end
|
||||
|
||||
if userMapvote[ calling_ply ] then
|
||||
local waittime = tonumber( GetConVarString( "ulx_votemapWaittime" ) ) or 5
|
||||
if CurTime() - userMapvote[ calling_ply ].time < waittime * 60 then -- Minutes -> seconds
|
||||
ULib.tsayError( calling_ply, "Sorry, you must wait " .. waittime .. " minutes before changing your vote.", true )
|
||||
local timediff = waittime*60 - (CurTime() - userMapvote[ calling_ply ].time)
|
||||
ULib.tsayError( calling_ply, "That means you must wait " .. string.FormattedTime( math.fmod( timediff, 3600 ), (waittime < 60) and "%02i:%02i" or math.floor( timediff/3600 ) .. " hour(s) and %02i:%02i" ) .. " more minutes.", true )
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local mapid
|
||||
if tonumber( map ) then
|
||||
mapid = tonumber( map )
|
||||
if not ulx.votemaps[ mapid ] then
|
||||
ULib.tsayError( calling_ply, "Invalid map id!", true )
|
||||
return
|
||||
end
|
||||
else
|
||||
if string.sub( map, -4 ) == ".bsp" then
|
||||
map = string.sub( map, 1, -5 ) -- Take off the .bsp
|
||||
end
|
||||
|
||||
mapid = ULib.findInTable( ulx.votemaps, map )
|
||||
if not mapid then
|
||||
ULib.tsayError( calling_ply, "Invalid map!", true )
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if userMapvote[ calling_ply ] then -- Take away from their previous vote
|
||||
mapvotes[ userMapvote[ calling_ply ].mapid ] = mapvotes[ userMapvote[ calling_ply ].mapid ] - 1
|
||||
end
|
||||
|
||||
userMapvote[ calling_ply ] = { mapid=mapid, time=CurTime() }
|
||||
mapvotes[ mapid ] = mapvotes[ mapid ] or 0
|
||||
mapvotes[ mapid ] = mapvotes[ mapid ] + 1
|
||||
|
||||
local minvotes = tonumber( GetConVarString( "ulx_votemapMinvotes" ) ) or 0
|
||||
local successratio = tonumber( GetConVarString( "ulx_votemapSuccessratio" ) ) or 0.5
|
||||
|
||||
local votes_needed = math.ceil( math.max( minvotes, successratio * #player.GetAll() ) ) -- Round up whatever the largest is.
|
||||
|
||||
-- TODO, color?
|
||||
ULib.tsay( _, string.format( "%s voted for %s (%i/%i). Say \"!votemap %i\" to vote for this map too.", calling_ply:Nick(), ulx.votemaps[ mapid ], mapvotes[ mapid ], votes_needed, mapid ), true )
|
||||
ulx.logString( string.format( "%s voted for %s (%i/%i)", calling_ply:Nick(), ulx.votemaps[ mapid ], mapvotes[ mapid ], votes_needed ) )
|
||||
|
||||
if mapvotes[ mapid ] >= votes_needed then
|
||||
local vetotime = tonumber( GetConVarString( "ulx_votemapVetotime" ) ) or 30
|
||||
|
||||
local admins = {}
|
||||
local players = player.GetAll()
|
||||
for _, player in ipairs( players ) do
|
||||
if player:IsConnected() then
|
||||
if ULib.ucl.query( player, "ulx veto" ) then
|
||||
table.insert( admins, player )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #admins <= 0 or vetotime < 1 then
|
||||
ULib.tsay( _, "Vote for map " .. ulx.votemaps[ mapid ] .. " successful! Changing levels now.", true ) -- TODO, color?
|
||||
ulx.logString( "Votemap for " .. ulx.votemaps[ mapid ] .. " won." )
|
||||
game.ConsoleCommand( "changelevel " .. ulx.votemaps[ mapid ] .. "\n" )
|
||||
else
|
||||
ULib.tsay( _, "Vote for map " .. ulx.votemaps[ mapid ] .. " successful! Now pending admin approval. (" .. vetotime .. " seconds)", true ) -- TODO, color?
|
||||
for _, player in ipairs( admins ) do
|
||||
ULib.tsay( player, "To veto this vote, just say \"!veto\"", true ) -- TODO, color?
|
||||
end
|
||||
ulx.logString( "Votemap for " .. ulx.votemaps[ mapid ] .. " won. Pending admin veto." )
|
||||
ulx.timedVeto = true
|
||||
hook.Call( ulx.HOOK_VETO )
|
||||
ulx.csay(calling_ply, "====== MAP CHANGE IN: " .. vetotime .. " SECOND(S) ======")
|
||||
local vetotime2 = vetotime - 1
|
||||
timer.Create( "ULXVotemapNotice", 1, vetotime2, function()
|
||||
ulx.csay(calling_ply, "====== MAP CHANGE IN: " .. vetotime2 .. " SECOND(S) ======")
|
||||
vetotime2 = vetotime2 - 1
|
||||
end )
|
||||
timer.Create( "ULXVotemap", vetotime, 1, function() game.ConsoleCommand( "changelevel " .. ulx.votemaps[ mapid ] .. "\n" ) end )
|
||||
end
|
||||
end
|
||||
end
|
||||
-- This command is defined at the bottom of vote.lua
|
||||
|
||||
function ulx.votemap_disconnect( ply ) -- We use this to clear out old people's votes
|
||||
if userMapvote[ ply ] then -- Take away from their previous vote
|
||||
mapvotes[ userMapvote[ ply ].mapid ] = mapvotes[ userMapvote[ ply ].mapid ] - 1
|
||||
userMapvote[ ply ] = nil
|
||||
end
|
||||
end
|
||||
hook.Add( "PlayerDisconnected", "ULXVoteDisconnect", ulx.votemap_disconnect )
|
Loading…
Reference in New Issue
Block a user