SA-MP Forums Archive
Countdown not starting? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Countdown not starting? (/showthread.php?tid=153118)



Countdown not starting? - NewTorran - 07.06.2010

Hello,

Im trying to make a race script,
And ive run into a little problem with the countdown,

What i want it to do is,
Check if theres more than 1 player online, If there is.
It will start a timer. But when theres 2 people online my server, I never see the countdown?
This is my code: (Unfinished)

pawn Код:
public CheckPlayers()
{
    if(RaceStarted == 0)
    {
        if(GetOnlinePlayers() > 1)
        {
            SetTimer("Countdown", 1000, 0);
            RaceStarted = 1;
            GameTextForAll("~w~Race starting in...", 1000, 4);
        }
    }
    return 1;
}
Oh and:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(RaceStarted == 0)
        {
          TogglePlayerControllable(playerid, 0);
          SetTimer("CheckPlayers", 5000, 1);
        }
    }
    return 1;
}



Re: Countdown not starting? - Ihsan_Cingisiz - 07.06.2010

Quote:
Originally Posted by Joe Torran C
Hello,

Im trying to make a race script,
And ive run into a little problem with the countdown,

What i want it to do is,
Check if theres more than 1 player online, If there is.
It will start a timer. But when theres 2 people online my server, I never see the countdown?
This is my code: (Unfinished)

pawn Код:
public CheckPlayers()
{
    if(RaceStarted == 0)
    {
        if(GetOnlinePlayers() > 1)
        {
            SetTimer("Countdown", 1000, 0);
            RaceStarted = 1;
            GameTextForAll("~w~Race starting in...", 1000, 4);
        }
    }
    return 1;
}
Oh and:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(RaceStarted == 0)
        {
          TogglePlayerControllable(playerid, 0);
          SetTimer("CheckPlayers", 5000, 1);
        }
    }
    return 1;
}
I think you need to do this..
Quote:

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
if(RaceStarted == 1)
{
TogglePlayerControllable(playerid, 0);
SetTimer("CheckPlayers", 5000, 1);
}
}
return 1;
}




Re: Countdown not starting? - DJDhan - 07.06.2010

Well, you need to show the countdown function coz the problem is there isn't it?


Re: Countdown not starting? - Ihsan_Cingisiz - 07.06.2010

Quote:
Originally Posted by DJDhan
Well, you need to show the countdown function coz the problem is there isn't it?
Yes, he need to do this :
Quote:

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
if(RaceStarted == 1)
{
TogglePlayerControllable(playerid, 0);
SetTimer("CheckPlayers", 5000, 1);
}
}
return 1;
}




Re: Countdown not starting? - NewTorran - 07.06.2010

Quote:
Originally Posted by DJDhan
Well, you need to show the countdown function coz the problem is there isn't it?
No because i dont see the Race is starting in... game text.
Quote:
Originally Posted by Ihsan_Cingisiz
I think you need to do this..
Quote:

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
if(RaceStarted == 1)
{
TogglePlayerControllable(playerid, 0);
SetTimer("CheckPlayers", 5000, 1);
}
}
return 1;
}

No because why would i want to check if the race has started. Then if it has start the race again? :P


Re: Countdown not starting? - DJDhan - 07.06.2010

Try this.
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER)
{
if(RaceStarted == 0)
{
  TogglePlayerControllable(playerid, 0);
  SetTimer("CheckPlayers", 5000, 1);
}
}
return 1;
}



Re: Countdown not starting? - MadeMan - 07.06.2010

pawn Код:
SetTimer("CheckPlayers", 5000, 1);
Put this under OnGameModeInit


Re: Countdown not starting? - NewTorran - 07.06.2010

Quote:
Originally Posted by MadeMan
pawn Код:
SetTimer("CheckPlayers", 5000, 1);
Put this under OnGameModeInit
Ok will try that


Re: Countdown not starting? - NewTorran - 07.06.2010

Yes that works thankyou!

But how can i detect if a vehicle is unoccupied, If it is, Put the player in it.

I have this:

pawn Код:
public OnPlayerSpawn(playerid)
{
  if(RaceStarted == 0)
    {
        for(new i = 0; i<MAX_VEHICLES; i++)
      {
        for(new i2 = 0; i2<MAX_PLAYERS; i2++)
            {
                if(IsPlayerInVehicle(i2, i))
                {
                  return 1;
                }
            }
            PutPlayerInVehicle(playerid, i, 0);
        }
    }
    return 1;
}



Re: Countdown not starting? - MadeMan - 07.06.2010

http://forum.sa-mp.com/index.php?topic=178519.0