OnPlayerUpdate lag my server?
#1

Well i came to point of hearing every people saying that's OnPlayerUpdate lags my server. Some people say to not use it. Well i probably don't know what to do. Ofc my server lags like hell but i didn't even thought that this code may lag it. So i decided to show my OnPlayerUpdate callback. This really lags? Or it's everything good?

To not being pointless i'll say you whats on this callback. It's just simple scripts for anti team kill, anti money hack and anti airbreak. OFC i wont show all the scripts variables etc. So i need to remove it and my server won't lag again?


pawn Код:
public OnPlayerUpdate(playerid)
{
    SetPlayerTeam(playerid,gTeam[playerid]);
    AntiMoneyCheat(playerid);
    pupdates[playerid]++;
    if(pupdates[playerid] > UPDATE_COUNT && running == 1){
        pupdates[playerid]=0;
        new check;
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsVehicleValid(GetPlayerVehicleID(playerid))){
            new Float:vx,Float:vy,Float:vz;
            GetVehicleVelocity(GetPlayerVehicleID(playerid),vx,vy,vz);
            if(vx==0.0 && vy==0.0 && vz < -0.0032 && vz > -0.022){
                if(IsPlayerInWater(playerid)==0){
                check=1;
                }
                else
                {
                check=3;
                }
            }
        }
        else
        {
            if(GetPlayerState(playerid)==PLAYER_STATE_ONFOOT && GetPlayerSurfingVehicleID(playerid)==INVALID_VEHICLE_ID){
                new Float:vx,Float:vy,Float:vz,Float:px,Float:py,Float:pz;
                GetPlayerVelocity(playerid,vx,vy,vz);
                pupdates[playerid]=0;
                new keys,ud,lr;
                GetPlayerKeys(playerid,keys,ud,lr);
                if (keys & KEY_SPRINT)
                {
                    if(-0.022 < vz < -0.0040 && -0.235 < vx < 0.235 && -0.235 < vy < 0.235)
                    {
                        if(!IsPlayerInRangeOfPoint(playerid,2.0,GetPVarFloat(playerid,"oposx"),GetPVarFloat(playerid,"oposy"),GetPVarFloat(playerid,"oposz")) || -0.5>(GetPVarFloat(playerid,"oposz")-pz)>-0.1 || 0.075>(GetPVarFloat(playerid,"oposz")-pz)>-0.075)
                        {
                            if(IsPlayerInWater(playerid)==0)
                            {
                                check=2;
                                if(airbreakcount[playerid] > (POSSIBLE_AIRBREAK_COUNT_ONFOOT-2))
                                {
                                    SetPlayerVelocity(playerid,0.3,0.3,0.3);
                                }
                            }
                            else
                            {
                                check=3;
                            }
                        }
                        SetPVarFloat(playerid,"oposx",px);
                        SetPVarFloat(playerid,"oposy",py);
                        SetPVarFloat(playerid,"oposz",pz);
                    }
                }
                else
                {
                    if(-0.022 < vz < -0.0040 && -0.121 < vx < 0.121 && -0.121 < vy < 0.121)
                    {
                        if(!IsPlayerInRangeOfPoint(playerid,2.0,GetPVarFloat(playerid,"oposx"),GetPVarFloat(playerid,"oposy"),GetPVarFloat(playerid,"oposz")) || -0.5>(GetPVarFloat(playerid,"oposz")-pz)>-0.1 || 0.075>(GetPVarFloat(playerid,"oposz")-pz)>-0.075)
                        {
                            if(IsPlayerInWater(playerid)==0)
                            {
                                check=2;
                                if(airbreakcount[playerid] > (POSSIBLE_AIRBREAK_COUNT_ONFOOT-2))
                                {
                                    SetPlayerVelocity(playerid,0.3,0.3,0.3);
                                }
                            }
                            else
                            {
                                check=3;
                            }
                        }
                        SetPVarFloat(playerid,"oposx",px);
                        SetPVarFloat(playerid,"oposy",py);
                        SetPVarFloat(playerid,"oposz",pz);
                    }
                }
            }
        }
        if(check > 0)
        {
            if(check < 3)
            {
                new POSSIBLE_AIRBREAK_COUNT;
                switch(check)
                {
                    case 1: POSSIBLE_AIRBREAK_COUNT=POSSIBLE_AIRBREAK_COUNT_CAR;
                    case 2: POSSIBLE_AIRBREAK_COUNT=POSSIBLE_AIRBREAK_COUNT_ONFOOT;
                }
                airbreakcount[playerid]++;
                if(airbreakcount[playerid] > POSSIBLE_AIRBREAK_COUNT)
                {
                        airbreakcount[playerid]=0;
                        new string[60], name[24];
                        GetPlayerName(playerid,name,sizeof(name));
                        format(string,sizeof(string),"* %s was been banned (Reason:airbreak)",name);
                        SendClientMessageToAll(color,string);
                        SaveToFile("BanLog",string); Ban(playerid);
                }
            }
        }
        else
        {
            airbreakcount[playerid]=0;
        }
    }
    return 1;
}
Reply
#2

Maybe timer is too low ?
Reply
#3

Do you realize that all that piece of code gets executed about 32 times each second?
Reply
#4

Don't use PVars there. PVars should be used only when you need cross-script communication or dynamic memory allocation.


Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
Do you realize that all that piece of code gets executed about 32 times each second?
per player*
Reply
#5

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
Do you realize that all that piece of code gets executed about 32 times each second?
Well it's not my script. I even didn't looked on it. BTW it should be optimized?


So as i see this is not good script. Any other anti airbreak script here?
Reply
#6

Quote:
Originally Posted by ZamaXor
Посмотреть сообщение
Well it's not my script. I even didn't looked on it. BTW it should be optimized?


So as i see this is not good script. Any other anti airbreak script here?
Of course, put that on a timer of 1500 ms.
Reply
#7

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
per player*
Exactly : )) He should really expect Crash.

Quote:
Originally Posted by ZamaXor
Посмотреть сообщение
Well it's not my script. I even didn't looked on it. BTW it should be optimized?
Use timers instead.
Reply
#8

ZamaXor, run some tests with these macros in OnPlayerUpdate:
http://forum.sa-mp.com/showthread.ph...706#post877706
Reply
#9

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
ZamaXor, run some tests with these macros in OnPlayerUpdate:
http://forum.sa-mp.com/showthread.ph...706#post877706
Okay i putted this script and compiled. No errors warnings.
Reply
#10

Quote:
Originally Posted by ZamaXor
Посмотреть сообщение
Okay i putted this script and compiled. No errors warnings.
Just keep it running for quite some time, get a few players on.
After a few hours of activity, search for warnings in the server log.
Reply
#11

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
Just keep it running for quite some time, get a few players on.
After a few hours of activity, search for warnings in the server log.
Yep i have a warning.

Код:
OnPlayerUpdate was executed in 3 ms.
EDIT: I have this warning for 6 times.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)