Problem with countdown
#1

Hi guys, i'm making a race but i've a problem with for(new i = 0; i < MAX_PLAYERS; i++). The cd is repeated a lot of times and i'm sure that i've done a terrible mess with the script:
pawn Код:
public Start5()
{
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
        if(PlayerRace[i] == true)
        {
            GameTextForPlayer(i, "~y~5", 1500, 3);
            SetTimer("Start4", 1000, false);
            PlayerPlaySound(i, 1056, 0, 0, 0);
        }
      }
    return 1;
}

public Start4()
{
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
        if(PlayerRace[i] == true)
        {
            GameTextForPlayer(i, "~b~4", 1500, 3);
            SetTimer("Start3", 1000, false);
            PlayerPlaySound(i, 1056, 0, 0, 0);
        }
      }
    return 1;
}

public Start3()
{
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
        if(PlayerRace[i] == true)
        {
            GameTextForPlayer(i, "~p~3", 1500, 3);
            SetTimer("Start2", 1000, false);
            PlayerPlaySound(i, 1056, 0, 0, 0);
        }
      }
    return 1;
}

public Start2()
{
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
        if(PlayerRace[i] == true)
        {
            GameTextForPlayer(i, "~y~2", 1500, 3);
            SetTimer("Start1", 1000, false);
            PlayerPlaySound(i, 1056, 0, 0, 0);
        }
      }
    return 1;
}

public Start1()
{
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
        if(PlayerRace[i] == true)
        {
            GameTextForPlayer(i, "~r~1", 1500, 3);
            SetTimer("StartGo", 1000, false);
            PlayerPlaySound(i, 1056, 0, 0, 0);
        }
      }
    return 1;
}

public StartGo()
{
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
        if(PlayerRace[i] == true)
        {
            GameTextForPlayer(i, "~g~go!", 1000, 3);
            PlayerPlaySound(i, 1057, 0, 0, 0);
            TogglePlayerControllable(i, 1);
            DisablePlayerRaceCheckpoint(i);
            SetPlayerRaceCheckpoint(i, 0, 1156.5406,-877.0353,43.8308, 1166.3489,-731.7609,60.8410, 20.0);
            CountCheck[i] = 1;
            Partenza = true;
            racez[i] = true;
        }
    }
    return 1;
}
Reply
#2

For starters use foreach. And secondly, way to many times. Combined it into one, at least.
Reply
#3

You start a global timer 500 times

pawn Код:
new count=5;

public StartCountDown
{
if(count<= 0) return //race starts
new Str[60];
for(new i=0; i < MAX_PLAYERS; i++)
    {
          format(str, sizeof str,"race starts in %d",count);
          SendClientMessage(i,-1,str);
    }
count--;
SetTimer("StartCountDown", 1000, false);
}
Reply
#4

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
You start a global timer 500 times

pawn Код:
new count=5;

public StartCountDown
{
if(count<= 0) return //race starts
new Str[60];
for(new i=0; i < MAX_PLAYERS; i++)
    {
          format(str, sizeof str,"race starts in %d",count);
          SendClientMessage(i,-1,str);
    }
count--;
SetTimer("StartCountDown", 1000, false);
}
I've made this, but i've got the same problem .-.
pawn Код:
new count=5;

public StartCountDown()
{
if(count<= 0) return SetTimer("StartRace",100,false),Partenza = true;
new str[60];
for(new i=0; i < MAX_PLAYERS; i++)
    {
       if(IsPlayerConnected(i) && PlayerRace[i] == true)
       {
          format(str, sizeof str,"~r~La Gara inizia tra ~g~%d",count);
          PlayerPlaySound(i, 1056, 0, 0, 0);
          GameTextForPlayer(i,str,1000,3);
       }
    }
count--;
SetTimer("StartCountDown", 1000, false);
return 1;
}
Reply
#5

pawn Код:
new CDTxt[][] = {

    "~g~go!",
    "~r~1",
    "~y~2",
    "~p~3",
    "~b~4",
    "~y~5"
};

forward CountDownForAll(times);
public CountDownForAll(times)
{
    if(times)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
            if(IsPlayerConnected(i) && PlayerRace[i])
            {
                GameTextForPlayer(i, CDTxt[times], 1500, 3);
                PlayerPlaySound(i, 1056, 0, 0, 0);
            }

        SetTimerEx("CountDownForAll",1000,false,"i",times-1);
    }else{
        for(new i = 0; i < MAX_PLAYERS; i++)
            if(IsPlayerConnected(i) && PlayerRace[i])
            {
                GameTextForPlayer(i, CDTxt[times], 1000, 3);
                PlayerPlaySound(i, 1057, 0, 0, 0);
                TogglePlayerControllable(i, 1);
                DisablePlayerRaceCheckpoint(i);
                SetPlayerRaceCheckpoint(i, 0, 1156.5406,-877.0353,43.8308, 1166.3489,-731.7609,60.8410, 20.0);
                CountCheck[i] = 1;
                racez[i] = true;
            }

        Partenza = true;
    }
    return 1;
}
and for start cd

pawn Код:
CountDownForAll(sizeof(CDTxt)-1);
Reply
#6

Working I love u
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)