This is my script. I have the variable %hasvoted set to 1 once you vote using /yes or /no. Unfortunately, players can still vote.
package voting
{
function autoendvote(%c)
{
servercmdendvote(%c);
messageall('',"\c6Time's up!");
}
function servercmdstartvote(%c,%time,%r1,%r2,%r3,%r4,%r5,%r6,%r7,%r8,%r9,%r10,%r11,%r12,%r13,%r14,%r15,%r16,%r17)
{
if(!%c.isadmin)
return;
%time *= 1000;
schedule(%time,0,autoendvote,%c);
$reason = %r1 SPC %r2 SPC %r3 SPC %r4 SPC %r5 SPC %r6 SPC %r7 SPC %r8 SPC %r9 SPC %r10 SPC %r11 SPC %r12 SPC %r13 SPC %r14 SPC %r15 SPC %r16 SPC %r17;
$reason = stripTrailingSpaces($reason);
$totalvotes = "";
$votehost = %c;
$voteactive = 1;
messageall('',"\c3" @ $votehost.name @ "\c6 has called a vote. Reason:\c3" @ $reason);
%time /= 1000;
$votetime = %time;
messageall('',"\c6This vote will last for \c3" @ $votetime @ "\c6 seconds.");
messageall('',"\c6Use /yes to vote yes and /no to vote no.");
messageclient(%c,'',"\c0IMPORTANT:\c6To end the vote, type \"\c3/endvote\c6\".");
}
function servercmdendvote(%c)
{
if(!%c.isadmin)
return;
if(!$voteactive == 1);
return;
$voteactive = 0;
messageall('',"\c6The vote with reason:\c3\"" @ $reason @ "\"\c6 has ended.");
messageall('',"\c6The final tally is...");
if($totalvotes > 0)
messageall('',"\c2The general consensus is yes!\c6 With a final vote of \c3" @ $totalvotes @ "\c6, the vote was a success!");
if($totalvotes < 0)
messageall('',"\c0The general consensus is no!\c6 With a final vote of \c3" @ $totalvotes @ "\c6, the vote was a failure!");
if($totalvotes == 0)
messageall('',"\c3The vote is a tie!\c6 I don't know how you did it, but you broke even!");
for(%x=0;%x<clientGroup.getCount();%x++)
{
clientgroup.getobject(%x).hasvoted = 0;
}
}
function servercmdyes(%c)
{
if(!$voteactive $= 1)
{
%c.chatmessage("\c0Error:\c6There is no vote in progress!");
return;
}
if(%c.hasvoted == 1)
{
%c.chatmessage("\c0Error:\c6You have already voted in this vote.");
return;
}
$voter = %c;
$totalvotes = $totalvotes + 1;
messageclient($votehost,'',"\c3" @ $voter.name @" \c6has voted \c2Yes.");
messageclient($votehost,'',"\c6The current tally of votes is \c3" @ $totalvotes @ "\c6.");
%c.chatmessage("\c6You have voted \c2in favor\c6.");
%c.hasvoted = 1;
}
function servercmdno(%c)
{
if(!$voteactive $= 1)
{
%c.chatmessage("\c0Error:\c6There is no vote in progress!");
return;
}
if(%c.hasvoted == 1)
{
%c.chatmessage("\c0Error:\c6You have already voted in this vote.");
return;
}
$voter = %c;
$totalvotes = $totalvotes - 1;
messageclient($votehost,'',"\c3" @ $voter.name @ " \c6has voted \c0No.");
messageclient($votehost,'',"\c6The current tally of votes is \c3" @ $totalvotes @ "\c6.");
%c.chatmessage("\c6You have voted \c0in opposition\c6.");
%c.hasvoted = 1;
}
};
activatePackage(voting);
Oh, and please don't bug me about the uselessness of packages in this usage. I'm doing that for my own mental cleanliness. (Unless someone tells me that it's BAD to use packages when they aren't neccesary??)