#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1
#define DATA "1.1.2NoMapchange"
new MuertesCT;
new MuertesT;
new bool:GanadoCT;
new bool:GanadoT;
new bool:is_cstrike;
new g_iGoal;
public Plugin:myinfo =
{
name = "SM Frag Battle",
author = "Franc1sco Steam: franug & AlmazON",
description = "Frag battle",
version = DATA,
url = "www.uea-clan.com"
};
public OnPluginStart()
{
HookEvent("player_death", playerDeath);
decl Handle:cvar_Goal, EngineVersion:engine;
HookConVarChange(cvar_Goal = CreateConVar("sm_fragbattle_goal", "500", "Goal for win.", _, true, 1.0), ChangeCvar_Goal);
g_iGoal = GetConVarInt(cvar_Goal);
CreateConVar("sm_fragbattle_version", DATA, "Frag Battle version.", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
if((engine = GetEngineVersion()) == Engine_CSS || engine == Engine_CSGO) is_cstrike = true;
}
public ChangeCvar_Goal(Handle:convar, String:oldValue[], String:newValue[]) g_iGoal = GetConVarInt(convar);
public OnConfigsExecuted()
{
ResetAll();
CreateTimer(1.0, Temporizador, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public Action:Temporizador(Handle:timer)
{
decl String:Mensaje[256], clients[MaxClients], Handle:hBuffer;
if(GanadoCT) FormatEx(Mensaje, sizeof(Mensaje), "Frag Battle\nCounter-Terrorist Win!\nT CT\n%i %i", g_iGoal, MuertesT, MuertesCT);
else if(GanadoT) FormatEx(Mensaje, sizeof(Mensaje), "Frag Battle\nTerrorist Win!\nT CT\n%i %i", g_iGoal, MuertesT, MuertesCT);
else FormatEx(Mensaje, sizeof(Mensaje), "Frag Battle\nGoal: %i\nT CT\n%i %i", g_iGoal, MuertesT, MuertesCT);
new numClients;
for (new i = 1; i <= MaxClients; ++i)
{
if(IsClientInGame(i) && !IsFakeClient(i)) clients[numClients++] = i;
}
// Send our message
BfWriteByte(hBuffer = StartMessage("KeyHintText", clients, numClients), 1);
BfWriteString(hBuffer, Mensaje);
EndMessage();
return Plugin_Continue;
}
public playerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
if(!GanadoCT && !GanadoT)
{
decl attacker;
if((attacker = GetClientOfUserId(GetEventInt(event, "attacker"))))
{
decl team;
if((team = GetClientTeam(attacker)) != GetClientTeam(GetClientOfUserId(GetEventInt(event, "userid"))))
{
switch (team)
{
case CS_TEAM_T:
{
if(++MuertesT >= g_iGoal) FinT();
}
case CS_TEAM_CT:
{
if(++MuertesCT >= g_iGoal) FinCT();
}
}
}
}
}
}
FinCT()
{
GanadoCT = true;
PrintToChatAll("\x04[Frag Battle] \x03Counter-Terrorist win the Frag Battle!");
if(is_cstrike) CS_TerminateRound(5.0, CSRoundEnd_CTWin);
else
{
for (new client=1; client<=MaxClients; ++client)
if (IsClientInGame(client) && IsPlayerAlive(client) && GetClientTeam(client) == CS_TEAM_T)
ForcePlayerSuicide(client);
}
CreateTimer(5.0, NewGame, _, TIMER_FLAG_NO_MAPCHANGE);
}
FinT()
{
GanadoT = true;
PrintToChatAll("\x04[Frag Battle] \x03Terrorist win the Frag Battle!");
if(is_cstrike) CS_TerminateRound(5.0, CSRoundEnd_TerroristWin);
else
{
for (new client=1; client<=MaxClients; ++client)
if (IsClientInGame(client) && IsPlayerAlive(client) && GetClientTeam(client) == CS_TEAM_CT)
ForcePlayerSuicide(client);
}
CreateTimer(5.0, NewGame, _, TIMER_FLAG_NO_MAPCHANGE);
}
public Action:NewGame(Handle:timer)
{
ResetAll();
Temporizador(timer);
return Plugin_Stop;
}
public OnClientDisconnect_Post(client)
{
if(!GetClientCount()) ResetAll();
}
ResetAll()
{
MuertesCT = 0;
MuertesT = 0;
GanadoCT = false;
GanadoT = false;
}