SA-MP Forums Archive
For loop not working - 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: For loop not working (/showthread.php?tid=596261)



For loop not working - Hayden_Almeida - 15.12.2015

Hello Guys. I am having a little trouble with my For Loop.
The Public: "Verify_ITAU" is called 1 time, with NO LOOPING.

Here is my code:
Код:
public Verify_ITAU()
{
	if(ITAU_FASE == 3)
	{
	    new Cont = 0;
	    for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(IsPlayerConnected(i))
			{
			    if(BankRobbery[i] == true)
			    {
                    if(IsPlayerInRangeOfPoint(i, 20.0, 829.0986,6.4355,1004.1870) || IsPlayerInRangeOfPoint(i, 300.0, 700.5287,-1162.6360,15.5628)) // Center of the Bank
			    	{
                        Cont++;
			    	}
		    	    if(Cont > 0) // if has anyone in area
                    {
                        SetTimer("Verify_ITAU", 15000, false);
                    }
                    else if(Cont == 0)
                    {
						new ExpGanho = 15; // not Important, giving Experience for player
                        Entrada_ITAU_Trancado = true; // Not Important, Locking the Bank's door.
                        SendClientMessage(i, COLOR_WHITE, "Conseguiu assaltar com sucesso!"); // the msg said: "Robbery sucess"
                        AssaltandoBanco[i] = false; // set the Player Var to false, not important here.
						PlayerInfo[i][pCash] = (PlayerInfo[i][pCash] + Grana_COFRES[i]); // giving money to player
						Grana_COFRES[i] = 0; // setting the money robbed of the player to 0 (var of the player)
						ITAU_FASE = 4; // this is the Phase (sequence)
						GameTextForPlayer(i, "~g~conseguiu!", 5000, 4); // "You did it"
						KillTimer(ALARME_TIMER); // Stopping the Alarm Sound
						SetTimerEx("GanhoExp", 6500, false, "i", i); // Giving the MSG "EXP +"
      				}
				}
			}
		}
	}
	if(ITAU_FASE == 4)
	{
		for(new w = 0; w < MAX_PLAYERS; w++)
		{
			if(IsPlayerConnected(w))
			{
			    SendClientMessage(w,COLOR_AVISO, "Banco ITAЪ trancado! Quem estiver dentro SAIA IMEDIATAMENTE. O Interior serб resetado dentro de 5 minutos. (2)"); // "ITAU BANK locked! Who is inside it, get out now. The interior will be reset in 5 minutes.(2)"
			}
		}
	}
	return 1;
}
And the Result INGAME (screenshot): http://i.imgur.com/aK4HS7Q.png

As you can see, its giving 8 Times the Message. Dont know why. In my point, have no reason for this is happening.


Re: For loop not working - SickAttack - 15.12.2015

The function is called 8 times (only explanation).

= timer issue


Re: For loop not working - Vince - 15.12.2015

Hint: if you expect help here, code in English. I can't be bothered to dissect a piece of code if I can't understand its context.


Re: For loop not working - saffierr - 15.12.2015

Exactly what Vince said, It's pretty annoying...


Re: For loop not working - Hayden_Almeida - 15.12.2015

Quote:
Originally Posted by saffierr
Посмотреть сообщение
Exactly what Vince said, It's pretty annoying...
Quote:
Originally Posted by Vince
Посмотреть сообщение
Hint: if you expect help here, code in English. I can't be bothered to dissect a piece of code if I can't understand its context.
I traslated now.
Try to read now. Thanks.


Re: For loop not working - Hayden_Almeida - 15.12.2015

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
The function is called 8 times (only explanation).

= timer issue
I dont think so. Because the Public "Verify ITAU" is called 1 time, with Loop: false. And the this public ONLY WILL BE CALLED AGAIN in this line:
Код:
Cont++;
}
if(Cont > 0) // if has anyone in area
{
           SetTimer("Verify_ITAU", 15000, false);
}
Cont = the number of the people inside area. If there is no one inside, Cont will be = 0 . And will not pass the If (Cont > 0) resulting not calling the
Код:
SetTimer("Verify_ITAU", 15000, false);