Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help - HUD element Crash Server (((
#1
Sad 
it works but after 5 - 10 minutes an error Confused

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;
        }

    }
}
[Image: 77c85afda648.gif]
Reply

#2
Moved )))))))))
Reply

#3
On your server in the addon/logs directory will be a console.log file, if any errors are reported from a code level they will exist in there.

If you can find those it will help to debug the plugin.
I now host all my MW3 projects on my private GIT repo
Reply

#4
(01-20-2013, 01:57)SgtLegend Wrote: On your server in the addon/logs directory will be a console.log file, if any errors are reported from a code level they will exist in there.

If you can find those it will help to debug the plugin.

Code:
[03:22:39] System.Collections.Generic.KeyNotFoundException:     .

    System.ThrowHelper.ThrowKeyNotFoundException()

    System.Collections.Generic.Dictionary`2.get_Item(TKey key)

    info.Class1.OnAddonFrame()

    Addon.PluginCode.TriggerAddonFrame()
[Image: 77c85afda648.gif]
Reply

#5
It should stop working after map change as you delete the HUDs but never recreate them
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] Windows 8.1 Fix for MW3 Server Addon master131 16 18,164 09-29-2014, 23:08
Last Post: SuperNovaAO
Brick [Release] MW3 Server Administration Addon iRoNinja 5 9,002 11-10-2013, 15:46
Last Post: Casper
Exclamation Help cmdlist, dvarlist server crash Nerus 17 11,901 11-09-2013, 23:54
Last Post: Nerus
  Our Level Fastfile is Different from the Server. CheeseToast 6 11,312 11-03-2013, 17:52
Last Post: CheeseToast
  Dedicated Server External (public) IP Nerus 3 5,895 11-02-2013, 14:16
Last Post: Casper
  MW3 Server Version superg1973 7 12,729 10-28-2013, 01:15
Last Post: kotyra972
  Help how to turn off map in dedicated server pero123 8 7,119 10-15-2013, 19:00
Last Post: Nekochan
  Issue with server addon and NAT dimitrifrom31 3 5,074 10-08-2013, 18:11
Last Post: iRoNinja
  GETTING SERVER ONLINE raym 6 5,701 09-28-2013, 22:42
Last Post: Nekochan
  advanced Server Config Poorya56 9 7,008 09-11-2013, 03:45
Last Post: trasto

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.