SA-MP Forums Archive
SetObjectMaterialText lags like hell in a timer. - 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: SetObjectMaterialText lags like hell in a timer. (/showthread.php?tid=549660)



SetObjectMaterialText lags like hell in a timer. [RESOLVED] - Aerotactics - 08.12.2014

What I want: a display of player names using SetObjectMaterialText and some objects.

The issue: SetObjectMaterialText lags the whole server each time it's called in this timer, making the objects being changed flash textures and the server pause:

RESOLVED! See comments.

pawn Код:
public BoardsUpdate()
{
    new Status[16];
    if(GameJoin == true)
    {
        Status = "Joinable";
    }
    else
    {
        Status = "Not Joinable";
    }
    SetObjectMaterialText(board1[2],"Status:",0,OBJECT_MATERIAL_SIZE_256x128,"Arial Black",36,0,0xFF000000,0x00000000);
    SetObjectMaterialText(board1[3],Status,0,OBJECT_MATERIAL_SIZE_256x128,"Arial Black",36,0,0xFF000000,0x00000000);
    switch(BoardSet)
    {
        case 0:
        {
            SetObjectMaterialText(board1[0],"Players",0,OBJECT_MATERIAL_SIZE_256x128,"Arial Black",36,0,0xFF000000,0x00000000);
            SetObjectMaterialText(board1[1],"Connected",0,OBJECT_MATERIAL_SIZE_256x128,"Arial Black",36,0,0xFF000000,0x00000000);

            for(new i=0; i<MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    SetObjectMaterialText(board[i],GetName(i),0,OBJECT_MATERIAL_SIZE_256x128,"Arial",24,1,0xFF000000,0x00000000);
                }
                else
                {
                    SetObjectMaterialText(board[i],"===",0,OBJECT_MATERIAL_SIZE_256x128,"Arial",24,1,0xFF000000,0x00000000);
                }
            }
        }
        case 1:
        {
            SetObjectMaterialText(board1[0],"Players",0,OBJECT_MATERIAL_SIZE_256x128,"Arial Black",36,0,0xFF000000,0x00000000);
            SetObjectMaterialText(board1[1],"In-Game",0,OBJECT_MATERIAL_SIZE_256x128,"Arial Black",36,0,0xFF000000,0x00000000);

            for(new i=0; i<MAX_PLAYERS; i++)
            {
                if(PlayerIsInLobby[i] == false)
                {
                    new Float:health, color;
                    GetPlayerHealth(i, health);
                    if(100 >= health >= 75) color = 0xFF00AA00;
                    if(74 >= health >= 50) color = 0xFFAAAA00;
                    if(49 >= health >= 25) color = 0xFFFF9900;
                    if(24 >= health >= 1) color = 0xFFAA0000;
                    if(health == 0) color = 0xFFAAAAAA;
                    SetObjectMaterialText(board[i],GetName(i),0,OBJECT_MATERIAL_SIZE_256x128,"Arial",24,1,color,0x00000000);
                }
                else
                {
                    SetObjectMaterialText(board[i],"===",0,OBJECT_MATERIAL_SIZE_256x128,"Arial",24,1,0xFF000000,0x00000000);
                }
            }
        }
    }
    return 1;
}



Re: SetObjectMaterialText lags like hell in a timer. - semara123 - 08.12.2014

are you set that code for all player that join to your server


Re: SetObjectMaterialText lags like hell in a timer. - Aerotactics - 08.12.2014

Quote:
Originally Posted by semara123
Посмотреть сообщение
are you set that code for all player that join to your server
Nope, it's a global timer. (SetTimer)


Re: SetObjectMaterialText lags like hell in a timer. - semara123 - 08.12.2014

so why u using this script ?? imean for what u use

cause that script makes the server lag (fps lag)


Re: SetObjectMaterialText lags like hell in a timer. - Aerotactics - 08.12.2014

Quote:
Originally Posted by semara123
Посмотреть сообщение
so why u using this script ?? imean for what u use

cause that script makes the server lag (fps lag)
I've worked around the lag by creating variables to only change the texture if it needs to update.