/* Plugin Made by: $harp$niper */
 
/* This will allow people on the server to vote for any gravity not just low or normal Example: admin_vote_gravity 200 : Will vote to change gravity to 200 so you can see this is much better than any other gravity voting plugins.*/
 
/* If you want to edit this you may edit in any way you wish but you much mention my name as orignal creator */
 
/* This Command is made for gravity voting to allow anyone to vote for any set of gravity at any time if the voting freq allows it */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_VOTE_GRAVITY ACCESS_VOTE_KICK
#define GRAVITY_VOTE_RATIO 55
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
new LogFile[]="Logs.txt";
 
public admin_vote_gravity(HLCommand,HLData,HLUser,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	if (vote_allowed()!=1) {
		selfmessage("Vote not allowed at this time.");
		return PLUGIN_HANDLED;	
	}
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUser,User,MAX_NAME_LENGTH);
	getvar("sv_gravity");
	snprintf(Text, MAX_TEXT_LENGTH, "Change Gravity to %s ?", Data);
	log(Text);
	vote(Text,"Yes","No","HandleGravVote",Data);
	say_command(User,Command,Data);
	snprintf(Text, MAX_TEXT_LENGTH, "[ADMIN] %s used %s %s.", User, Command, Data);
	writefile(LogFile, Text);
	return PLUGIN_HANDLED;
}
 
public HandleGravVote(WinningOption,HLGravity,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new strGravity[MAX_DATA_LENGTH];
	new Ratio = GRAVITY_VOTE_RATIO;
	convert_string(HLGravity,strGravity,MAX_DATA_LENGTH);
 
	if (WinningOption == 1) {
		if (VoteCount >= Ratio*UserCount/100) {
			snprintf(Text, MAX_TEXT_LENGTH, "Changing Gravity to %s due to a vote.", strGravity);
			say(Text);
			exec("admin_quiet 2");
			plugin_exec("admin_gravity",strGravity);
			exec("admin_quiet 0");
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Gravity vote succeded but not enough for change (needed %s).", strNumber);
			say(Text);
		}
	} else {
		say("Gravity vote failed.");
	}
}
 
public plugin_init() {
	plugin_registerinfo("Sharps Advanced Grav Vote","Vote for any gravity.",STRING_VERSION);
	plugin_registercmd("admin_vote_gravity","admin_vote_gravity",ACCESS_VOTE_GRAVITY,"admin_vote_gravity <gravity> : Votes to change gravity.");
	return PLUGIN_CONTINUE;
}