SA-MP Forums Archive
Does this timer will cause lag of the entire server? - 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: Does this timer will cause lag of the entire server? (/showthread.php?tid=643599)



Does this timer will cause lag of the entire server? - ToiletDuck - 23.10.2017

Hi, I just coded this for my Furnace System.

here is the code I use y_timer
Код:
task FurnaceTimer[1000]()
{
	for(new x = 0; x < MAX_BASES; x++)
	{
		if(BaseData[x][baseCreated])
		{
			if(BaseData[x][baseTotalFurnace] != 0)
			{
				for(new y = 0; y < MAX_BASEOBJECTS; y++)
				{
					if(BaseObjectData[x][y][oID] != INVALID_OBJECT_ID && BaseObjectData[x][y][oFurnace] && BaseObjectData[x][y][oFurnaceStatus])
					{
						if(BaseFurnaceData[x][y][furnaceMainItem] != -1 && BaseFurnaceData[x][y][furnaceSecondItem] != -1 || BaseFurnaceData[x][y][furnaceSecondItem] != -1)
						{
							if(BaseFurnaceData[x][y][furnaceSItemQuantity] < 2) return 1;
							if(++BaseObjectData[x][y][oFurnaceTimer] >= 120)
							{
								if(BaseFurnaceData[x][y][furnaceMainItem] != -1 && BaseFurnaceData[x][y][furnaceSecondItem] != -1)
								{
									BaseFurnaceData[x][y][furnaceMItemQuantity]--;
									switch(BaseFurnaceData[x][y][furnaceMainItem])
									{
										case ITEM_IRON:
										{
											if(BaseFurnaceData[x][y][furnaceFinalItem] != ITEM_IRON) return 1;
											BaseFurnaceData[x][y][furnaceFinalItem] = ITEM_IRONBAR;
											BaseFurnaceData[x][y][furnaceFItemQuantity]++;
										}
										case ITEM_BLUEIRON:
										{
											if(BaseFurnaceData[x][y][furnaceFinalItem] != ITEM_BLUEIRON) return 1;
											BaseFurnaceData[x][y][furnaceFinalItem] = ITEM_BLUEIRONBAR;
											BaseFurnaceData[x][y][furnaceFItemQuantity]++;

										}
										case ITEM_REDIRON:
										{
											if(BaseFurnaceData[x][y][furnaceFinalItem] != ITEM_REDIRON) return 1;
											BaseFurnaceData[x][y][furnaceFinalItem] = ITEM_REDIRONBAR;
											BaseFurnaceData[x][y][furnaceFItemQuantity]++;

										}
									}
								}
								BaseFurnaceData[x][y][furnaceSItemQuantity] -= 2;
								BaseObjectData[x][y][oFurnaceTimer] = 0;
							}
						}
						else BaseObjectData[x][y][oFurnaceStatus] = 0;
					}
				}
				
			}
		}
	}
        return 1;
}
will this code cause lags? if there are hundred of bases and hundred of base furnace objects? if Yes how I can optimize this?


Re: Does this timer will cause lag of the entire server? - whadez - 23.10.2017

Oh the styling of code ...
What is the purpose of this could you tell us so maybe we can give you a better code?


Re: Does this timer will cause lag of the entire server? - ToiletDuck - 23.10.2017

Quote:
Originally Posted by whadez
Посмотреть сообщение
Oh the styling of code ...
What is the purpose of this could you tell us so maybe we can give you a better code?
every 2mins it will produce a new material. hmm not being rude here xD

The code there stated what i wanted to be. I'm not quite sure if this code or way of coding will cause lag.
Uhm how do I explain this lol. As you can see the code there every two minutes will produce new material.

Also It loops through all Bases created in the server and Furnaces In the server.

So meaning if there are hunred of bases this code will loop it all same goes to furnace