Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help I add flags but geting error
#1
Rainbow 
hello everyone i add flags all work good but when i start server join game after 2 min geting error g_spawn no free entities plis help me
Code:
using System;
using System.Collections.Generic;
using Addon;
using System.IO;
using System.Collections;
namespace zflags
{
    public class flags : CPlugin
    {
        Dictionary<int, int> Client_HudElem_Flag = new Dictionary<int, int>();

        public override void OnMapChange()
        {
            string map = GetDvar("mapname");
            if (map == "mp_bravo")
            {

                Entity w = SpawnModel("script_model", "prop_flag_neutral", new Vector(1938.302f, -349.1249f, 1200.525f));
                Entity w1 = SpawnModel("script_model", "prop_flag_neutral", new Vector(-984.309f, 331.6788f, 1057.125f));
                Entity w2 = SpawnModel("script_model", "prop_flag_neutral", new Vector(1817.183f, -792.3326f, 1169.125f));
                Entity w3 = SpawnModel("script_model", "prop_flag_neutral", new Vector(-1970.91f, -268.9228f, 937.125f));

            }

        }


        public override void OnAddonFrame()
        {
            List<ServerClient> clients;
            try
            {
                clients = GetClients();
                if (clients != null && clients.Count > 0)
                {
                    foreach (ServerClient c in GetClients())
                    {
                        if (c.Other.isAlive == true)
                        {
                            HudElem hl = GetHudElement(Client_HudElem_Flag[c.ClientNum]);
                            string map = GetDvar("mapname");


                            /////////
                            if (map == "mp_bravo")
                            {
                                Entity w = SpawnModel("script_model", "prop_flag_neutral", new Vector(1938.302f, -349.1249f, 1200.525f));
                                Entity w1 = SpawnModel("script_model", "prop_flag_neutral", new Vector(-984.309f, 331.6788f, 1057.125f));
                                Entity w2 = SpawnModel("script_model", "prop_flag_neutral", new Vector(1817.183f, -792.3326f, 1169.125f));
                                Entity w3 = SpawnModel("script_model", "prop_flag_neutral", new Vector(-1970.91f, -268.9228f, 937.125f));
                                if ((Difference(c.OriginX, 1938.302f) <= 100) && (Difference(c.OriginY, -349.1249f) <= 100) && (Difference(c.OriginZ, 1200.525f) <= 100))
                                {
                                    hl.SetString("Press ^3F^7 to ^1Teleport!");

                                    if (c.Other.ButtonPressed(Buttons.Activate))
                                    {
                                        iPrintLnBold("^2After ^1Moab ^2Chang Spot!", c);

                                        c.OriginX = -984.309f;
                                        c.OriginY = 331.6788f;
                                        c.OriginZ = 1057.125f;
                                    }
                                }

                                else if ((Difference(c.OriginX, -984.309f) <= 100) && (Difference(c.OriginY, 331.6788f) <= 100) && (Difference(c.OriginZ, 1057.125f) <= 100))
                                {
                                    hl.SetString("Press ^3F^7 to ^1Teleport! ");
                                    if (c.Other.ButtonPressed(Buttons.Activate))
                                    {
                                        iPrintLnBold("^2In Map!", c);
                                        c.OriginX = 1937.302f;
                                        c.OriginY = -349.1249f;
                                        c.OriginZ = 1200.525f;
                                    }
                                }
                                else if ((Difference(c.OriginX, 1817.183f) <= 100) && (Difference(c.OriginY, -792.3326f) <= 100) && (Difference(c.OriginZ, 1169.125f) <= 100))
                                {
                                    hl.SetString("Press ^3F^7 to ^1Teleport ^7 to the ^4Out Side!");

                                    if (c.Other.ButtonPressed(Buttons.Activate))
                                    {
                                        iPrintLnBold("^2After ^1Moab ^2Chang Spot!", c);

                                        c.OriginX = -1970.91f;
                                        c.OriginY = -268.9228f;
                                        c.OriginZ = 937.125f;
                                    }
                                }

                                else if ((Difference(c.OriginX, -1970.91f) <= 100) && (Difference(c.OriginY, -268.9228f) <= 100) && (Difference(c.OriginZ, 937.125f) <= 100))
                                {
                                    hl.SetString("Press ^3F^7 to ^1Teleport ^7Back in the ^4MAP!");

                                    if (c.Other.ButtonPressed(Buttons.Activate))
                                    {
                                        iPrintLnBold("^2Back!", c);
                                        c.OriginX = 1817.173f;
                                        c.OriginY = -792.3326f;
                                        c.OriginZ = 1169.125f;
                                    }
                                }


                                else
                                {
                                    hl.SetString("");
                                }
                            }
                            ///////////////////////////////////////////////////////////////////////////
                            //////////////////  DONT CHANGE ANYTHING BELOW THIS!  /////////////////////
                            ///////////////////////////////////////////////////////////////////////////
                        }
                    }
                }
            }

            catch (Exception z)
            {
                ServerPrint("Error flag: " + z.Message);
            }

        }

        public static float Difference(float loc, float loc2)
        {
            return Math.Abs(loc - loc2);
        }

        public override void OnPlayerDisconnect(ServerClient client)
        {
            if (Client_HudElem_Flag.ContainsKey(client.ClientNum))
            {
                HudElem info2 = GetHudElement(Client_HudElem_Flag[client.ClientNum]);
                info2.Type = HudElementTypes.None;
                Client_HudElem_Flag.Remove(client.ClientNum);
            }
        }

        public override void OnPlayerConnect(ServerClient client)
        {
            int HudElemNum1 = CreateHud_Flag(client.ClientNum);
            if (Client_HudElem_Flag.ContainsKey(client.ClientNum))
                Client_HudElem_Flag[client.ClientNum] = HudElemNum1;
            else
                Client_HudElem_Flag.Add(client.ClientNum, HudElemNum1);
        }

        private int CreateHud_Flag(int ClientNum)
        {
            HudElem hud = CreateNewHudElem();
            hud.Type = HudElementTypes.Text;
            hud.ShowToEnt = ClientNum;
            hud.HideInMenu = true;
            //THIS SETS THE FONT OF YOUR TEXT
            hud.Font = HudElementFonts.Default;
            //THIS SETS HOW BIG YOU WANT THE TEXT
            hud.FontScale = 1.5f;
            hud.PointType = 120;
            //THIS SETS WHERE YOU WANT THE TEXT TO APPEAR
            //THE Y IS HORIZANTAL ON HUD
            hud.OriginY = 180f;
            //X IS VERTICAL ON HUD
            hud.OriginX = -100f;
            hud.SetString("");
            return hud.HudElementNum;
        }

    }
}
Reply

#2
Too many models spawned. Probably you have another bunker plugins or whatever.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#3
Code:
Entity w = SpawnModel("script_model", "prop_flag_neutral", new Vector(1938.302f, -349.1249f, 1200.525f));
                                Entity w1 = SpawnModel("script_model", "prop_flag_neutral", new Vector(-984.309f, 331.6788f, 1057.125f));
                                Entity w2 = SpawnModel("script_model", "prop_flag_neutral", new Vector(1817.183f, -792.3326f, 1169.125f));
                                Entity w3 = SpawnModel("script_model", "prop_flag_neutral", new Vector(-1970.91f, -268.9228f, 937.125f));
You have that in a foreach loop in the OnAddonFrame().

So for each addon frame it generates [NumOfPlayers] * [NumOfFlags].

Make your Entity variables global and remove the the variable declarations (lines like shown above) from your foreach loop in your OnAddonFrame().
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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