Help with a public function.
#1

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;
}
Reply
#2

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);
        }
    }
Reply
#3

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..
Reply
#4

Bump
Reply
#5

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.
Reply
#6

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;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)