SA-MP Forums Archive
Message showing two times - 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: Message showing two times (/showthread.php?tid=675118)



Message showing two times - _GHT_MarK445 - 05.05.2020

Code:
forward duelstart();
public duelstart()
{
	DuelCountdown --;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(InDuel[i] == true)
            {
				if(DuelCountdown == 5)
				{
				    GameTextForPlayer(i, "~r~5", 1000, 3);
				    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
				}
				if(DuelCountdown == 4)
				{
				    GameTextForPlayer(i, "~r~4", 1000, 3);
				    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
				}
				if(DuelCountdown == 3)
				{
				    GameTextForPlayer(i, "~r~3", 1000, 3);
				    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
				}
				if(DuelCountdown == 2)
				{
				    GameTextForPlayer(i, "~r~2", 1000, 3);
				    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
				}
				if(DuelCountdown == 1)
				{
				    GameTextForPlayer(i, "~r~1", 1000, 3);
				    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
				}
				if(DuelCountdown == 0)
				{
					KillTimer(dueltimer);
					Duel = true;
	                new string[128];
	                format(string, sizeof(string), "Boxing duel between %s and %s started!", Dueler1, Dueler2);
	                SendClientMessageToAll(DUEL, string);
	                TogglePlayerControllable(i, 1);
	                GameTextForPlayer(i, "~g~BOX YOURSELF!", 2000, 3);
	                PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
				}
			}
		}
	}
	return 1;
}
I have this function in timer, it is 1000ms timer (1 second). The problem is, that when the DuelCountdown gets to 0, it like starts the duel twice (writes the Boxing duel between message twice). Do you guys have any reason why this could occur?


Re: Message showing two times - SyS - 05.05.2020

You might want to change the
PHP Code:
SendClientMessageToAll(DUELstring); 
or add break in that last if condition
PHP Code:
if(DuelCountdown == 0)
{
/*your code*/
   
break;

It sends to all players and the loop still iterates for other players in duel too as no break in iteration is provided and therefore, it repeats the message.


Re: Message showing two times - _GHT_MarK445 - 06.05.2020

When i broke it there, one player (of the two) is not getting unfrozen (toggleplayercontrolable), how to fix this?