Anyhow repair this script. (index error) and overall
PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#define PREFIX "\x06[Jail]\x04"
new I_ClientTime[26];
new bool:B_Info;
new bool:AllowCT = true;
new bool:P_Info[32][2];
public Plugin:myinfo = {
name = "No more nepoměr",
author = "ffredyk and Blodhblaka",
description = "Jailbreak Difference Balance - 1 CT to every 2 T",
version = "1.1",
url = "http://newera.fakaheda.eu"
};
public OnPluginStart()
{
HookEvent("round_prestart", RoundStart);
HookEvent("player_team", TeamChange, EventHookMode_Pre);
AddCommandListener(TeamJoin, "jointeam");
}
public OnClientConnected(client)
{
I_ClientTime[client] = 0; //Reset timestampu
}
public OnMapStart()
{
for(new i=1;i<26;i++)
{
if(IsClientConnected(i))
{
I_ClientTime[i] = RoundToNearest(GetClientTime(i));
}
}
}
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
{
{
CreateTimer(5.0, Blodhblaka2);
}
ResetInfo();
B_Info = true;
ComputeDiff();
for(new i=1;i<26;i++)
{
if(IsClientInGame(i))
{
if(P_Info[i][0])
{
PrintToChat(i,"%s Nemůžeš k CT, protože není dostatečný poměr!", PREFIX);
P_Info[i][0] = false;
}
if(P_Info[i][1])
{
PrintToChat(i,"%s Byl jsi přesunut k Terroristům, protože kazíš poměr!", PREFIX);
P_Info[i][1] = false;
}
}
}
}
}
public Action:Blodhblaka2(Handle:timer)
{
ResetInfo();
B_Info = true;
ComputeDiff();
for(new i=1;i<33;i++)
{
if(IsClientInGame(i))
{
if(P_Info[i][0])
{
PrintToChat(i,"%s Nemůžeš k CT, protože není dostatečný poměr!", PREFIX);
P_Info[i][0] = false;
}
if(P_Info[i][1])
{
PrintToChat(i,"%s Byl jsi přesunut k Terroristům, protože kazíš poměr!", PREFIX);
P_Info[i][1] = false;
}
}
}
}
public Action:TeamJoin(client, const String:command[], argc)
{
B_Info = false;
ComputeDiff();
if(SwitchTest(client))
{
return Plugin_Continue;
}
else
{
return Plugin_Handled;
}
}
public Action:TeamChange(Handle:event, const String:name[], bool:dontBroadcast)
{
B_Info = false;
ComputeDiff();
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(SwitchTest(client))
{
return Plugin_Continue;
}
else
{
return Plugin_Handled;
}
}
public SwitchTest(client)
{
if(AllowCT)
{
return true;
}
else
{
if(GetUserAdmin(client)!= INVALID_ADMIN_ID)
{
return true;
}
else
{
P_Info[client][0] = true;
PrintToChat(client,"%s Nemůžeš k CT, protože není dostatečný poměr!", PREFIX);
return false;
}
}
}
public ComputeDiff()
{
new TCount = GetTeamClientCount(CS_TEAM_T);
new CTCount = GetTeamClientCount(CS_TEAM_CT);
TCount = TCount - (TCount % 2);
new CTAllowed = TCount / 2;
if(CTCount > CTAllowed && TCount > 0 && CTCount > 0)
{
ScrambleCT();
AllowCT = false;
}
else
{
AllowCT = true;
if(B_Info) PrintToChatAll("%s Poměr je %.2f (optimum je 0.5)", PREFIX, float(CTCount) / float(TCount));
B_Info = false;
}
}
public ScrambleCT()
{
new targetTime = 999999; //Client time
new targetClient = -1; //Result client
for(new i=1;i<33;i++)
{
if(IsClientConnected(i) && GetClientTeam(i) == CS_TEAM_CT)
{
new time = RoundToNearest(GetClientTime(i));
if(GetUserAdmin(i)!= INVALID_ADMIN_ID)
{
targetClient = -99999;
}
else
{
if(time < targetTime)
{
targetTime = time;
targetClient = i;
}
}
}
}
if(targetClient > 0 && IsClientInGame(targetClient))
{
SetEntProp(targetClient, Prop_Send, "m_lifeState", 2);
ChangeClientTeam(targetClient, 2);
if(GetClientHealth(targetClient) > 0)
{
SetEntProp(targetClient, Prop_Send, "m_lifeState", 0);
}
P_Info[targetClient][1] = true;
ComputeDiff();
}
}
public ResetInfo()
{
for(new i=0;i<26;i++)
{
P_Info[i][0] = false;
P_Info[i][1] = false;
}
}