#include <cstrike>
#include <sdktools>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo =
{
name = "Bot Replacer",
author = "SenatoR, babka68",
description = "Игрок может сыграть вместо бота",
version = "1.3",
url = "https://vk.com/zakazserver68, hlmod.ru"
}
Handle CheckSpecTimer[MAXPLAYERS + 1];
int BotAmount[MAXPLAYERS + 1], g_iAmountBot, g_iPriceBot;
bool g_bShow_Message_Hud, g_bType_Kick;
public void OnPluginStart()
{
HookEvent("round_start", EventRoundStart);
HookEvent("round_end", EventRoundEnd);
ConVar cvar;
cvar = CreateConVar("sm_bot_replacer_amount", "1", "Сколько раз за раунд игрок может сыграть вместо бота?", _, true, 0.0, true, 20.0);
cvar.AddChangeHook(CVarChanged_Amount_Bot);
g_iAmountBot = cvar.IntValue;
cvar = CreateConVar("sm_bot_replacer_price", "2000", "Сколько стоит сыграть за бота?", _, true, 0.0, true, 16000.0);
cvar.AddChangeHook(CVarChanged_Price_Bot);
g_iPriceBot = cvar.IntValue;
cvar = CreateConVar("sm_bot_replacer_showhud", "1", "Показывать сообщение, что можно играть за бота?", _, true, 0.0, true, 1.0);
cvar.AddChangeHook(CVarChanged_Show_Message_Hud);
g_bShow_Message_Hud = cvar.BoolValue;
cvar = CreateConVar("sm_bot_replacer_typekick", "0", "0 - Кикнуть бота, 1 - Удалить бота", _, true, 0.0, true, 1.0);
cvar.AddChangeHook(CVarChanged_Type_Kick);
g_bType_Kick = cvar.BoolValue;
AutoExecConfig(true, "sm_bot_replacer");
}
public void CVarChanged_Amount_Bot(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_iAmountBot = cvar.IntValue;
}
public void CVarChanged_Price_Bot(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_iPriceBot = cvar.IntValue;
}
public void CVarChanged_Show_Message_Hud(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_bShow_Message_Hud = cvar.BoolValue;
}
public void CVarChanged_Type_Kick(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_bType_Kick = cvar.BoolValue;
}
public void OnClientPostAdminCheck(int client)
{
if (!IsFakeClient(client))
{
BotAmount[client] = 0;
if (g_bShow_Message_Hud)
CheckSpecTimer[client] = CreateTimer(1.0, Spec_Timer, client, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action Spec_Timer(Handle timer, any client)
{
int i = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if (i > 0 && IsFakeClient(i) && GetClientTeam(client) == GetClientTeam(i) && IsPlayerAlive(i))
{
PrintHintText(client, "Нажмите E, чтобы играть за бота %N", i);
}
return Plugin_Continue;
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon)
{
if (buttons & IN_USE && !IsPlayerAlive(client))
{
int i = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
int price = g_iPriceBot;
int cash = GetEntProp(client, Prop_Send, "m_iAccount");
if (i > 0 && IsFakeClient(i) && GetClientTeam(client) == GetClientTeam(i) && BotAmount[client] < g_iAmountBot && price <= cash)
{
SetEntProp(client, Prop_Send, "m_iAccount", cash - price);
int health = GetClientHealth(i);
int armor = GetClientArmor(i);
float pos[3];
GetClientAbsOrigin(i, pos);
if (g_bType_Kick)
ServerCommand("bot_kick %N", i);
else
KickClient(i);
CS_RespawnPlayer(client);
SetEntityHealth(client, health);
SetEntProp(client, Prop_Data, "m_ArmorValue", armor);
TeleportEntity(client, pos, NULL_VECTOR, NULL_VECTOR);
BotAmount[client]++;
}
}
return Plugin_Continue;
}
public void EventRoundStart(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i))
{
BotAmount[i] = 0;
}
}
}
public void EventRoundEnd(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i))
{
BotAmount[i] = 0;
}
}
}
public void OnClientDisconnect(int client)
{
if (CheckSpecTimer[client] != null)
{
KillTimer(CheckSpecTimer[client]);
CheckSpecTimer[client] = null;
}
BotAmount[client] = 0;
}