/votekick + /vote
#1

'Sup y'all?
Since I'm on a trip and writing this on an iPhone, I can't script this command myself! That's why I wanted to ask, how I could script a votekick-command, which displays the votes after 1 minute? (60000 ms)
There should be also a /voteyes and /voteno!
I think you got what I mean...
Reply
#2

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;
}
Reply
#3

Well, this is a pretty long FS, so if I were you, I would release it right now!
Also, it's a little too big for a little guy like me!
I simply want an admin to be able to start a votekick, and then, players can vote with /vyes and /vno...
After killing the timer, the results would be shown and the player would get kicked...or not^^
Can be all done with messafes, I don't prefer dialogs!
Reply
#4

pawn Код:
new bool:VoteOn = false,
    bool:HasVoted[MAX_PLAYERS] = false,
    VoteAgainst = -1,
    VoteReason[64],
    VoteTimer,
    YesVotes,
    NoVotes;

forward VoteEnd();

public VoteEnd()
{
    new string[128];
    if(YesVotes == NoVotes) format(string, sizeof(string), "Vote Failed. Yes: %i No: %i", YesVotes, NoVotes);
    else if(YesVotes > NoVotes)
    {
        format(string, sizeof(string), "%s vote kicked. Yes: %i No: %i (Reason: %s)", YesVotes, NoVotes, VoteReason);
        SendClientMessage(VoteAgainst, string);
        Kick(VoteAgainst);
    }
    else format(string, sizeof(string), "Vote Failed. Yes: %i No: %i", YesVotes, NoVotes);
    SendClientMessageToAll(0x00CCCCAA, string);
    VoteAgainst = -1;
    VoteReason = "\0";
    YesVotes = 0; NoVotes = 0;
    for(new i=0; i < MAX_PLAYERS; i++) if(HasVoted[i]) HasVoted[i] = false;
    VoteOn = false;
    KillTimer(VoteTimer);
}

