Can this OnPlayerUpdate cause lag?
#1

Hey,I have been facing lag beginning of the day,can this cause lag?

Because I had modified my onplayerupdate a few days ago. Maybe there is a loop causing huge lag.
pawn Код:
public OnPlayerUpdate(playerid)
{
   new weapon=GetPlayerWeapon(playerid);
   new vehicleid;
   vehicleid = GetPlayerVehicleID(playerid);
   if(weapon==38||weapon==1||weapon==2||weapon==3||weapon==5||weapon==6||weapon==7||weapon==9||weapon==10||weapon==11||weapon==12||weapon==13||weapon==14||weapon==15||weapon==39)
   if(PlayerInfo[playerid][pAdmin] < 4 && HasMG[playerid] != 1)
   {
   new name[MAX_PLAYER_NAME], string[128];
   GetPlayerName(playerid, name, sizeof(name));
   format(string, sizeof(string), "[ANTI CHEAT]:%s is banned for weapon hacking!",name);
   SendClientMessageToAll(RED, string);
   PlayerInfo[playerid][pBan] = 1;
   BanEx(playerid,"Weapon Hack");
   }
   if(weapon == 35)
   {
      if(PlayerInfo[playerid][pAXP] < 350 && PlayerInfo[playerid][pCXP] < 250 && GetPlayerScore(playerid) < 1000)
      {
         new name[MAX_PLAYER_NAME], string[128];
         GetPlayerName(playerid, name, sizeof(name));
         format(string, sizeof(string), "[ANTI CHEAT]:%s is banned for weapon hacking!(RPG)",name);
         SendClientMessageToAll(RED, string);
         PlayerInfo[playerid][pBan] = 1;
         BanEx(playerid,"Weapon Hack (RPG)");
      }
   }
   if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USEJETPACK)
   if(PlayerInfo[playerid][pAdmin] < 4 && HasJP[playerid] != 1)
   {
   new name[MAX_PLAYER_NAME], string[128];
   GetPlayerName(playerid, name, sizeof(name));
   format(string, sizeof(string), "[ANTI CHEAT]:%s is banned for spawning JetPack!",name);
   SendClientMessageToAll(RED, string);
   PlayerInfo[playerid][pBan] = 1;
   BanEx(playerid,"JetPack Hack");
   }
   if(IsPlayerInVehicle(playerid,vehicleid)) // well yes,onplayerstatechange didn't work.
   {
         new seat;
         seat = GetPlayerVehicleSeat(playerid);
         if(seat == 0)
         {
            SetPlayerArmedWeapon(playerid,0);
         }
   }
   if(weapon == 27)
   {
      if(GetPlayerScore(playerid) < 8000)
      {
         new name[MAX_PLAYER_NAME], string[128];
         GetPlayerName(playerid, name, sizeof(name));
         format(string, sizeof(string), "[ANTI CHEAT]:%s is banned for weapon hacking! (SPAS)",name);
         SendClientMessageToAll(RED, string);
         PlayerInfo[playerid][pBan] = 1;
         BanEx(playerid,"Weapon Hack (SPAS)");
      }
   }
   return 1;
}
Reply
#2

You can move stuff away from the main thing if you implement an OnPlayerWeaponChange callback.

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerNPC(playerid)) return 1;

    // ----- Stuff that needs constant checking -----
   
    // ----- OnPlayerWeaponChange -----
    static
        oldWeapon[MAX_PLAYERS char];
    new
        newWeapon = GetPlayerWeapon(playerid);
       
    if(newWeapon != oldWeapon{playerid})
    {
        OnPlayerWeaponChange(playerid, newWeapon, oldWeapon{playerid});
        oldWeapon{playerid} = newWeapon;
        return 1;
    }

    // Rest of stuff
}
pawn Код:
public OnPlayerWeaponChange(playerid, newweapon, oldweapon)
{
    // check if newweapon = 38, 39 ...
    return 1;
}
As long as you're not doing loops or extensive calculations you should be fine.
Reply
#3

You must realize that OnPlayerUpdate is called a few times per second, which is really alot..
Try commenting it with /* and */, the whole OnPlayerUpdate callback, and see if the lagg goes away.
This would be the easiest method to see if that's the source of your lagg.
Reply
#4

Alright,just asking straightly,which release is it of yours? Or,how can I profile?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)