Blockland Forums > Modification Help
Attempting to make a Vote mod. People can vote more than once. HELP
Nexus:
--- Quote from: Nexus on January 11, 2012, 11:59:36 PM ---
--- End quote ---
Er, it occurred to me that players could use an exploit where they join multiple times at once by opening multiple instances of blockland. When tallying up the votes, probably make a check to ensure that a bl_id is not getting to vote twice.
CityRPG:
--- Quote from: Nexus on January 12, 2012, 12:12:56 AM ---Er, it occurred to me that players could use an exploit where they join multiple times at once by opening multiple instances of blockland. When tallying up the votes, probably make a check to ensure that a bl_id is not getting to vote twice.
--- End quote ---
My first reply actually noted this, and then I redacted it.
If you only set a property on the client that is only tallied after the vote, this bug doesn't happen. The only exploit would be having multiple clients join of the same BL_ID, but that's somewhat impractical.
Lugnut:
sooo...
for(%x=0;%x<clientGroup.getCount();%x++)
{
if(clientgroup.getobject(%x).vote = 1)
$totalvotes + 1;
if(clientgroup.getobject(%x).vote = 2)
$totalvotes - 1;
if(clientgroup.getobject(%x).vote = 0)
}
--- Code: --- function servercmdendvote(%c)
{
if(!%c.isadmin)
return;
if(!$voteactive == 1);
return;
$voteactive = 0;
for(%x=0;%x<clientGroup.getCount();%x++)
{
if(clientgroup.getobject(%x).vote == 1)
$totalvotes++;
if(clientgroup.getobject(%x).vote == 2)
$totalvotes--;
}
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).vote = 0;
}
}
function servercmdyes(%c)
{
if(!$voteactive == 1)
{
%c.chatmessage("\c0Error:\c6There is no vote in progress!");
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.vote = 1;
}
--- End code ---
Something like this?
If this doesn't work, you'll probably find out that I have no idea how to use for() loops, and I just got lucky in the usage in my main code...
Nexus:
Instead of adding or subtracting to the same variable, do it $votesYes and $votesNo and then compare them to see which is larger.
As you have it, if no wins, it would display a negative number of votes.
Also don't forget that you are removing $totalvotes = $totalvotes + 1;