View Single Post
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 12-14-2008 , 21:49   Re: [L4D] Force mapchanger
Reply With Quote #7

I'll show you why I linked you to optimizations page.
Code:
public Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(GetConVarInt(Allowed))
    {
        decl String:currentMap[64];
        GetCurrentMap(currentMap, 64); //Why get map name everytime a roundend is called? Simply get once on mapstart and your done.

        if (StrEqual(currentMap, "l4d_vs_farm05_cornfield") == true || StrEqual(currentMap, "l4d_vs_hospital05_rooftop") == true)
        {
            RoundEndCounter += 1;

            if (RoundEndCounter == 4 && StrEqual(currentMap, "l4d_vs_farm05_cornfield") == true) //Didn't we already check if we were on this map?
            {
                for (new player=1; player<=GetMaxClients(); player++) //Here you'll be using GetMaxClients() for each loop we do. If server has 16 slots GetMaxClients() will be called 16 times without a need.
                {
                    if (IsClientInGame(player) && IsFakeClient(player))
                    {
                        ServerCommand("kick %s", player); //We got a command for this: KickClient
                    }
                }

                ServerCommand("changelevel %s", "l4d_vs_hospital01_apartment"); //Why are you using %s if your setting it in core not by variable?
            }
            if (RoundEndCounter == 4 && StrEqual(currentMap, "l4d_vs_hospital05_rooftop") == true) //Again we already checked the map and if the code above matched this is a waste. Also 2nd time we check RoundEndCounter
            {
                for (new player=1; player<=GetMaxClients(); player++)
                {
                    if (IsClientInGame(player) && IsFakeClient(player))
                    {
                        ServerCommand("kick %s", player);
                    }
                }

                ServerCommand("changelevel %s", "l4d_vs_farm01_hilltop");
            }
        }
    }
}
About a realtime game we have to make it as smother as possible. The cpu your wasting could be used to make server run smother. Also if every plugin we make we waste cpu if we stick them in a server we have lag. The lag is not necessary because of 1 single plugin not optimized.

Also I answered the thread you sent.
Sammy-ROCK! is offline