SA-MP Forums Archive
OnPlayerUpdate 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)
+--- Thread: OnPlayerUpdate Lag (/showthread.php?tid=483025)



Removed - maxy153 - 23.12.2013

__________________________


Re: OnPlayerUpdate Lag - Lynn - 23.12.2013

Don't run it on OnPlayerUpdate.
Loop it through a timer.
OnPlayerUpdate updates so quickly that if you have a decent playerbase it'll cause sufficient lag throughout the server.


Re: OnPlayerUpdate Lag - maxy153 - 23.12.2013

__________________________


Re: OnPlayerUpdate Lag - AndreT - 23.12.2013

OnPlayerUpdate, in terms of modern hardware, isn't something that's TOO frequent, I suppose (a lot of operations go a lot deeper into the timing). But what the source of problems in this code is that in way too often cases you update the textdraw string. It does not show visually to the player since it is a textdraw, but if you would have it as a client message, you would see the hell it causes in your chatbox.

There is a wide range of stuff you should not do so frequently and when communicating with the player through an API of some kind, it is good to remember that you should interact with it as little as possible.

I'm not sure about the speed of the natives causing any trouble here, but the actual formatting and the internal commands that these natives issue. So only update when necessary, and don't do it so often!

// EDIT:
wrong with the loop is that you don't have a playerid to operate on. For this, you must loop through all players.
pawn Код:
for(int playerid = 0; playerid != MAX_PLAYERS; playerid++)
{
    if(GetPlayerWantedLevel(playerid) > 0)
    {
        // code
    }
}
(Note that I don't run an IsPlayerConnected check because I can be sure that GetPlayerWantedLevel returns 0 for disconnected players)


Re: OnPlayerUpdate Lag - maxy153 - 23.12.2013

__________________________


Re: OnPlayerUpdate Lag - HavingGood - 23.12.2013

Код:
new updatetimer[MAX_PLAYERS];


OnGameModeInit:
----
updatetimer[playerid] = SetTimerEx("update", 1000, true, "d", playerid);
----


forward update(playerid);
public update(playerid)
{
	for(int playerid = 0; playerid != MAX_PLAYERS; playerid++)
	{
	    if(GetPlayerWantedLevel(playerid) >= 1)
		{
		new string[124];
		format(string, sizeof(string), "~b~~h~Tickets~h~(%d/10): ~g~~h~$%d000~n~~r~/ticket to pay", GetPlayerWantedLevel(playerid), GetPlayerWantedLevel(playerid));
		TextDrawSetString(Ticket, string);
		Ticket = TextDrawCreate(497.000000, 129.000000, " ");
		return 1;
		}
	}
	return 1;
}



Re: OnPlayerUpdate Lag - maxy153 - 23.12.2013

__________________________


Re: OnPlayerUpdate Lag - HavingGood - 23.12.2013

Код:
new updatetimer[MAX_PLAYERS];


OnGameModeInit:
----
updatetimer[playerid] = SetTimerEx("update", 1000, true, "d", playerid);
----


forward update(playerid);
public update(playerid)
{
	for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
	{
	    if(GetPlayerWantedLevel(playerid) >= 1)
		{
		new string[124];
		format(string, sizeof(string), "~b~~h~Tickets~h~(%d/10): ~g~~h~$%d000~n~~r~/ticket to pay", GetPlayerWantedLevel(playerid), GetPlayerWantedLevel(playerid));
		TextDrawSetString(Ticket, string);
		Ticket = TextDrawCreate(497.000000, 129.000000, " ");
		return 1;
		}
	}
	return 1;
}



Re: OnPlayerUpdate Lag - maxy153 - 23.12.2013

__________________________


Re: OnPlayerUpdate Lag - erminpr0 - 23.12.2013

Quote:
Originally Posted by HavingGood
Посмотреть сообщение
Код:
new updatetimer[MAX_PLAYERS];


OnGameModeInit:
----
updatetimer[playerid] = SetTimerEx("update", 1000, true, "d", playerid);
----


forward update(playerid);
public update(playerid)
{
	for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
	{
	    if(GetPlayerWantedLevel(playerid) >= 1)
		{
		new string[124];
		format(string, sizeof(string), "~b~~h~Tickets~h~(%d/10): ~g~~h~$%d000~n~~r~/ticket to pay", GetPlayerWantedLevel(playerid), GetPlayerWantedLevel(playerid));
		TextDrawSetString(Ticket, string);
		Ticket = TextDrawCreate(497.000000, 129.000000, " ");
		return 1;
		}
	}
	return 1;
}
Thats bad, you have already defined 'playerid' as parameter, should use it in a loop again.

Fix:

pawn Код:
forward UpdateWanted();
public UpdateWanted()
{
    for(new i, z = GetMaxPlayers(); i < z; i++)
    {
        if(!IsPlayerConnected(i) || GetPlayerWantedLevel(playerid) == 0)
            continue;
        new string[128];
        format(string, sizeof string, "~b~~h~Tickets~h~(%d/10): ~g~~h~$%d000~n~~r~/ticket to pay", GetPlayerWantedLevel(playerid), GetPlayerWantedLevel(playerid));
        return TextDrawSetString(Ticket, string);
    }
}