All pastes #343634 Raw Edit

VoteServ

public cpp v1 · immutable
·published 2007-02-07 05:05 UTC
rendered paste body
/*==========================================   -VoteServ- GamerX VoteKick Service v1.0         Coded by Phantom, Matite==========================================*/#include <a_samp>#define COLOR_YELLOW 0xFFFF00AA#define COLOR_WHITE 0xFFFFFFAA#define COLOR_RED 0xFF0033AAnew Votes; // Vote Countnew Voted[MAX_PLAYERS]; // Has Player Voted?new vTimer, vPlayer, players, rVotes;new pPerc, pTime, pState, settimer; // Settingsnew gString[255];new KickTimer[MAX_PLAYERS];new reason[128];//-------------------------------------------------public OnFilterScriptInit(){	print("\n  VoteServ for GamerX\n");	print("  Loading Configuration...\n");	rConfig();	print("    Configuration: ");	printf("      |RequiredPercentage      [%d]", pPerc);	printf("      |Voting Period           [%d Seconds]", pTime);	return 1;}public PlayerName(playerid){  new pName[32];  GetPlayerName(playerid, pName, sizeof(pName));  return pName;}public OnPlayerConnect(playerid){  players++;  if(settimer!=1)	{		SetTimer("constTimer", 1000,1);	    settimer=1;	}	return 1;}public OnPlayerDisconnect(playerid){players--;Voted[playerid] = 0;KickTimer[playerid] = 0;return 1;}//--------------------------------------------------public OnPlayerCommandText(playerid, cmdtext[]){	new cmd[255], tmp[255];	new string[255];	new idx, idplayer;		cmd = strtok(cmdtext, idx);	    if(strcmp(cmd, "/votekick", true) == 0)	{	    if(vTimer > 0){ SendClientMessage(playerid, COLOR_YELLOW, "Cannot Run Concurrent Vote-Kicks!"); return 1;}		        tmp = strtok(cmdtext, idx);		if(!strlen(tmp)) {			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /votekick [PlayerID] [Reason]");			strdel(reason, 0,128);			return 1;		}		idplayer = strval(tmp);		tmp = strtok(cmdtext, idx);		if(!strlen(tmp)) {			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /votekick [PlayerID] [Reason]");			strdel(reason, 0,128);			return 1;		}  		strins(reason, tmp,0,128);				if(IsPlayerConnected(idplayer))		{			vPlayer = idplayer;			vTimer = (pTime + 1);   			rVotes = ((players * pPerc) / 100);			format(string, sizeof(string), "-VoteServ- %s has started a votekick for %s (%s)", PlayerName(playerid), PlayerName(vPlayer), reason);			SendClientMessageToAll(COLOR_YELLOW, string);			format(string, sizeof(string), "*** %d Votes Required for kicking [Type /vote to vote]", rVotes);            SendClientMessageToAll(COLOR_YELLOW, string);			return 1;		}	 }	 	 else if(strcmp(cmdtext, "/vote", true) == 0)	 {	    if(vTimer < 1){ SendClientMessage(playerid, COLOR_WHITE, "There are no votekicks in action"); return 1;}	    if(Voted[playerid] == 1){ SendClientMessage(playerid, COLOR_WHITE, "You have already voted!"); return 1;}	    	 	Votes++;	 	Voted[playerid] = 1;	    format(string, sizeof(string), "-VoteServ- %s has voted to kick %s (total votes: %d/%d)", PlayerName(playerid), Votes, rVotes);	    SendClientMessageToAll(COLOR_YELLOW, string);	    if(Votes == rVotes){ VoteKickSuccessful(); }	    return 1;	    }	         else if(strcmp(cmdtext, "/vs end", true) == 0)	 {	    if(vTimer < 1){ SendClientMessage(playerid, COLOR_WHITE, "There are no vote kicks in action"); return 1;}        AdminEndVoteKick(playerid);	    return 1;	    }	         else if(strcmp(cmdtext, "/vs help", true) == 0)	 	{	    SendClientMessage(playerid, COLOR_YELLOW,"GamerX VoteKick Service [VoteServ]");		SendClientMessage(playerid, COLOR_YELLOW,"Availible Commands:");		SendClientMessage(playerid, COLOR_YELLOW,"/votekick [PlayerID] [Reason]");		SendClientMessage(playerid, COLOR_YELLOW,"/vote - Votes for Current VoteKick");		SendClientMessage(playerid, COLOR_YELLOW,"/view - Displays Current VoteKick");	    return 1;	    }	 else if(strcmp(cmdtext, "/view", true) == 0)	 {        if(vTimer < 1){SendClientMessage(playerid, COLOR_WHITE, "There are no vote kicks in action");return 1;}        	format(string, sizeof(string), "-VoteServ- Current VoteKick for %s (%s)", PlayerName(vPlayer), reason);       		SendClientMessageToAll(COLOR_YELLOW, string);			format(string, sizeof(string), "*** [%d/%d] Votes Required for kicking [Type /vote to vote]", rVotes, Votes);			SendClientMessageToAll(COLOR_YELLOW, string);			return 1;	}	return 0;}public constTimer(){	if(vTimer > 1)	{	vTimer--;	}	if(vTimer == 1)	{	EndVoteKick();	vTimer--;	}}//-------------------------------------------------------------EndVoteKick(){ClearVoted();Votes = 0;format(gString, sizeof(gString), "-VoteServ- Attempt to vote kick %s failed", PlayerName(vPlayer));SendClientMessageToAll(COLOR_YELLOW, gString);vPlayer = -1;strdel(reason, 0,128);return 1;}AdminEndVoteKick(playerid){ClearVoted();Votes = 0;vTimer = 0;format(gString, sizeof(gString), "-VoteServ- VoteKick for %s was canceled by an Admin", PlayerName(vPlayer), PlayerName(playerid));SendClientMessageToAll(COLOR_YELLOW, gString);vPlayer = -1;strdel(reason, 0,128);return 1;}VoteKickSuccessful(){ClearVoted();Votes = 0;format(gString, sizeof(gString), "-OperServ- %s has been kicked by VoteServ (%s)", PlayerName(vPlayer), reason);SendClientMessageToAll(COLOR_RED, gString);KickTimer[vPlayer] = 1;SetTimer("vKick", 500, 0);vPlayer = -1;strdel(reason, 0,128);return 1;}ClearVoted(){for(new i=0;i<MAX_PLAYERS;i++)	{	if(IsPlayerConnected(i))	{		Voted[i] = 0;	}}}//--------------------------------------------------------------------rConfig(){	new File:fhandle;	new cname[256];	new temp[256];	new value[256];	fhandle = fopen("podconfig.txt",io_readwrite);		while(fread(fhandle,temp,sizeof(temp),false))		{		    cname = strtok2(temp,0);			value = strtok2(temp,(strlen(cname)+1));   			if(strcmp(cname,"Method",true) == 0) pState = strval(value); // Unused			else if(strcmp(cname,"Percent",true) == 0) pPerc = strval(value);			else if(strcmp(cname,"Vote-Timer",true) == 0) pTime = strval(value);		}		fclose(fhandle);		return 1;}//----------------------------------------------------------public vKick(){for(new j=0;j<MAX_PLAYERS;j++)	{		if(IsPlayerConnected(j))		{		    if(KickTimer[j] == 1)		    {		    KickTimer[j] = 0;		    Kick(j);		    }		}	}}//-----------------------------------------------------------strtok2(const string[],valve){	new index=valve;	new length = strlen(string);	while ((index < length) && (string[index] <= ' '))	{		index++;	}	new offset = index;	new result[20];	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))	{		result[index - offset] = string[index];		index++;	}	result[index - offset] = EOS;	return result;}strtok(const string[], &index){	new length = strlen(string);	while ((index < length) && (string[index] <= ' '))	{		index++;	}	new offset = index;	new result[20];	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))	{		result[index - offset] = string[index];		index++;	}	result[index - offset] = EOS;	return result;}