CMD:votekick(playerid, params[])
{
    if(INSERT_ADMIN_LEVEL_HERE)
    {
        if(VoteOn) return SendClientMessage(playerid, 0xCC0000AA, "There's already a vote going on!"
        new Target, reason[64];
        if(sscanf(params, "rS(None)[64]", Target, reason)) return SendClientMessage(playerid, 0xCC0000AA, "USAGE: /votekick <player> <optional:reason>");
       
        VoteAgainst = Target;
        format(VoteReason, sizeof(VoteReason), "%s", reason);
        VoteTimer = SetTimer("VoteEnd", 300_000, false);
        new string[128];
        format(string, sizeof(string), "Vote kick initiated against %s (Reason: %s)", Name(Target), VoteReason);
        SendClientMessageToAll(0x00CCCC, string);
    }
    else return SendClientMessage(playerid, 0xCC0000AA, "You aren't the required level.");
    return 1;
}

CMD:voteyes(playerid)
{
    if(!VoteOn) return SendClientMessage(playerid, 0xCC0000AA, "There's no vote going on!");
    if(HasVoted[playerid]) return SendClientMessage(playerid, 0xCC0000AA, "You already voted!");
    YesVotes++;
    HasVoted[playerid] = true;
    new string[50];
    format(string, sizeof(string), "{00CCCC}| Vote System | {00CC00}Yes: %i {CC0000}No: %i", YesVotes, NoVotes);
    SendClientMessageToAll(0x00CCCCAA, string);
}

CMD:voteno(playerid)
{
    if(!VoteOn) return SendClientMessage(playerid, 0xCC0000AA, "There's no vote going on!");
    if(HasVoted[playerid]) return SendClientMessage(playerid, 0xCC0000AA, "You already voted!");
    NoVotes++;
    HasVoted[playerid] = true;
    new string[50];
    format(string, sizeof(string), "{00CCCC}| Vote System | {00CC00}Yes: %i {CC0000}No: %i", YesVotes, NoVotes);
    SendClientMessageToAll(0x00CCCCAA, string);
}

CMD:vkick(playerid, params[]) return cmd_votekick(playerid, params);
CMD:vyes(playerid) return cmd_voteyes(playerid);
CMD:vno(playerid) return cmd_voteno(playerid);
So something like that?
Reply
#5

Oh yes, that's exactly what I wanted! You're a great scripter!
When I will arrive home, I'mma test + and change some stuff! Thank you man! :P
Reply
#6

Erm, I tested it now and had to change some stuff because there were errors! But there's a problem:

I start a votekick against myself, and then, I'm voting for "no", that means "/voteno"! But, it shows the following:

Votesystem: Yes: 0 No:

It should usually also count the No's and the current results...Here, I'mma show you my whole code again, the rest seems to be okay!^^

PHP код:
CMD:votekick(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 1)
    {
        if(
VoteOn) return SendClientMessage(playerid0xCC0000AA"There's already a vote going on!");
        new 
Targetreason[64];
        if(
sscanf(params"rS(None)[64]"Targetreason)) return SendClientMessage(playerid0xCC0000AA"USAGE: /votekick <playerid> <optional:reason>");
        
        
VoteOn true;
        
VoteAgainst Target;
        
format(VoteReasonsizeof(VoteReason), "%s"reason);
        
VoteTimer SetTimer("VoteEnd"60000false);
        new 
string[128];
        
format(stringsizeof(string), "Vote kick initiated against %s (Reason: %s)"Name(Target), VoteReason);
        
SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    }
    else return 
SendClientMessage(playeridCOLOR_RED,"You have to be level 1 to use that command!");
    return 
1;
}
CMD:voteyes(playerid)
{
    if(!
VoteOn) return SendClientMessage(playerid0xCC0000AA"There's no vote going on!");
    if(
HasVoted[playerid]) return SendClientMessage(playerid0xCC0000AA"You already voted!");
    
YesVotes++;
    
HasVoted[playerid] = true;
    new 
string[50];
    
format(stringsizeof(string), "{00CCCC}| Vote System | {00CC00}Yes: %i {CC0000}No: %i"YesVotesNoVotes);
    
SendClientMessageToAll(0x00CCCCAAstring);
    return 
1;
}
CMD:voteno(playerid)
{
    if(!
VoteOn) return SendClientMessage(playerid0xCC0000AA"There's no vote going on!");
    if(
HasVoted[playerid]) return SendClientMessage(playerid0xCC0000AA"You already voted!");
    
NoVotes++;
    
HasVoted[playerid] = true;
    new 
string[50];
    
format(stringsizeof(string), "{00CCCC}| Vote System | {00CC00}Yes: %i {CC0000}No: %i"YesVotesNoVotes);
    
SendClientMessageToAll(0x00CCCCAAstring);
    return 
1;
}
CMD:vkick(playeridparams[]) return cmd_votekick(playeridparams);
CMD:vyes(playerid) return cmd_voteyes(playerid);
CMD:vno(playerid) return cmd_voteno(playerid); 
PHP код:
forward VoteEnd(playerid);
public 
VoteEnd(playerid)
{
    new 
votestring[128];
    if(
YesVotes == NoVotesformat(votestringsizeof(votestring), "Vote Failed. Yes: %i No: %i"YesVotesNoVotes);
    else if(
YesVotes NoVotes)
    {
        
format(votestringsizeof(votestring), "%s got vote kicked. Yes: %i No: %i (Reason: %s)"YesVotesNoVotesVoteReason);
        
SendClientMessage(playeridVoteAgainstvotestring);
        
Kick(VoteAgainst);
    }
    else 
format(votestringsizeof(votestring), "Votekick failed. Yes: %i No: %i"YesVotesNoVotes);
    
SendClientMessageToAll(0x00CCCCAAvotestring);
    
VoteAgainst = -1;
    
VoteReason "\0";
    
YesVotes 0NoVotes 0;
    for(new 
i=0MAX_PLAYERSi++) if(HasVoted[i]) HasVoted[i] = false;
    
VoteOn false;
    
KillTimer(VoteTimer);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)