SA-MP Forums Archive
Help with a public function. - 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: Help with a public function. (/showthread.php?tid=439608)



Help with a public function. - Strier - 26.05.2013

Alright, when the minutes / seconds are @0 the code is supposed to re-spawn everyone and show them the class selection, and announce the winner but it just goes to 0:00 and nothing happens, here is the public function.

pawn Код:
public TeamWinning(playerid)
{
    if(Seconds == 0 && Minutes == 0)
    {
        if(cKills > tKills)
        {
            GameTextForAll("~r~~h~Terrorists win!", 5000, 6);
            cKills = 0;
            tKills = 0;
            for(new i=0;i<MAX_PLAYERS;i++)
            {
                 ForceClassSelection(playerid);
            }
        }
        else if(cKills < tKills)
        {
            if(Seconds == 0 && Minutes == 0)
            {
                GameTextForAll("~b~~h~Counter terrorists win!", 5000, 6);
                cKills = 0;
                tKills = 0;
                for(new i=0;i<MAX_PLAYERS;i++)
                {
                    ForceClassSelection(playerid);
                }
            }
        }
        else if(cKills == tKills)
        {
            if(Seconds == 0 && Minutes == 0)
            {
                GameTextForAll("~w~~h~None won the match!",4000,6);
                cKills = 0;
                tKills = 0;
                for(new i=0;i<MAX_PLAYERS;i++)
                {
                    ForceClassSelection(playerid);
                }
            }
        }
    }
    return 1;
}



Re: Help with a public function. - Revo - 26.05.2013

You'll need to provide more information, e.g. the timer to zero function, and the timer or function that triggers this function.

Also, you're repeating your code, it doesn't matter much, but it's just a pain in my eyes to keep it like that, simply due to its length. Also check if the player is connected.

Consider doing this:

pawn Код:
if(Seconds == 0 && Minutes == 0)
    {
        if(cKills > tKills)
        {
            GameTextForAll("~r~~h~Terrorists win!", 5000, 6);
        }
        else if(cKills < tKills)
        {
            GameTextForAll("~b~~h~Counter terrorists win!", 5000, 6);
        }
        else
        {
            GameTextForAll("~w~~h~None won the match!",4000,6);
        }
       
        cKills = 0;
        tKills = 0;
        for(new i=0;i<MAX_PLAYERS;i++)
        {
             if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
             ForceClassSelection(playerid);
        }
    }



Re: Help with a public function. - Strier - 26.05.2013

pawn Код:
new Seconds = 59;
new Minutes = 4;

public GameTime(playerid)
{
    if(Seconds || Minutes) {
        Seconds--;
        if(Seconds <= -1) {
            Minutes--;
            Seconds=59;
        }
        new TimeString[128];
        format(TimeString, 128, "~Y~~H~TIME LEFT: %02d:%02d", Minutes, Seconds);
        PlayerTextDrawSetString(playerid, Textdraw0[ playerid ], TimeString);
    }

    return 1;
}

SetTimer("GameTime", 1000, true);
The timer is set in ongamemodeinit and it's set to 1000 to update the TD..


Re: Help with a public function. - Strier - 26.05.2013

Bump


Re: Help with a public function. - Vince - 26.05.2013

Quote:
Originally Posted by Revo
Посмотреть сообщение
Also check if the player is connected.
No point. Functions won't work for players that aren't connected. To fix your problem, read this: https://sampwiki.blast.hk/wiki/ForceClassSelection. Specifically the note.


Re: Help with a public function. - Strier - 26.05.2013

So yeah, i've finished the code still when the count is 0, it doesn't do what it has to do...

here the code:

pawn Код:
public TeamWinning(playerid)
{
    if(Seconds == 0 && Minutes == 0)
    {
        if(cKills > tKills)
        {
            GameTextForAll("~r~~h~Terrorists win!", 5000, 6);
        }
        else if(cKills < tKills)
        {
            GameTextForAll("~b~~h~Counter terrorists win!", 5000, 6);
        }
        else
        {
            GameTextForAll("~w~~h~None won the match!",4000,6);
        }

        cKills = 0;
        tKills = 0;
        Seconds=59;
        Minutes=0;
        for(new i=0;i<MAX_PLAYERS;i++)
        {
            if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
            ForceClassSelection(i);
            TogglePlayerSpectating(i, true);
            TogglePlayerSpectating(i, false);
        }
    }
    return 1;
}