12.03.2012, 22:39
I was actually contemplating releasing this...However I don't have many ideas for it
pawn Код:
/*
VoteSystem by Brutal[ABK]
If there's an conflicts with the IDs used, please post in the thread with the conflicted IDs.
Features:
Vote Kick
Vote Ban
Private Messaging
*/
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define Version "v0.1a" //The current version of the voting system
#define VoteTime 5 //Change the number to how many minutes you want votes to last.
forward VoteEnd();
#define VOTEBAN 1 //1 enables vote ban, 0 disables
//=========[Dialog Defines]=========
#define InitialMenu 100
#define PrivateMenu 101
#define KickMenu 102
#define BanMenu 103
#define VoteMenu 108
//==================================
new VoteType = -1, //This is the vote type, type 1 is kick
YesVotes = 0, //This is self explanitory
NoVotes = 0, //This is self explanitory
bool:Voting = false, //This will be to check if a vote is currently on
bool:HasVoted[MAX_PLAYERS] = false, //This is self explanitory
VoteAgainst = -1, //We'll use VoteAgainst for if it's a number
VoteReason[64], //This will be for if it has a reason - such as vote kicks
VoteTimer, //This is our timer ID for voting.
PMRecip[MAX_PLAYERS] = -1; //This is for our PM system
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print("VoteSystem Filterscript by Brutal[ABK]");
printf(" [%s]\n", Version);
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
//This is so we can check how many players are online
//No point in voting if there's less than 3
new PlayerCount = 0;
for(new i=0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) PlayerCount++;
//We're going to set our VoteAgainst to the player
//This will also control private messages.
PMRecip[playerid] = clickedplayerid;
new DialogString[128];
//Here we're going to check if a vote is currently active
//If it is, we're only going to show them private message
if(Voting && PlayerCount < 3) format(DialogString, sizeof(DialogString), "Private Message");
//If not, we're going to give them the vote options.
#if VOTEBAN == 1
else
{
format(DialogString, sizeof(DialogString), "Private Message\nVote Kick\nVote Ban");
VoteAgainst = clickedplayerid;
}
#else
else
{
format(DialogString, sizeof(DialogString), "Private Message\nVote Kick");
VoteAgainst = clickedplayerid;
}
#endif
//Then we show our dialog to them with the current items
ShowPlayerDialog(playerid, InitialMenu, DIALOG_STYLE_LIST, "Votation System", DialogString, "Ok", "Close");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
//Here we'll initiat our switch - if you want to learn more about switches
//Please go here, https://sampwiki.blast.hk/wiki/Control_S...s#switch_2
//You can see cases below there.
switch(dialogid)
{
case InitialMenu:
{
switch(listitem)
{
case 0: //This is the private message list item
{
ShowPlayerDialog(playerid,PrivateMenu,DIALOG_STYLE_INPUT,"Private Message","Please input your message below","Ok","Close");
}
case 1: //This is the Vote Kick list item
{
ShowPlayerDialog(playerid,KickMenu,DIALOG_STYLE_INPUT,"Vote Kick","What's the reason?","Ok","Cancel");
}
case 2: //This is the Vote Ban list item
{
ShowPlayerDialog(playerid,BanMenu,DIALOG_STYLE_INPUT,"Vote Ban","What's the reason?","Ok","Cancel");
}
}
}
case PrivateMenu:
{
//If inputtext has a length, let's go ahead and send the message
//Our PrivateMessage function takes three arguments.
//The player who is sending, the recipient, and the message.
if(strlen(inputtext)) PrivateMessage(playerid, PMRecip[playerid], inputtext);
}
case KickMenu:
{
if(strlen(inputtext) && strlen(inputtext) <= 64)
{
Voting = true; //Says that a vote is currently on
VoteType = 1; //1 is for kick
YesVotes = 1; //We up the vote as the one who voted auto yeses
HasVoted[playerid] = true; //We say that the player who initiated voted already
//This is our timer, it will call VoteEnd after our VoteTime passes
//VoteTime is in minutes (5*1000 = 5 minutes in milliseconds for example)
VoteTimer = SetTimer("VoteEnd", VoteTime*1000, false); //false means it wont repeat
format(VoteReason, sizeof(VoteReason), "%s", inputtext);
}
}
case BanMenu: //ineed im copy and pasting what i did above :P
{
if(strlen(inputtext) && strlen(inputtext) <= 64)
{
Voting = true; //Says that a vote is currently on
VoteType = 2; //2 is for ban
YesVotes = 1; //We up the vote as the one who voted auto yeses
HasVoted[playerid] = true; //We say that the player who initiated voted already
//This is our timer, it will call VoteEnd after our VoteTime passes
//VoteTime is in minutes (5*1000 = 5 minutes in milliseconds for example)
VoteTimer = SetTimer("VoteEnd", VoteTime*1000, false); //false means it wont repeat
format(VoteReason, sizeof(VoteReason), "%s", inputtext);
}
}
case VoteMenu:
{
if(response) YesVotes++; //If they clicked yes
else NoVotes++; //If they clicked no
//No matter what they pick, we send a message to everyone saying the current vote status
new string[128];
format(string, sizeof(string), "{00CCCC}| Vote System | {00CC00}Yes: %i {CC0000}No: %i", YesVotes, NoVotes);
SendClientMessageToAll(0x00CCCCAA, string);
}
}
return 1;
}
CMD:vote(playerid)
{
if(Voting) //If there's a vote going on
{
//Let's show a dialog on what type of vote, who it's against, the reason, and the current status
new string[155];
format(string, sizeof(string), "Vote: %s\nVote Against: %s\nReason: %s\n\nVotes\nYes: %i No: %i", VoteName(VoteType), Name(VoteAgainst), VoteReason, YesVotes, NoVotes);
ShowPlayerDialog(playerid, VoteMenu, DIALOG_STYLE_MSGBOX, "Voting System", string, "Yes", "No");
}
else return SendClientMessage(playerid, 0xCC0000AA, "There's no vote going on!");
return 1;
}
public VoteEnd() //This is the function called by our timer when the vote ends
{
switch(VoteType)
{
case 1: //This is for Vote Kick
{
new string[128];
if(YesVotes == NoVotes) //Incase the votes are equal, we'll randomize it.
{
switch(random(1)) //This is random between 0 and 1
{
//If it lands on 0, lets accept the kick
case 0:
{
format(string, sizeof(string), "Vote success. %s kicked for %s", Name(VoteAgainst), VoteReason);
SendClientMessageToAll(0xCC0000AA, string);
Kick(VoteAgainst);
}
//If it lands on 1, we deny it
case 1: SendClientMessageToAll(0xFF0000AA, "Votes were equal, randomly added a vote. Vote failed.");
}
}
else if(YesVotes > NoVotes) //If there are more Yes votes than No votes
{
format(string, sizeof(string), "Yes: %i No: %i. %s kicked for %s", YesVotes, NoVotes, Name(VoteAgainst), VoteReason);
SendClientMessageToAll(0xCC0000AA, string);
Kick(VoteAgainst);
}
else
{
format(string, sizeof(string), "Vote failed. Yes: %i No: %i", YesVotes, NoVotes);
SendClientMessageToAll(0xFF0000AA, string);
}
}
#if VOTEBAN == 1
case 2:
{
new string[128];
if(YesVotes == NoVotes) SendClientMessageToAll(0xFF0000AA, "Vote failed.");
else if(YesVotes > NoVotes) //If there are more Yes votes than No votes
{
format(string, sizeof(string), "Yes: %i No: %i. %s kicked for %s", YesVotes, NoVotes, Name(VoteAgainst), VoteReason);
SendClientMessageToAll(0xCC0000AA, string);
BanEx(VoteAgainst, VoteReason);
}
else
{
format(string, sizeof(string), "Vote failed. Yes: %i No: %i", YesVotes, NoVotes);
SendClientMessageToAll(0xFF0000AA, string);
}
}
#endif
}
//Here we'll reset the variables used
Voting = false;
YesVotes = 0;
NoVotes = 0;
VoteReason = "\0"; // \0 represents null
VoteType = -1;
VoteAgainst = -1;
for(new i=0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) HasVoted[i] = false;
KillTimer(VoteTimer); //Kills the timer
}
//This is our Private Message function, it's sort of handy
//We can save space in our OnDialogResponse using this
stock PrivateMessage(playerid, recip, message[])
{
new string[128];
format(string, sizeof(string), "PM to %s(%d): %s", Name(recip), recip, message);
SendClientMessage(playerid, 0x009999AA, string);
format(string, sizeof(string), "PM from %s(%d): %s", Name(playerid), playerid, message);
SendClientMessage(recip, 0x009999AA, string);
}
//This is our Name function
//It just saves space in our other stuff
stock Name(playerid)
{
//Please note, using MAX_PLAYER_NAME is more efficient than just using 24.
//If they ever change the max characters you can have in your name, this will take care of it
//as it's defined in a_players include.
new name[MAX_PLAYER_NAME];
//This gets their name then stores it inside of our name string
GetPlayerName(playerid, name, sizeof(name));
return name; //returns the name string
}
stock VoteName(type)
{
new name[10];
switch(type)
{
case 1: name = "Vote Kick";
case 2: name = "Vote Ban";
default: name = "Error";
}
return name;
}