OnClientConnected is still commented out while OnClientDisconnect is what should be commented out. The primary reason to be using this plugin is wasted.
Its also rather spammy when people connect and join their team (they actually join 2 teams - spectator first).
I replaced OnClientConnected, OnClientDisconnect and JoinTeam with the following:
PHP Code:
public OnClientConnected(client)
{
if (IsFakeClient(client)) return;
Joining[client] = false;
CSkipNextClient(client);
CPrintToChatAll("%sPlayer: {green}%N{default} has connected to the server.", TAG_INFO, client);
}
public OnClientDisconnect(client)
{
if (IsFakeClient(client)) return;
Joining[client] = false;
/* Don't need the disconnect - L4D2 already reports that.. Leaving this here for when Valve breaks yet another function.
CSkipNextClient(client);
CPrintToChatAll("%sPlayer: {green}%N{default} has disconnected from the server.", TAG_INFO, client);
*/
}
public JoinTeam(Handle:event, String:event_name[], bool:dontBroadcast)
{
new playerClient = GetClientOfUserId(GetEventInt(event, "userid"));
new clientTeam = GetEventInt(event, "team");
if (!playerClient) return;
if (IsFakeClient(playerClient)) return;
new Handle:pack;
if (Joining[playerClient]) // If the player has just changed teams recently..
{
KillTimer(JoiningTimer[playerClient]);
JoiningTimer[playerClient] = CreateDataTimer(1.0, AnnounceJoining, pack);
WritePackCell(pack, playerClient);
WritePackCell(pack, clientTeam);
}
else // This is the first team join the player has done..
{
Joining[playerClient] = true;
JoiningTimer[playerClient] = CreateDataTimer(1.0, AnnounceJoining, pack);
WritePackCell(pack, playerClient);
WritePackCell(pack, clientTeam);
}
}
I also added this:
PHP Code:
#include <colors>
new bool:Joining[MAXPLAYERS+1]; // No need to spam join specator, join team when someone connects..
new Handle:JoiningTimer[MAXPLAYERS+1]; // Used to disable joining specator team when someone connects.
#define TAG_INFO "{lightgreen}[Join]{default} "
public Action:AnnounceJoining(Handle:timer, Handle:pack)
{
ResetPack(pack);
new playerClient = ReadPackCell(pack);
new clientTeam = ReadPackCell(pack);
if (!Joining[playerClient]) return;
Joining[playerClient] = false;
CSkipNextClient(playerClient); // No need to tell this person they are joining a team.. they already know.
switch (clientTeam)
{
case TEAM_SPECTATORS:
{
CPrintToChatAll("%sPlayer: {green}%N{default} has joined the Spectators.", TAG_INFO, playerClient);
}
case TEAM_SURVIVORS:
{
CPrintToChatAll("%sPlayer: {green}%N{default} has joined the Survivors.", TAG_INFO, playerClient);
}
case TEAM_INFECTED:
{
Joining[playerClient] = false;
CPrintToChatAll("%sPlayer: {green}%N{default} has joined the Infected.", TAG_INFO, playerClient);
}
}
}
It uses Colors.inc.. if you dont want to use that, replace the CPrintToChat's with PrintToChat's and remove the CSkipNextClient's. Also change the {lightgreen}, etcs to \x03's or just remove them if you dont want any color.
Anyway, it will wait 1 second after someone changes teams to report it. If they change again during that time, the first report wont show up. Cuts down on the connecting spam quite a bit (~33%). You also dont see your own messages (the CSkipNextClient lines), you already know when you change teams.
the error messages kiwi is getting, i believe results in the lack of this line:
Code:
if (!playerClient) return;