#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <colorchat>
#define MAX_players 32
#define MAX_menudata 1024
new ga_PlayerName[MAX_players][32]
new ga_PlayerAuthID[MAX_players][35]
new ga_PlayerID[MAX_players]
new ga_PlayerIP[MAX_players][16]
new ga_MenuData[MAX_menudata]
new ga_Choice[2]
new gi_VoteStarter
new gi_MenuPosition
new gi_Sellection
new gi_TotalPlayers
new gi_SysTimeOffset = 0
new i
new idol
new idoll[32]
//pcvars
new gi_LastTime
new gi_DelayTime
new gf_Ratio
new gf_MinVoters
new gf_BF_Ratio
new gi_BanTime
new gi_Disable
new gi_BanType
public plugin_init()
{
register_plugin("VoteBan_2","2.0","WTF")
register_clcmd("say /voteban","SayIt" )
register_clcmd("say voteban","SayIt" )
register_menucmd(register_menuid("ChoosePlayer"),1023,"ChooseMenu")
register_menucmd(register_menuid("VoteMenu"),1023,"CountVotes")
gi_LastTime=register_cvar("amx_voteban_lasttime","0")
gi_DelayTime=register_cvar("amxx_voteban_delaytime","120")
gf_Ratio=register_cvar("amxx_voteban_ratio","0.70")
gf_MinVoters=register_cvar("amxx_voteban_minvoters","0.0")
gf_BF_Ratio=register_cvar("amxx_voteban_bf_ratio","0.20")
gi_Disable=register_cvar("amxx_voteban_disable","0")
gi_BanType=register_cvar("amxx_voteban_type","2")
}
public SayIt(id)
{
if(get_pcvar_num(gi_Disable))
{
client_print(id,print_chat,"VoteBan off.")
return 0
}
new Elapsed=get_systime(gi_SysTimeOffset) - get_pcvar_num(gi_LastTime)
new Delay=get_pcvar_num(gi_DelayTime)
if((Delay > Elapsed) && !is_user_admin(id))
{
new seconds = Delay - Elapsed
ColorChat(id,RED,"[VOTEBAN] Голосование возможно через %d секунд.",seconds)
return 0
}
get_players(ga_PlayerID,gi_TotalPlayers)
for(i=0;i<gi_TotalPlayers;i++)
{
new TempID = ga_PlayerID[i]
if(TempID == id)
gi_VoteStarter=i
get_user_name(TempID,ga_PlayerName[i],31)
get_user_authid(TempID,ga_PlayerAuthID[i],34)
get_user_ip(TempID,ga_PlayerIP[i],15,1)
}
gi_MenuPosition = 0
ShowPlayerMenu(id)
return 0
}
public timed(id)
{
new i_Menu = menu_create("\rВыбери время бана:", "server_menu")
menu_additem(i_Menu, "\r15 \wминут", "1", 0)
menu_additem(i_Menu, "\r30 \wминут", "2", 0)
menu_additem(i_Menu, "\r1 \wчас", "3", 0)
menu_additem(i_Menu, "\r2 \wчаса", "4", 0)
menu_additem(i_Menu, "\r3 \wчаса", "5", 0)
menu_setprop(i_Menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, i_Menu, 0)
return PLUGIN_HANDLED
}
public server_menu(id, menu, item)
{
if (item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new s_Data[6], s_Name[64], i_Access, i_Callback
menu_item_getinfo(menu, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(s_Name), i_Callback)
new i_Key = str_to_num(s_Data)
switch(i_Key)
{
case 1:
{
gi_BanTime = 15
run_vote()
}
case 2:
{
gi_BanTime = 30
run_vote()
}
case 3:
{
gi_BanTime = 60
run_vote()
}
case 4:
{
gi_BanTime = 120
run_vote()
}
case 5:
{
gi_BanTime = 180
run_vote()
}
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
public ShowPlayerMenu(id)
{
new arrayloc = 0
new keys = (1<<9)
arrayloc = format(ga_MenuData,(MAX_menudata-1),"\r[\wVOTEBAN\r] \wУкажи игрока:^n")
for(i=0;i<8;i++)
if( gi_TotalPlayers>(gi_MenuPosition+i))
{
arrayloc += format(ga_MenuData[arrayloc],(MAX_menudata-1-arrayloc),"\y%d.\w%s^n",i+1,ga_PlayerName[gi_MenuPosition+i])
keys |= (1<<i)
}
if( gi_TotalPlayers>(gi_MenuPosition+8))
{
arrayloc += format(ga_MenuData[arrayloc],(MAX_menudata-1-arrayloc),"^n\y9.\r[\wДалее\r]")
keys |= (1<<8)
}
arrayloc += format(ga_MenuData[arrayloc],(MAX_menudata-1-arrayloc),"^n\y0.\r[\wВыход\r]")
show_menu(id,keys,ga_MenuData,20,"ChoosePlayer")
return PLUGIN_HANDLED
}
public ChooseMenu(id,key)
{
switch(key)
{
case 8:
{
gi_MenuPosition=gi_MenuPosition+8
ShowPlayerMenu(id)
}
case 9:
{
if(gi_MenuPosition>=8)
{
gi_MenuPosition=gi_MenuPosition-8
ShowPlayerMenu(id)
}
else
return 0
}
default:
{
gi_Sellection=gi_MenuPosition+key
new admin = get_user_index(ga_PlayerName[gi_Sellection])
if (get_user_flags(admin) & ADMIN_LEVEL_H)
{
ColorChat(0, RED, "[VOTEBAN] ^x04%s ^x03является админом! Банить нельзя!", ga_PlayerName[gi_Sellection])
return 0
}
else
{
timed(id)
return 0
}
}
}
return PLUGIN_HANDLED
}
public run_vote()
{
new Now=get_systime(gi_SysTimeOffset)
idol = get_user_index(ga_PlayerName[gi_Sellection])
set_pcvar_num(gi_LastTime, Now)
get_user_ip(idol,idoll,15,1)
log_amx("VoteBan Запустил %s против %s %s.=D.",ga_PlayerName[gi_VoteStarter],ga_PlayerName[gi_Sellection],ga_PlayerAuthID[gi_Sellection])
ColorChat(0, RED, "[VOTEBAN] Голосование запустил ^x04%s ^x03против ^x04%s", ga_PlayerName[gi_VoteStarter],ga_PlayerName[gi_Sellection])
format(ga_MenuData,(MAX_menudata-1),"Голосование запустил \y%s^n\wЗабанить \r%s \wна \r%d \wминут?^n\y1.\wДа^n\y2.\wНет",ga_PlayerName[gi_VoteStarter],ga_PlayerName[gi_Sellection],gi_BanTime)
ga_Choice[0] = 0
ga_Choice[1] = 0
show_menu(0,(1<<0)|(1<<1),ga_MenuData,15,"VoteMenu" )
set_task(20.0,"outcom")
return 0
}
public CountVotes(id,key)
{
++ga_Choice[key]
return PLUGIN_HANDLED
}
public outcom()
{
new TotalVotes = ga_Choice[0] + ga_Choice[1]
new Float:result = (float(ga_Choice[0]) / float(TotalVotes))
if(get_pcvar_float(gf_MinVoters) >= (float(TotalVotes) / float(gi_TotalPlayers)))
{
ColorChat(0,RED,"[VOTEBAN] Недостаточно голосов за Бан ^x04%s!",ga_PlayerName[gi_Sellection])
return 0
}
else
{
if(result < get_pcvar_float(gf_BF_Ratio))
{
ColorChat(0,RED,"[VOTEBAN] ^x04%s ^x03забанен на ^x04%d ^x03минут.",ga_PlayerName[gi_VoteStarter],gi_BanTime)
ActualBan(gi_VoteStarter)
log_amx("[AMXX] %s was Banned for %d minutes.",ga_PlayerName[gi_VoteStarter],gi_BanTime)
}
if( result >= get_pcvar_float(gf_Ratio) )
{
ColorChat(0,RED,"[VOTEBAN] ^x04%s ^x03забанен на ^x04%d ^x03минут.",ga_PlayerName[gi_Sellection],gi_BanTime)
log_amx("[AMXX] %s was Banned for %d minutes.",ga_PlayerAuthID[gi_Sellection],gi_BanTime)
ActualBan(gi_Sellection)
}
else
{
ColorChat(0,RED,"[VOTEBAN] Голосование не состоялось. Недостаточно голосов.")
log_amx("[AMXX] The VoteBan dit not sucseed.")
}
}
ColorChat(0,RED,"[VOTEBAN] Проголосовало ^x04%d ^x03игроков, ^x04%d ^x03За.",gi_TotalPlayers,ga_Choice[0])
return 0
}
public ActualBan(Selected)
{
new Type = get_pcvar_num(gi_BanType)
get_user_name(idol, idoll, 31)
switch(Type)
{
case 1:
server_cmd("addip %d %s",gi_BanTime,ga_PlayerIP[Selected])
case 2:
server_cmd("amx_ban %d %s VoteBan",gi_BanTime, idoll)
case 3:
server_cmd("amx_bancs %s %d Voteban",ga_PlayerName[gi_Sellection], gi_BanTime)
default:
server_cmd("banid %d %s kick",gi_BanTime,ga_PlayerAuthID[Selected])
}
return 0
}