Countdown not starting?
#1

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

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

Reply
#3

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

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

Reply
#5

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)