Jan 18, 2008, 12:31 AM
I've implemented a melee vote system using SourceOP's Lua system. It's quite simple really. First I coded a generic Vote class which uses my Menu class to display voting options. Then, from that, I made an "AbstainableVote" class where players can choose to abstain. After that, coding the melee vote wasn't very difficult.
The code will probably change as I finalize some things. 30 is the number of seconds the vote stays up. 3 just tells AbstainableVote which choice is the Abstain one (3rd one).
The vote can only be started by admins and isn't automatic or on a schedule (unless people want it like that?).
I just thought I'd share some recent development.
Oh, and here is what it looks like in game:
http://www.sourceop.com/screenshots/meleevote.jpg
Code:
function meleevoteover( vote )
local yesvotes = vote.picks[1]
local novotes = vote.picks[2]
local abstentions = vote.picks[3]
if(yesvotes >= novotes) then
wintext = "Yes wins: "
game.ConsoleCommand("DF_tf2_meleeonly 1")
else
wintext = "No wins: "
game.ConsoleCommand("DF_tf2_meleeonly 0")
end
wintext = wintext .. "Yes: " .. yesvotes .. ", No: " .. novotes .. ", Abstain: " .. abstentions .. "\n"
sourceop.SayTextAll(wintext)
end
function meleevote( pPlayer, command, arguments )
if(!pPlayer || pPlayer:IsAdmin(8, "admin_meleevote")) then
AbstainableVote("Enable melee only mode?",
{"Yes", "No", "Abstain"}, 3, 30,
"Abstain is the default choice.\nAbstentions go to the majority.",
meleevoteover)
end
end
if(sourceop.FeatureStatus(FEAT_ADMINCOMMANDS)) then
concommand.Add("admin_meleevote", meleevote)
end
The code will probably change as I finalize some things. 30 is the number of seconds the vote stays up. 3 just tells AbstainableVote which choice is the Abstain one (3rd one).
The vote can only be started by admins and isn't automatic or on a schedule (unless people want it like that?).
I just thought I'd share some recent development.
Oh, and here is what it looks like in game:
http://www.sourceop.com/screenshots/meleevote.jpg