remove all unoccupied cars spawned with /v command.
#5

Oh, my bad. Then I guess, assuming you have an enum for players -
pawn Код:
forward public CheckForUnusedVehs(playerid);
enum pI
{
     vSPAWNED[ 10 ] // Can spawn max 10 vehicles
}
new PlayerInfo[ MAX_PLAYERS ][ pI ];

public OnPlayerConnect(playerid)
{
    for(new i = 0 ; i < MAX_PLAYERS ; i++ )
    {      
               PlayerInfo[playerid][vSPAWNED][ i ] = -1;
    }
    SetTimerEx("CheckForUnusedVehs", 1000, 1, "d", playerid);
    return 1;
}

CMD:v(..)
{
    ..
    for(new i = 0 ; i < 10; i ++)
    {
           if( PlayerInfo[playerid][vSPAWNED][ i ] == -1 )
                 return (PlayerInfo[playerid][vSPAWNED][ i ] = CreateVehicle(...));
   }
   return 1;
}

stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == 2)
      {
            return i;
      }
    }
  }
  return -1;
}

public CheckForUnusedVehs( playerid )
{
  for(new i = 0; i < 10; i++ )
  {
      if(PlayerInfo[playerid][ vSPAWNED ][ i ] != -1 )
      {
          if(GetVehicleDriver( PlayerInfo[playerid][ vSPAWNED ][ i ]  ) == -1)
           {
                DestroyVehicle( i );
           }
     }
........
Either use a timer, or you can overload (native) the CreateVehicle function to call a custom callback, say "OnPlayerSpawnVehicle" and check if previous vehicle spawned is occupied or not (will reduce usage of CPU - Just called when the next vehicle is spawned instead of a per second timer.)
Reply


Messages In This Thread
remove all unoccupied cars spawned with /v command. - by RedJohn - 21.08.2013, 23:26
Re: remove all unoccupied cars spawned with /v command. - by RedJohn - 22.08.2013, 15:19
Re: remove all unoccupied cars spawned with /v command. - by RajatPawar - 22.08.2013, 15:23
Re: remove all unoccupied cars spawned with /v command. - by RedJohn - 24.08.2013, 00:35
Re: remove all unoccupied cars spawned with /v command. - by RajatPawar - 24.08.2013, 07:32

Forum Jump:


Users browsing this thread: 2 Guest(s)