Will it makes a Lag ?
#1

This is my code for a cnr server...

Will this makes any lag cuz my server's players are gettting timeout very fast and sometimes lagging also

PHP код:
public OnPlayerUpdate(playerid)
{
    if(!
Player[playerid][onDuty])
        
updateWanted(playerid);
    
//-------- Sweeper Job ---------------------------------------------------//
    
if(SweeperJob[playerid] && GetVehicleModel(GetPlayerVehicleID(playerid)) == 574 && SweeperUpdate[playerid] < tickcount())
    {
        
SweeperUpdate[playerid] = tickcount()+UPDATE_TIME;
        
SweeperDistance[playerid] += floatround(GetPlayerDistanceFromPoint(playeridSweeperLastPos[playerid][0], SweeperLastPos[playerid][1], SweeperLastPos[playerid][2]));
        
GetPlayerPos(playeridSweeperLastPos[playerid][0], SweeperLastPos[playerid][1], SweeperLastPos[playerid][2]);
        new 
string[64];
        
format(stringsizeof(string), "~b~~h~Sweeper Job~n~~n~~w~Cleaned: ~y~%d Meters"SweeperDistance[playerid]);
        
PlayerTextDrawSetString(playeridSweeperText[playerid], string);
    }
    
//-------------------------------------------------------------------------------//
    
if(Player[playerid][onDerby])
    {
        new 
Float:xFloat:yFloat:zmsg[256];
        
format(msgsizeof(msg), "[Derby]: %s has fallen from the map."GetName(playerid));
        
GetPlayerPos(playeridxyz);
        if(
< -1.00)
        {
            foreach(new 
Player)
            {
                if(
Player[i][onDerby])
                    
//Info(i, msg);
                    
SendClientMessage(i,COLOR_ORANGE,msg);
            }
            
loadData(playerid);
            
Player[playerid][onDerby] = false;
        }
    }
    
    if(
Player[playerid][onFallout])
    {
        new 
Float:xFloat:yFloat:zmsg[512];
        
format(msgsizeof(msg), "[Fallout]: %s has dropped out of Fallout event."GetName(playerid));
        
GetPlayerPos(playeridxyz);
        if(
2.00)
        {
            foreach(new 
Player)
            {
                if(
Player[i][onFallout])
                    
//Info(i, msg);
                    
SendClientMessage(i,COLOR_ORANGE,msg);
            }
            
loadData(playerid);
            
SetCameraBehindPlayer(playerid);
            
Player[playerid][onFallout] = false;
        }
    }
    if(
GetPVarInt(playerid,"YEAH") == 1)
    {
        new
            
Float:VPos[3],
            
Float:Rotation
        
;
         
GetVehiclePos(GetPlayerVehicleID(playerid), VPos[0], VPos[1], VPos[2]);
         
Rotation PointAngle(playeridVPos[0], VPos[1], GetPVarFloat(playerid"Spongebob"), GetPVarFloat(playerid"Mario"));
        if(!
Player[playerid][truckingMission])
            
AttachObjectToVehicle(GPSObject[playerid], GetPlayerVehicleID(playerid), 0.00.01.50.090.0Rotation);
        else
            
AttachObjectToVehicle(GPSObject[playerid], GetPlayerVehicleID(playerid), 0.00.03.50.090.0Rotation);
    }
    return 
1;

Reply
#2

Absolutely.

MAX_PLAYERS*(30)*(objects 2)*MAX_VEHICLES

About.. 6.000.000 new objects are being created in a single second if they have got the var "YEAH"

Leeeeeegit
Reply
#3

Yeah, "Absolutely" as Meller said, As you are checking for the player much times to see if any of these things happening, Which will cause lag for sure.
Reply
#4

how can i fix it and do u know any optimisation method ?

and i had saw in some post that this code:
PHP код:
foreach(new Player
            { 
                if(
Player[i][onFallout]) 
                    
//Info(i, msg); 
                    
SendClientMessage(i,COLOR_ORANGE,msg); 
            } 
will cause players to timeout or lag ?
if yes ,
is there any other same function to fix this problem ?
Reply
#5

Yes also this may cause much problems, I believe that you need to get away of these functions by using the system you want all in one place, I mean under the command /sweep (for example) try making everything related to it, either by creating other functions and putting it under it or with any other method, or just reduce the usage of them somehow, As you are making much lines in one place which checks much, And checks every single player (OnPlayerUpdate) which will make much lag/crash/timeout/Server is down
Reply
#6

Only use OnPlayerUpdate if it's the only thing you can use (e.g. detecting pause).
Reply
#7

Quote:
Originally Posted by Paulice
Посмотреть сообщение
Only use OnPlayerUpdate if it's the only thing you can use (e.g. detecting pause).
Quite incorrect...


All you have to do is use it efficiently, and have proper checks, and it won't give issue.

This is the same with OnPlayerKeyStateChange, and the rest of them.

_ANY_ callback can effectively be misused to an extent that the server will be lagged out by it, it all depends on what you are using it for.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)