[quote]#include <amxmodx>
#include <amxmisc>
#define PLUGIN "TimeLimit vote"
#define AUTHOR "many"
#define VERSION "0.4"
#define MAX_RESULTS 5
#pragma semicolon 1
//thnx pr4er for help
new Float:g_timelimit;
new menu;
new g_voteCount[MAX_RESULTS + 1];
new g_tls[MAX_RESULTS];
new tls[MAX_RESULTS];
new g_CountSys;
enum Color {
NORMAL = 1, // clients scr_concolor cvar color
GREEN, // Green Color
TEAM_COLOR, // Red, grey, blue
GREY, // grey
RED, // Red
BLUE, // Blue
};
new TeamName[][] = {
"",
"TERRORIST",
"CT",
"SPECTATOR"
};
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
g_CountSys = register_cvar("amx_countsys", "1");
new name[12], string[12];
new multiplic = 20;// +++++
for(new i=0;i<MAX_RESULTS;i++) {
format(name, sizeof name -1, "amx_tl_%d", i+1);
format(string, sizeof string -1, "%d", multiplic);
tls = register_cvar(name, string);
multiplic += 10;
}
}
public plugin_cfg() {
menu = menu_create("\wCat vrei sa joci pe aceasta harta ?", "menu_handler");
for(new i=0;i<MAX_RESULTS;i++)
g_tls = get_pcvar_num(tls);
set_task(180.0, "start_vote");
build_menu();
}
build_menu() {
new option[64], temp[12];
for(new i=0;i<MAX_RESULTS;i++) {
format(option, sizeof option -1, "\w%d minute", g_tls);
format(temp, sizeof temp -1, "%d", i+1);
menu_additem(menu, option, temp, 0);
}
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
}
public start_vote(id) {
new players[32], inum, i;
get_players(players, inum, "ch");
for(i=0;i<inum;i++)
menu_display(players, menu, 0);
set_task(15.0, "finish_vote");
for(i=1;i<(MAX_RESULTS+1);i++)
g_voteCount = 0;
return PLUGIN_CONTINUE;
}
public menu_handler(id, menu, item) {
if( !is_user_connected( id ) )
return PLUGIN_HANDLED ;
if(item == MENU_EXIT) {
menu_cancel(id);
return PLUGIN_HANDLED;
}
new data[6], name[32];
new access, callback;
menu_item_getinfo(menu, item, access, data, 5, "", 0, callback);
new key = str_to_num(data);
get_user_name(id, name, 31);
ColorChat(0, GREEN, "[AMXX] %s^x01 vrea sa joace^x04 %d^x01 minute !", name, g_tls[key -1]);
g_voteCount[key]++;
menu_cancel(id);
return PLUGIN_HANDLED;
}
public finish_vote() {
new players[32], inum;
get_players(players, inum, "ch");
for(new i=0;i<inum;i++)
client_cmd(players, "slot10");
CountVotes();
}
public CountVotes() {
g_timelimit = get_cvar_float("mp_timelimit");
new votesNum = 0;
if(!get_pcvar_num(g_CountSys)) {
new best = 0;
for(new i=1;i<(MAX_RESULTS+1);i++) {
if(g_voteCount > g_voteCount[best])
best = i;
}
for(new i=1;i<(MAX_RESULTS+1);i++)
votesNum += g_voteCount;
new iRatio = votesNum ? floatround(get_cvar_float("amx_vote_ratio") * float(votesNum), floatround_ceil) : 1;
new iResult = g_voteCount[best];
if(iResult >= iRatio) {
new new_time = g_tls[best -1];
ColorChat(0, GREEN, "[AMXX]^x01 Se vor juca^x04 %d^x01 minute pe aceasta harta !", new_time);
set_cvar_num("mp_timelimit", new_time);
}
else {
ColorChat(0, GREEN, "[AMXX]^x01 Votare nereusita!");
}
}
if(get_pcvar_num(g_CountSys) == 1) {
new summ_time = 0;
new _time;
for(new i=1;i<(MAX_RESULTS+1);i++) {
votesNum += g_voteCount;
summ_time += g_voteCount[i] * g_tls[i-1];
}
if(votesNum) {
_time = floatround(float(summ_time) / float(votesNum), floatround_ceil);
if (_time - (_time = _time / 10 * 10) >= 5)
_time += 10;
ColorChat(0, GREEN, "[AMXX]^x01 Se vor juca^x04 %d^x01 minute pe aceasta harta !", _time);
set_cvar_num("mp_timelimit", _time);
}
else {
ColorChat(0, GREEN, "[AMXX]^x01 Votare nereusita!");
}
}
}
public plugin_end() {
set_cvar_float("mp_timelimit", g_timelimit);
}
ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) {
new message[256];
switch(type) {
case NORMAL: // clients scr_concolor cvar color
{
message[0] = 0x01;
}
case GREEN: // Green
{
message[0] = 0x04;
}
default: // White, Red, Blue
{
message[0] = 0x03;
}
}
vformat(message[1], 251, msg, 4);
// Make sure message is not longer than 192 character. Will crash the server.
message[192] = '^0';
new team, ColorChange, index, MSG_Type;
if(id) {
MSG_Type = MSG_ONE;
index = id;
} else {
index = FindPlayer();
MSG_Type = MSG_ALL;
}
team = get_user_team(index);
ColorChange = ColorSelection(index, MSG_Type, type);
ShowColorMessage(index, MSG_Type, message);
if(ColorChange) {
Team_Info(index, MSG_Type, TeamName[team]);
}
}
ShowColorMessage(id, type, message[]) {
static bool:saytext_used;
static get_user_msgid_saytext;
if(!saytext_used)
{
get_user_msgid_saytext = get_user_msgid("SayText");
saytext_used = true;
}
message_begin(type, get_user_msgid_saytext, _, id);
write_byte(id);
write_string(message);
message_end();
}
Team_Info(id, type, team[]) {
static bool:teaminfo_used;
static get_user_msgid_teaminfo;
if(!teaminfo_used) {
get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
teaminfo_used = true;
}
message_begin(type, get_user_msgid_teaminfo, _, id);
write_byte(id);
write_string(team);
message_end();
return 1;
}
ColorSelection(index, type, Color:Type) {
switch(Type) {
case RED:
{
return Team_Info(index, type, TeamName[1]);
}
case BLUE:
{
return Team_Info(index, type, TeamName[2]);
}
case GREY:
{
return Team_Info(index, type, TeamName[0]);
}
}
return 0;
}
FindPlayer() {
new i = -1;
while(i <= get_maxplayers()) {
if(is_user_connected(++i))
return i;
}
return -1;
}[/quote]