01-19-2013, 21:03
it works but after 5 - 10 minutes an error
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Addon;
namespace info
{
public class Class1 : CPlugin
{
public Dictionary<int, int> Client_HudElem_Info = new Dictionary<int, int>();
public Dictionary<int, int> Client_HudElem_ServerName = new Dictionary<int, int>();
public Dictionary<int, int> Client_HudElem_Deaths = new Dictionary<int, int>();
public Dictionary<int, int> Client_HudElem_Kills = new Dictionary<int, int>();
public override void OnServerLoad()
{
ServerPrint("\n:::Info Plugin loaded v1.0:::\n:::Author: :D:::\n");
}
public void CreateHUD(ServerClient Client)
{
//Add client and it's hudelement to the list
int HudElemKills = CreateHud_Kills(Client.ClientNum);
if (Client_HudElem_Kills.ContainsKey(Client.ClientNum))
{
Client_HudElem_Kills[Client.ClientNum] = HudElemKills;
}
else
{
Client_HudElem_Kills.Add(Client.ClientNum, HudElemKills);
}
int HudElemDeaths = CreateHud_Deaths(Client.ClientNum);
if (Client_HudElem_Deaths.ContainsKey(Client.ClientNum))
{
Client_HudElem_Deaths[Client.ClientNum] = HudElemDeaths;
}
else
{
Client_HudElem_Deaths.Add(Client.ClientNum, HudElemDeaths);
}
int HudElemServerName = CreateHud_ServerName(Client.ClientNum);
if (Client_HudElem_ServerName.ContainsKey(Client.ClientNum))
{
Client_HudElem_ServerName[Client.ClientNum] = HudElemServerName;
}
else
{
Client_HudElem_ServerName.Add(Client.ClientNum, HudElemServerName);
}
int HudElemInfo = CreateHud_Info(Client.ClientNum);
if (Client_HudElem_Info.ContainsKey(Client.ClientNum))
{
Client_HudElem_Info[Client.ClientNum] = HudElemInfo;
}
else
{
Client_HudElem_Info.Add(Client.ClientNum, HudElemInfo);
}
}
public void DeleteHUD(ServerClient Client)
{
if (Client_HudElem_Kills.ContainsKey(Client.ClientNum))
{
HudElem kl = GetHudElement(Client_HudElem_Kills[Client.ClientNum]);
kl.Type = HudElementTypes.None;
Client_HudElem_Kills.Remove(Client.ClientNum);
}
if (Client_HudElem_Deaths.ContainsKey(Client.ClientNum))
{
HudElem dt = GetHudElement(Client_HudElem_Deaths[Client.ClientNum]);
dt.Type = HudElementTypes.None;
Client_HudElem_Deaths.Remove(Client.ClientNum);
}
if (Client_HudElem_ServerName.ContainsKey(Client.ClientNum))
{
HudElem sn = GetHudElement(Client_HudElem_ServerName[Client.ClientNum]);
sn.Type = HudElementTypes.None;
Client_HudElem_ServerName.Remove(Client.ClientNum);
}
if (Client_HudElem_Info.ContainsKey(Client.ClientNum))
{
HudElem info = GetHudElement(Client_HudElem_Info[Client.ClientNum]);
info.Type = HudElementTypes.None;
Client_HudElem_Info.Remove(Client.ClientNum);
}
}
public void DeleteAllHUD()
{
foreach (KeyValuePair<int, int> it in Client_HudElem_Kills)
{
HudElem elem = GetHudElement(it.Value);
elem.Type = HudElementTypes.None;
}
Client_HudElem_Kills.Clear();
foreach (KeyValuePair<int, int> it in Client_HudElem_Deaths)
{
HudElem elem = GetHudElement(it.Value);
elem.Type = HudElementTypes.None;
}
Client_HudElem_Deaths.Clear();
foreach (KeyValuePair<int, int> it in Client_HudElem_ServerName)
{
HudElem elem = GetHudElement(it.Value);
elem.Type = HudElementTypes.None;
}
Client_HudElem_ServerName.Clear();
foreach (KeyValuePair<int, int> it in Client_HudElem_Info)
{
HudElem elem = GetHudElement(it.Value);
elem.Type = HudElementTypes.None;
}
Client_HudElem_Info.Clear();
}
public override void OnPlayerConnect(ServerClient Client)
{
CreateHUD(Client);
}
public override void OnPlayerDisconnect(ServerClient Client)
{
DeleteHUD(Client);
}
public override void OnMapChange()
{
DeleteAllHUD();
}
public override void OnAddonFrame()
{
List<ServerClient> clients;
clients = GetClients();
foreach (ServerClient c in clients)
{
HudElem Kills = GetHudElement(Client_HudElem_Kills[c.ClientNum]);
HudElem Deaths = GetHudElement(Client_HudElem_Deaths[c.ClientNum]);
HudElem Info = GetHudElement(Client_HudElem_Info[c.ClientNum]);
HudElem ServerName = GetHudElement(Client_HudElem_ServerName[c.ClientNum]);
Kills.SetString("Kills: ^2" + c.Stats.Kills);
Deaths.SetString("Deaths: ^1" + c.Stats.Deaths);
ServerName.SetString("^1Server Name");
if (c.Team == Teams.Axis)
{
Info.SetString("^2Text!\n" +
"^7Text!\n" +
"^3Text!\n");
}
if (c.Team == Teams.Allies)
{
Info.SetString("^2Text!\n" +
"^7Text!\n" +
"^3Text!\n");
}
}
}
private int CreateHud_Kills(int ClientNum)
{
HudElem hud = CreateNewHudElem();
hud.Type = HudElementTypes.Text;
hud.ShowToEnt = ClientNum;
hud.HideInMenu = true;
hud.Font = HudElementFonts.Default;
hud.FontScale = 1.3f;
hud.PointType = 81;
hud.OriginY = 200f;
hud.OriginX = 10f;
hud.SetString("");
return hud.HudElementNum;
}
private int CreateHud_Deaths(int ClientNum)
{
HudElem hud = CreateNewHudElem();
hud.Type = HudElementTypes.Text;
hud.ShowToEnt = ClientNum;
hud.HideInMenu = true;
hud.Font = HudElementFonts.Default;
hud.FontScale = 1.3f;
hud.PointType = 81;
hud.OriginY = 212f;
hud.OriginX = 10f;
hud.SetString("");
return hud.HudElementNum;
}
private int CreateHud_Info(int ClientNum)
{
HudElem hud = CreateNewHudElem();
hud.Type = HudElementTypes.Text;
hud.ShowToEnt = ClientNum;
hud.HideInMenu = true;
hud.Font = HudElementFonts.Default;
hud.FontScale = 1.3f;
hud.PointType = 81;
hud.OriginY = 235f;
hud.OriginX = 10f;
hud.SetString("");
return hud.HudElementNum;
}
private int CreateHud_ServerName(int ClientNum)
{
HudElem hud = CreateNewHudElem();
hud.Type = HudElementTypes.Text;
hud.ShowToEnt = ClientNum;
hud.HideInMenu = true;
hud.Font = HudElementFonts.Default;
hud.FontScale = 1.3f;
hud.PointType = 82;
hud.OriginY = 160f;
hud.OriginX = 5f;
hud.SetString("");
return hud.HudElementNum;
}
}
}