You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

208 lines
7.5 KiB

#include <sourcemod>
#include <clientprefs>
#include "extra.sp"
#define VIP_COMMANDS_COUNT 4
char g_vipblock_commands[VIP_COMMANDS_COUNT][32] = {"sm_rof", "sm_aia", "sm_sethealth", "sm_speedme"};
char g_vipblock_commands_disable[VIP_COMMANDS_COUNT][32] = {"sm_rof #%i 1", "sm_aia #%i 0", "sm_sethealth %i 0", "sm_speed %i 360"};
int g_vipblock_player_votes[TF2_MAXPLAYERS][TF2_MAXPLAYERS];
float g_vipblock_need_count = 0.3;
int g_vipblock_player_settime[TF2_MAXPLAYERS];
int g_vipblock_blocktime = 900;
Handle g_vipblock_timer = INVALID_HANDLE;
char g_vipblock_votecmd[32] = "sm_votevip";
Handle g_vipblock_cookie = INVALID_HANDLE;
#define VIPBLOCK_VOTE_COMPLETE "У игрок %N был ограничен по итогу подсчетов голосов!"
#define VIPBLOCK_VOTE_VOTED "Игрок %N проголосовал за блокировку VIP у игрока %N. Проголосовать за: !voteblock в чат или через меню."
#define VIPBLOCK_TIMEOUT "Блокировка ВИП команд снята!"
stock bool VIPBlockCheckTime(int client){
if(g_vipblock_player_settime[client] && GetTime() - g_vipblock_player_settime[client] > g_vipblock_blocktime){
VIPBlockClearPlayerVotes(client);
PrintCenterText(client, VIPBLOCK_TIMEOUT);
return true;
} else return false;
}
stock bool VIPBlockCheckVotes(int client){
if(ReturnVoteCount(client, g_vipblock_player_votes) >= CalcNeedCount(g_vipblock_need_count)){
VIPBlockPlayer(client);
return true;
} else {
return false;
}
}
stock VIPBlockClearPlayerVotes(int client, bool save_cookie = true){
g_vipblock_player_settime[client] = 0;
ClearPlayerVotes(client, g_vipblock_player_votes);
if(save_cookie) VIPBlockSaveCookie(client);
}
stock VIPBlockCmdsDisable(int client){
int uid = GetClientUserId(client);
if(uid){
for(int i = 0; i < VIP_COMMANDS_COUNT;i++){
ServerCommand(g_vipblock_commands_disable[i], uid);
}
}
}
stock VIPBlockPlayer(int client){
PrintCenterTextAll(VIPBLOCK_VOTE_COMPLETE, client);
PrintToChatAll(VIPBLOCK_VOTE_COMPLETE, client);
VIPBlockClearPlayerVotes(client);
g_vipblock_player_settime[client] = GetTime();
VIPBlockSaveCookie(client);
VIPBlockCmdsDisable(client);
}
stock VIPBlockVoteOn(){
if(g_vipblock_timer != INVALID_HANDLE) KillTimer(g_vipblock_timer);
else g_vipblock_timer = CreateTimer(5.0, CallbackVIPBlockTimer, _, TIMER_REPEAT);
RegConsoleCmd(g_vipblock_votecmd, CommandVIPBlockVote, "Vote for votevipblock player on server");
RegConsoleCmd("sm_voteblock", CommandVIPBlockVote, "Vote for votevipblock player on server");
RegAdminCmd("sm_voteblock_enable", CommandVIPBlockEnable, ADMFLAG_ROOT);
g_vipblock_cookie = RegClientCookie("fv_vipblock_settime", "", CookieAccess_Private);
VIPBlockListener(true);
PrintToServer("[FV] [VIPBlock] support enable");
for(int client = 1; client <= MaxClients; client++){
if(IsValidClient(client) && AreClientCookiesCached(client)) VIPBlockCheckCookie(client);
}
}
stock VIPBlockListener(bool add = true){
for(int i = 0; i < VIP_COMMANDS_COUNT; i++){
if(add) AddCommandListener(VIPBlockCommandListener, g_vipblock_commands[i]);
else RemoveCommandListener(VIPBlockCommandListener, g_vipblock_commands[i]);
}
}
public Action VIPBlockCommandListener(int client, const char[] command, int args){
if(g_vipblock_player_settime[client] == 0) return Plugin_Handled;
if(VIPBlockCheckTime(client)){
PrintCenterText(client, "С тебя сняли ограничение на использование VIP команд!");
return Plugin_Handled;
} else {
PrintCenterText(client, "Тебе ограничен доступ к VIP командам по результатам голосования! Ограничение пропадет через %i секунд.", g_vipblock_blocktime - (GetTime() - g_vipblock_player_settime[client]));
return Plugin_Stop;
}
}
stock VIPBlockCheckCookie(int client){
VIPBlockClearPlayerVotes(client, false);
char cookie[256];
GetClientCookie(client, g_vipblock_cookie, cookie, sizeof(cookie));
if(strlen(cookie) > 0){
int settime = StringToInt(cookie);
g_vipblock_player_settime[client] = settime;
PrintToServer("[FV] [VIPBlock] %N set %i", client, g_vipblock_player_settime[client]);
}
}
stock VIPBlockSaveCookie(int client){
char cookie[256];
if(g_vipblock_player_settime[client]) Format(cookie, sizeof(cookie), "%i", g_vipblock_player_settime[client]);
else Format(cookie, sizeof(cookie), "0");
SetClientCookie(client, g_vipblock_cookie, cookie);
if(g_vipblock_player_settime[client]) PrintToServer("[FV] [VIPBlock] %N set %i", client, g_vipblock_player_settime[client]);
}
stock VIPBlockVoteOff(){
VIPBlockListener(false);
if(g_vipblock_timer != INVALID_HANDLE) KillTimer(g_vipblock_timer);
}
stock DisplayVIPBlockMenu(int client){
Handle VIPBlockMenu = CreateMenu(CallbackVIPBlockBuildMenu);
SetMenuTitle(VIPBlockMenu, "Выключить VIP у:");
char menu_line[64];
char player_uid[32];
for(int player = 1; player <= MaxClients; player++){
if(IsValidClient(player)){
//if(player == client) continue;
if(CheckCommandAccess(player, "", ADMFLAG_BAN)) continue;
if(!CheckCommandAccess(player, "", ADMFLAG_RESERVATION)) continue;
Format(player_uid, sizeof(player_uid), "%i", GetClientUserId(player));
if(g_vipblock_player_settime[player]){
Format(menu_line, sizeof(menu_line), "%N [Выключен VIP]", player);
AddMenuItem(VIPBlockMenu, player_uid, menu_line, ITEMDRAW_DISABLED);
}
else if(g_vipblock_player_votes[player][client] == 0) {
Format(menu_line, sizeof(menu_line), "%N [%i/%i]", player, ReturnVoteCount(player, g_vipblock_player_votes), CalcNeedCount(g_vipblock_need_count));
AddMenuItem(VIPBlockMenu, player_uid, menu_line);
} else {
Format(menu_line, sizeof(menu_line), "%N [Ты проголосовал]", player);
AddMenuItem(VIPBlockMenu, player_uid, menu_line, ITEMDRAW_DISABLED);
}
}
}
if(GetMenuItemCount(VIPBlockMenu) == 0){
PrintCenterText(client, "Незакого голосовать, нет випов на сервере.");
return;
}
DisplayMenu(VIPBlockMenu, client, 0);
return;
}
stock CallbackVIPBlockBuildMenu(Handle VIPBlockMenu, MenuAction action, int client, int pos){
switch(action){
case MenuAction_Select:{
char player_uid[32];
GetMenuItem(VIPBlockMenu, pos, player_uid, sizeof(player_uid));
int player = GetClientOfUserId(StringToInt(player_uid));
if(player == 0){
PrintCenterText(client, "Увы игрок вышел!");
return;
}
g_vipblock_player_votes[player][client] = 1;
if(!VIPBlockCheckVotes(player)) PrintCenterTextAll(VIPBLOCK_VOTE_VOTED, client, player);
}
case MenuAction_End: delete VIPBlockMenu;
}
return;
}
stock Action CallbackVIPBlockTimer(Handle timer){
for(int client = 1; client <= MaxClients; client++){
if(IsValidClient(client)){
VIPBlockCheckVotes(client);
VIPBlockCheckTime(client);
}
}
}
public Action CommandVIPBlockVote(int client, int args){
if (client == 0)
{
ReplyToCommand(client, "Cannot use command from RCON.");
return Plugin_Handled;
}
DisplayVIPBlockMenu(client);
return Plugin_Handled;
}
public Action CommandVIPBlockEnable(int client, int args){
char text[256], arg[64];
GetCmdArgString(text, sizeof(text));
BreakString(text, arg, sizeof(arg));
int target = FindTarget(client, arg, _, false);
if(target == -1) return Plugin_Handled;
if(g_vipblock_player_settime[target]){
ReplyToCommand(client, "Already setted!");
} else {
VIPBlockPlayer(target);
ReplyToCommand(client, "Setted!");
}
return Plugin_Handled;
}