SA-MP Forums Archive
Server lag...? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Server lag...? (/showthread.php?tid=201909)



Server lag...? - Face9000 - 22.12.2010

Hi all,im coding a new tdm gm,i tried on serverffs and some players except major lag.

What can increase lag in the server?


Re: Server lag...? - Sinner - 22.12.2010

Timers, large functions under OnPlayerUpdate, infinite loops, inefficient coding, etc...


Re: Server lag...? - Hal - 22.12.2010

If only some players lag, they could all have terrible internet connections, or be really far from the host while others can be closer


Re: Server lag...? - Face9000 - 22.12.2010

Quote:
Originally Posted by Sinner
Посмотреть сообщение
Timers, large functions under OnPlayerUpdate, infinite loops, inefficient coding, etc...
I dont use OnPlayerUpdate,i use only this timers OnGameModeInit:

pawn Код:
zonetimer = SetTimer("ZoneUpdate", 10000, true);
    timer1 = SetTimer("AntiCheat",5000,true);
Quote:
Originally Posted by Hal
Посмотреть сообщение
If only some players lag, they could all have terrible internet connections, or be really far from the host while others can be closer
My server has location in France.This can affect?


Re: Server lag...? - Mauzen - 22.12.2010

Does this affect all players at a time or only single ones?
If it only lags for some players, it cant be something with the script, as scripting problems would lag the whole server -> all players at once


Re: Server lag...? - Face9000 - 22.12.2010

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Does this affect all players at a time or only single ones?
If it only lags for some players, it cant be something with the script, as scripting problems would lag the whole server -> all players at once
Yes,sometimes happen to ALL players.I know cuz i lag too and in chat all saying "lag lag" bla bla.


Re: Server lag...? - Mauzen - 22.12.2010

Hm, then it is most probably the script. It could also be the hoster, but I dont think serverffs lags that much.

There are a lots of parts that could cause the lag, hard to tell exactly where you have to look for.
At first you should check your for(...)-loops (or while(...)-loops) that loop thorugh all players, all vehicles, zones, or in general a large number. They can make the server lag, if there is a lot of code, or complex functions in them.


Re: Server lag...? - Face9000 - 22.12.2010

The script is 2995 Lines (Not much i know,i started working on 12/12...)

This is a small part of the ZoneUpdate (The function to take over turfs).

pawn Код:
public ZoneUpdate()
{
    for(new z=0; z < MAX_ZONES; z++)
    {
        if(ZoneTakeOverTeam[z] == -1)
        {
            for(new t=0; t < MAX_TEAMS; t++)
            {
                if(t == ZoneInfo[z][z_team]) continue;
                if(GetMembersInZone(z, t) >= 4)
                {
                    ZoneTakeOverTeam[z] = t;
                    GangZoneFlashForAll(ZoneInfo[z][z_id], GetTeamColor(t));
                    ZoneTakeOverTime[z] = 0;
                }
            }
        }
        else
        {
            if(GetMembersInZone(z, ZoneTakeOverTeam[z]) > 0)
            {
                ZoneTakeOverTime[z]++;
                if(ZoneTakeOverTime[z] >= 120)
                {
                    GangZoneStopFlashForAll(ZoneInfo[z][z_id]);
                    GangZoneShowForAll(ZoneInfo[z][z_id], GetTeamColor(ZoneTakeOverTeam[z]));
                    ZoneInfo[z][z_team] = ZoneTakeOverTeam[z];
                    for(new i=0; i<MAX_PLAYERS; i++)
                    {
                        if(IsPlayerConnected(i))
                        {
                            if(GetPlayerZone(i) == z && gTeam[i] == ZoneTakeOverTeam[z])
                            {
                                SetPlayerScore(i, GetPlayerScore(i) + 2);
                                GameTextForPlayer(i, "~g~Turf ~r~taken over~n~~b~~h~", 6000, 3);
                            }
                        }
                    }
                    ZoneTakeOverTeam[z] = -1;
                    ZoneTakeOverTime[z] = 0;
                }
            }
            else
            {
                ZoneTakeOverTeam[z] = -1;
                GangZoneStopFlashForAll(ZoneInfo[z][z_id]);
                ZoneTakeOverTime[z] = 0;
            }
        }
    }
}
This are the timers for the IRC ECHO BOTS:

pawn Код:
SetTimerEx("IRC_ConnectDelay", 20000, 0, "d", 1);
SetTimerEx("IRC_ConnectDelay", 25000, 0, "d", 2);
This is the loop for AntiCheat:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {



Re: Server lag...? - Mauzen - 23.12.2010

The zone function doesnt look bad, it could only lag, if you have a really big amout of zones (200+)

EDIT: Ah ok, nice to hear you could fix it.


Re: Server lag...? - Face9000 - 23.12.2010

I've resolved the lag issue,it was a shitty hided high ping timer that cause bad lag + some bot textdraw.

P:S Mauzen the zones are 72.