SA-MP Forums Archive
My code gave a server lag out??? - 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: My code gave a server lag out??? (/showthread.php?tid=428278)



My code gave a server lag out??? - SequenceCuz - 05.04.2013

here is my code

PHP Code:
stock CreateBgs(playeridFloat:x,Float:y,Float:z)
{
    for(new 
0sizeof(BgsCreate); i++)
      {
          if(
BgsCreate[i][pMake] == 0)
          {
              if(
PlayerInfo[playerid][pBag] == 1)
            {
                
AddItem(i,"Coyote Patrol Pack",1);
            }
              if(
PlayerInfo[playerid][pBag] == 2)
            {
                
AddItem(i,"Alice Backpack",1);
            }
              if(
PlayerInfo[playerid][pBag] == 3)
            {
                
AddItem(i,"Money Backpack",1);
            }
             while(
PlayerHasItem(playerid,"Bandage"))
              {
                  
AddItem(i,"Bandage",1);
                  
RemoveItem(playerid,"Bandage",1);
              }
              while(
PlayerHasItem(playerid,"Water Bottle"))
              {
                  
AddItem(i,"Water Bottle",1);
                  
RemoveItem(playerid,"Water Bottle",1);
              }
              while(
PlayerHasItem(playerid,"Baseball bat"))
              {
                  
AddItem(i,"Baseball bat",1);
                  
RemoveItem(playerid,"Baseball bat",1);
              }
              while(
PlayerHasItem(playerid,"Painkiller"))
              {
                  
AddItem(i,"Painkiller",1);
                  
RemoveItem(playerid,"Painkiller",1);
              }
              while(
PlayerHasItem(playerid,"Empty Water Bottle"))
              {
                  
AddItem(i,"Empty Water Bottle",1);
                  
RemoveItem(playerid,"Empty Water Bottle",1);
              }
              while(
PlayerHasItem(playerid,"Cop Clothes"))
              {
                  
AddItem(i,"Cop Clothes",1);
                  
RemoveItem(playerid,"Cop Clothes",1);
              }
              while(
PlayerHasItem(playerid,"9mm Pistol"))
              {
                  
AddItem(i,"9mm Pistol",1);
                  
RemoveItem(playerid,"9mm Pistol",1);
              }
              while(
PlayerHasItem(playerid,"Pistol Ammo"))
              {
                  
AddItem(i,"Pistol Ammo",1);
                  
RemoveItem(playerid,"Pistol Ammo",1);
              }
              while(
PlayerHasItem(playerid,"Police Car Key"))
              {
                  
AddItem(i,"Police Car Key",1);
                  
RemoveItem(playerid,"Police Car Key",1);
              }
              while(
PlayerHasItem(playerid,"AK-47"))
              {
                  
AddItem(i,"AK-47",1);
                  
RemoveItem(playerid,"AK-47",1);
              }
              while(
PlayerHasItem(playerid,"M4A1"))
              {
                  
AddItem(i,"M4A1",1);
                  
RemoveItem(playerid,"M4A1",1);
              }
              while(
PlayerHasItem(playerid,"Mp5"))
              {
                  
AddItem(i,"Mp5",1);
                  
RemoveItem(playerid,"Mp5",1);
              }
              while(
PlayerHasItem(playerid,"Room Key 047"))
              {
                  
AddItem(i,"Room Key 047",1);
                  
RemoveItem(playerid,"Room Key 047",1);
              }
            
BgsCreate[i][pMake]=1;
            
BgsCreate[i][pX]=x;
            
BgsCreate[i][pY]=y;
            
BgsCreate[i][pZ]=z-0.4;
            
BgsCreate[i][pObject] = CreateObject(bagmo[playerid], xyz-0.4000);
            
BgsCreate[i][p3d] = CreateStreamed3DTextLabel("{1AE657}BAG\n{AAAAAA}Ўґ»ШиБ Left Alt аѕЧиН¤й№ўН§"0xAAAAAAC8xyz-0.410.00);
            return 
1;
          }
    }
      return 
0;

it work fine i place it on

PHP Code:
public onplayerdeath(playerid)
{
      
Createbgs(playeridx,y,z);
      
///blablabla

And it work fine only die around 5-9 times

Then it does server lag out cannot do anything
cannot respond


Re: My code gave a server lag out??? - Djole1337 - 05.04.2013

It's like you did while(true) - Infinite loop.


Re: My code gave a server lag out??? - SequenceCuz - 05.04.2013

how to fixed it??


Re: My code gave a server lag out??? - Djole1337 - 05.04.2013

Not quite sure what is this
pawn Code:
while(PlayerHasItem(playerid,"Bandage"))
You meant if(..) ?


Re: My code gave a server lag out??? - SequenceCuz - 05.04.2013

no if

If i use "if" it will be one times right

I want to use while because

While i have bandage then it keep going does the progress man u know ??