SA-MP Forums Archive
Is looping in that way wrong? - 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: Is looping in that way wrong? (/showthread.php?tid=524031)



Is looping in that way wrong? - TH3_R3D™ - 04.07.2014

Greetings,

pawn Код:
//underneath an other function
SetTimer("CheckPlayers", 1000, 1);
Код:
The function which is causing : Run time error 3: "Stack/heap collision (insufficient stack size)"
pawn Код:
public CheckPlayers()
{
    foreach(new i : Player)
    {
        if(IsPlayerInWater(i))
        {
            OnPlayerLoseDerby(i);
        }
        if(PlayerCount == 1 && PlayerIsPlaying[i] == 1)
        {
            TogglePlayerControllable(i, 0);
           
            new str[100];
            format(str, sizeof(str), "Winner is: %s", GetPlayerNameEx(i));
            SendClientMessage(i,GREEN, str);
            if(PlayerIsPlaying[i] == 1){
                GivePlayerMoney(i, 1000); }

            PlayerIsPlaying[i] = 0;
            DerbyStart = 0;
            NextMap();
        }
        if(PlayerCount == 0 && PlayerIsPlaying[i] == 0)
        {
            TogglePlayerControllable(i, 0);
           
            SendClientMessage(i,GREEN, "No Winner");
            PlayerIsPlaying[i] = 0;
            DerbyStart = 0;
            KillTimer(DetectPlayer);
            NextMap();
        }
    }
    return 1;
}
Am I doing it wrong? Thanks in advance!


Re: Is looping in that way wrong? - TH3_R3D™ - 05.07.2014

A day passed...


Re: Is looping in that way wrong? - rickisme - 05.07.2014

try this ?

pawn Код:
public CheckPlayers()
{
    foreach(new i : Player)
    {
        if(IsPlayerInWater(i))
        {
            OnPlayerLoseDerby(i);
        }
        if(PlayerCount == 1 && PlayerIsPlaying[i] == 1)
        {
            TogglePlayerControllable(i, 0);
           
            new str[100];
            format(str, sizeof(str), "Winner is: %s", GetPlayerNameEx(i));
            SendClientMessage(i,GREEN, str);
            if(PlayerIsPlaying[i] == 1){
                GivePlayerMoney(i, 1000); }

            PlayerIsPlaying[i] = 0;
            DerbyStart = 0;
            NextMap();
        }
        else if(PlayerCount == 0 && PlayerIsPlaying[i] == 0)
        {
            TogglePlayerControllable(i, 0);
           
            SendClientMessage(i,GREEN, "No Winner");
            PlayerIsPlaying[i] = 0;
            DerbyStart = 0;
            KillTimer(DetectPlayer);
            NextMap();
        }
    }
    return 1;
}



Re: Is looping in that way wrong? - TH3_R3D™ - 05.07.2014

no effect, (what adjustments have you made?) I can see nothing..


Re: Is looping in that way wrong? - rickisme - 05.07.2014

just add else after if

btw compile your script with -d2 mode to get error line


Re: Is looping in that way wrong? - TH3_R3D™ - 05.07.2014

Quote:
Originally Posted by rickisme
Посмотреть сообщение
btw compile your script with -d2 mode to get error line
how?


Re: Is looping in that way wrong? - rickisme - 05.07.2014

https://github.com/Zeex/samp-plugin-...ith-debug-info