So i am using this code, (calling a ulx votemap2 at the end) but i get an error:
Code:
[lua]
function ulx.doVoteMod( title, options, callback, timeout, filter, noecho, ... )
timeout = timeout or 20
local rp = RecipientFilter()
rp:AddAllPlayers()
local voters = #player.GetAll()
umsg.Start( "ulx_vote", rp )
umsg.String( title )
umsg.Short( timeout )
ULib.umsgSend( options )
umsg.End()
timer.Create( "ULXVoteTimeout", timeout, 1, ulx.voteDone )
end
function ulx.voteCallback( ply, command, argv )
if not voteInProgress then
ULib.tsayError( ply, "There is not a vote in progress" )
return
end
if not argv[ 1 ] or not tonumber( argv[ 1 ] ) or not voteInProgress.options[ tonumber( argv[ 1 ] ) ] then
ULib.tsayError( ply, "Invalid or out of range vote." )
return
end
if ply.ulxVoted then
ULib.tsayError( ply, "You have already voted!" )
return
end
local echo = util.tobool( GetConVarNumber( "ulx_voteEcho" ) )
local id = tonumber( argv[ 1 ] )
voteInProgress.results[ id ] = voteInProgress.results[ id ] or 0
voteInProgress.results[ id ] = voteInProgress.results[ id ] + 1
voteInProgress.votes = voteInProgress.votes + 1
ply.ulxVoted = true -- Tag them as having voted
local str = ply:Nick() .. " voted for: " .. voteInProgress.options[ id ]
if echo and not voteInProgress.noecho then
ULib.tsay( _, str ) -- TODO, color?
end
ulx.logString( str )
if game.IsDedicated() then Msg( str .. "n" ) end
if voteInProgress.votes >= voteInProgress.voters then
timer.Destroy( "ULXVoteTimeout" )
ulx.voteDone()
end
end
if SERVER then concommand.Add( "ulx_vote", ulx.voteCallback ) end
function ulx.voteDone()
local players = player.GetAll()
for _, ply in ipairs( players ) do -- Clear voting tags
ply.ulxVoted = nil
end
local vip = voteInProgress
voteInProgress = nil
ULib.pcallError( vip.callback, vip, unpack( vip.args, 1, 10 ) ) -- Unpack is explicit in length to avoid odd LuaJIT quirk.
end
local function CheckTheRound()
if GetGlobalInt("ttt_rounds_left") == 1 then
VoteForNextMap("ttt_67thway_v4","ttt_67thway_v3","ttt_vessel","ttt_whitehouse_b2","ttt_slender_v2","ttt_rooftops_a2","ttt_crummycradle_a4")
RunConsoleCommand("ulx","csay","A votemap has been initiated to pick the next map!")
elseif GetGlobalInt("ttt_rounds_left") == 0 then
RunConsoleCommand("ulx","csay","The map will change in 5 seconds.")
timer.Create( "my_timer", 5, 0, function() ULib.consoleCommand( "changelevel " .. changeTo .. "n" ) end)
end
end
hook.Add("TTTEndRound","blah",CheckTheRound)
local function voteMapDoneOTHER( t, argv, ply )
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
if not winner then
str = "Vote results: No one voted, the next map will be picked randomly."
RunConsoleCommand( "ulx", "csay", str )
changeTo = t.options[ math.random(1,#t.options) ]
str = "The next map will be "..changeTo.."."
timer.Create( "msg1", 4, 1, function() RunConsoleCommand( "ulx", "csay", str ) end)
str = "The map will be changed next round."
timer.Create( "msg2", 8, 1, function() RunConsoleCommand( "ulx", "csay", str ) end)
else
str = "Votemap results: '" .. t.options[ winner ] .. "' won. (" .. winnernum .. "/" .. t.voters .. ")"
RunConsoleCommand( "ulx", "csay", str )
changeTo = t.options[ winner ]
str = "The map will be changed next round."
timer.Create( "msg1", 4, 1, function() RunConsoleCommand( "ulx", "csay", str ) end)
end
RunConsoleCommand( "ulx", "csay", str ) -- TODO, color?
ulx.logString( str )
if game.IsDedicated() then Msg( str .. "n" ) end
end
function VoteForNextMap( ... )
local argv = { ... }
ulx.doVoteMod( "Change map to..", argv, voteMapDoneOTHER, _, _, _, argv, calling_ply )
end
[/lua]
The error:
[lua]
[Error] gamemodes/terrortown/gamemode/RGScripts.lua:67: attempt to index local 'vip' (a nil value)
1.unknown -gamemodes/terrortown/gamemode/RGScripts.lua:67
Timer Failed! [UlxVoteTimeout] [@gamemodes/terrortown/gamemode/RGScripts.lua (line 17)]
[/lua]
Any help appriciated, thanks!
[editline]26th April 2013[/editline]
Also, when you vote, it errors ingame as "there is no vote currently running"
On line 66 you've set voteInProgress to nil which it tries to use on the next line...
[lua]
function ulx.doVoteMod( title, options, callback, timeout, filter, noecho, ... )
timeout = timeout or 20
local rp = RecipientFilter()
rp:AddAllPlayers()
local voters = #player.GetAll()
umsg.Start( "ulx_vote", rp )
umsg.String( title )
umsg.Short( timeout )
ULib.umsgSend( options )
umsg.End()
voteInProgress = { callback=callback, options=options, title=title, results={}, voters=voters, votes=0, noecho=noecho, args={...} }
timer.Create( "ULXVoteTimeout", timeout, 1, ulx.voteDone )
end
function ulx.voteCallback( ply, command, argv )
if not voteInProgress then
ULib.tsayError( ply, "There is not a vote in progress" )
return
end
if not argv[ 1 ] or not tonumber( argv[ 1 ] ) or not voteInProgress.options[ tonumber( argv[ 1 ] ) ] then
ULib.tsayError( ply, "Invalid or out of range vote." )
return
end
if ply.ulxVoted then
ULib.tsayError( ply, "You have already voted!" )
return
end
local echo = util.tobool( GetConVarNumber( "ulx_voteEcho" ) )
local id = tonumber( argv[ 1 ] )
voteInProgress.results[ id ] = voteInProgress.results[ id ] or 0
voteInProgress.results[ id ] = voteInProgress.results[ id ] + 1
voteInProgress.votes = voteInProgress.votes + 1
ply.ulxVoted = true -- Tag them as having voted
local str = ply:Nick() .. " voted for: " .. voteInProgress.options[ id ]
if echo and not voteInProgress.noecho then
ULib.tsay( _, str ) -- TODO, color?
end
ulx.logString( str )
if game.IsDedicated() then Msg( str .. "\n" ) end
if voteInProgress.votes >= voteInProgress.voters then
timer.Destroy( "ULXVoteTimeout" )
ulx.voteDone()
end
end
if SERVER then concommand.Add( "ulx_vote", ulx.voteCallback ) end
function ulx.voteDone()
local players = player.GetAll()
for _, ply in ipairs( players ) do -- Clear voting tags
ply.ulxVoted = nil
end
local vip = voteInProgress
voteInProgress = nil
ULib.pcallError( vip.callback, vip, unpack( vip.args, 1, 10 ) ) -- Unpack is explicit in length to avoid odd LuaJIT quirk.
end
local function CheckTheRound()
if GetGlobalInt("ttt_rounds_left") == 1 then
VoteForNextMap("ttt_67thway_v4","ttt_67thway_v3","ttt_vessel","ttt_whitehouse_b2","ttt_slender_v2","ttt_rooftops_a2","ttt_crummycradle_a4")
RunConsoleCommand("ulx","csay","A votemap has been initiated to pick the next map!")
elseif GetGlobalInt("ttt_rounds_left") == 0 then
RunConsoleCommand("ulx","csay","The map will change in 5 seconds.")
timer.Create( "my_timer", 5, 0, function() ULib.consoleCommand( "changelevel " .. changeTo .. "\n" ) end)
end
end
hook.Add("TTTEndRound","blah",CheckTheRound)
local function voteMapDoneOTHER( t, argv, ply )
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
if not winner then
str = "Vote results: No one voted, the next map will be picked randomly."
RunConsoleCommand( "ulx", "csay", str )
changeTo = t.options[ math.random(1,#t.options) ]
str = "The next map will be "..changeTo.."."
timer.Create( "msg1", 4, 1, function() RunConsoleCommand( "ulx", "csay", str ) end)
str = "The map will be changed next round."
timer.Create( "msg2", 8, 1, function() RunConsoleCommand( "ulx", "csay", str ) end)
else
str = "Votemap results: '" .. t.options[ winner ] .. "' won. (" .. winnernum .. "/" .. t.voters .. ")"
RunConsoleCommand( "ulx", "csay", str )
changeTo = t.options[ winner ]
str = "The map will be changed next round."
timer.Create( "msg1", 4, 1, function() RunConsoleCommand( "ulx", "csay", str ) end)
end
RunConsoleCommand( "ulx", "csay", str ) -- TODO, color?
ulx.logString( str )
if game.IsDedicated() then Msg( str .. "\n" ) end
end
function VoteForNextMap( ... )
local argv = { ... }
ulx.doVoteMod( "Change map to..", argv, voteMapDoneOTHER, _, _, _, argv, calling_ply )
end
[/lua]
Line 16
[lua]
voteInProgress = { callback=callback, options=options, title=title, results={}, voters=voters, votes=0, noecho=noecho, args={...} }
[/lua]
adding that in at line 16 fixed it all, works now!
Sorry, you need to Log In to post a reply to this thread.