Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <sscanf2>
- #include <Pawn.CMD>
- enum voteData
- {
- Option[12],
- OptionTwo[12],
- VoteCount[2]
- };
- new Votes[voteData];
- new
- VoteOn,
- VotedFor[MAX_PLAYERS],
- Voted[MAX_PLAYERS];
- public OnPlayerConnect(playerid)
- {
- Voted[playerid] = 0;
- VotedFor[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(Voted[playerid])
- {
- Voted[playerid] = 0;
- if(VotedFor[playerid] == 1)
- Votes[VoteCount][0]--;
- else
- Votes[VoteCount][1]--;
- VotedFor[playerid] = 0;
- }
- return 1;
- }
- CMD:vote(playerid, params[])
- {
- if(!VoteOn)
- return SendClientMessage(playerid, -1, "There is no vote going on.");
- new string[144];
- if(Voted[playerid])
- {
- if(VotedFor[playerid] == 1)
- format(string, sizeof(string), "You have already voted for %s, if you wish to vote for another option - /cancelvote and try voting again.", Votes[Option]);
- else if(VotedFor[playerid] == 2)
- format(string, sizeof(string), "You have already voted for %s, if you wish to vote for another option - /cancelvote and try voting again.", Votes[OptionTwo]);
- SendClientMessage(playerid, -1, string);
- return 0;
- }
- if(isnull(params))
- {
- SendClientMessage(playerid, -1, "USAGE: /vote [option]");
- format(string, sizeof(string), "Options: %s | %s", Votes[Option], Votes[OptionTwo]);
- SendClientMessage(playerid, -1, string);
- }
- if(!strcmp(params, Votes[Option], true))
- {
- if(isnull(params))
- return 0;
- format(string, sizeof(string), "You have voted for %s.", Votes[Option]);
- SendClientMessage(playerid, -1, string);
- Votes[VoteCount][0]++;
- Voted[playerid] = 1;
- VotedFor[playerid] = 1;
- }
- else if(!strcmp(params, Votes[OptionTwo], true))
- {
- if(isnull(params))
- return 0;
- format(string, sizeof(string), "You have voted for %s.", Votes[OptionTwo]);
- SendClientMessage(playerid, -1, string);
- Votes[VoteCount][1]++;
- Voted[playerid] = 1;
- VotedFor[playerid] = 2;
- }
- else return SendClientMessage(playerid, -1, "You did not enter any specified option.");
- return 1;
- }
- CMD:startvote(playerid, params[])
- {
- if(VoteOn)
- return SendClientMessage(playerid, -1, "There is already an vote going on.");
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, -1, "You are not an administrator.");
- new opt1[12], opt2[12];
- if(sscanf(params, "s[12]s[12]", opt1, opt2))
- return SendClientMessage(playerid, -1, "USAGE: /startvote [option1] [option2]");
- if(isnull(opt1) || isnull(opt2))
- return SendClientMessage(playerid, -1, "Options must have atleast 1 character.");
- if(strcmp(opt1, opt2, true) == 0)
- return SendClientMessage(playerid, -1, "Option 1 and 2 can not be the same.");
- format(Votes[Option], 12, opt1);
- format(Votes[OptionTwo], 12, opt2);
- VoteOn = 1;
- new string[144];
- format(string, sizeof(string), "Voting has started! Option: %s or %s", Votes[Option], Votes[OptionTwo]);
- SendClientMessageToAll(-1, string);
- return 1;
- }
- CMD:endvote(playerid, params[])
- {
- if(!VoteOn)
- return SendClientMessage(playerid, -1, "There is no vote going on.");
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, -1, "You are not an administrator.");
- new
- string[144];
- if(Votes[VoteCount][0] > Votes[VoteCount][1])
- {
- format(string, sizeof(string), "%s has won the vote.", Votes[Option]);
- SendClientMessageToAll(-1, string);
- }
- else if(Votes[VoteCount][0] < Votes[VoteCount][1])
- {
- format(string, sizeof(string), "%s has won the vote.", Votes[OptionTwo]);
- SendClientMessageToAll(-1, string);
- }
- else if(Votes[VoteCount][0] == Votes[VoteCount][1])
- {
- format(string, sizeof(string), "No one won! Votes are equal (%s | %s)", Votes[Option], Votes[OptionTwo]);
- SendClientMessageToAll(-1, string);
- }
- for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
- {
- if(Voted[i])
- {
- Voted[i] = 0;
- VotedFor[i] = 0;
- }
- }
- Votes[Option] = EOS;
- Votes[OptionTwo] = EOS;
- Votes[VoteCount][0] = 0;
- Votes[VoteCount][1] = 0;
- VoteOn = 0;
- return 1;
- }
- CMD:cancelvote(playerid, params[])
- {
- if(!VoteOn)
- return SendClientMessage(playerid, -1, "There's no vote going on.");
- if(!Voted[playerid])
- return SendClientMessage(playerid, -1, "You haven't voted for anything to cancel your vote.");
- if(VotedFor[playerid] == 1)
- {
- Votes[VoteCount][0]--;
- }
- else if(VotedFor[playerid] == 2)
- {
- Votes[VoteCount][1]--;
- }
- Voted[playerid] = 0;
- VotedFor[playerid] = 0;
- SendClientMessage(playerid, -1, "You have cancelled your vote.");
- return 1;
- }
- CMD:votes(playerid)
- {
- if(!VoteOn)
- return SendClientMessage(playerid, -1, "There is no vote going on.");
- new string[144];
- SendClientMessage(playerid, -1, "|__________Number of votes_________|");
- format(string, sizeof(string), "Option: %s (Votes: %d)", Votes[Option], Votes[VoteCount][0]);
- SendClientMessage(playerid, -1, string);
- format(string, sizeof(string), "Option: %s (Votes: %d)", Votes[OptionTwo], Votes[VoteCount][1]);
- SendClientMessage(playerid, -1, string);
- return 1;
- }
- CMD:votehelp(playerid)
- {
- SendClientMessage(playerid, -1, "Vote Help: /vote /cancelvote /votes");
- if(IsPlayerAdmin(playerid))
- {
- SendClientMessage(playerid, -1, "Admin: /startvote /endvote");
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment