How can i make it stop searching when it finds 1 unoccupied vehicle
#1

Well i have this script and what its supposed to do is when u spawn it will find a unocupied vehicle and put u in it.
well it works kind of as i can move the wheels of a car when i spawn. But my player isnt sat in the seat, And a few secs later i die, I think its trying to put me in all the vehicles. So i need to make it stop searching when it finds 1 unoccpued vehicle. How?

pawn Код:
public OnPlayerRequestSpawn(playerid)
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(IsVehicleOccupied(i))
        {
            GameTextForPlayer(playerid, "There are no more cars left.", 2500, 3);
        }
        else if(!IsVehicleOccupied(i))
        {
            PutPlayerInVehicle(playerid, i, 0);
        }
    }
    return 1;
}
   
stock IsVehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
        {
            if(GetPlayerVehicleID(i) == vehicleid)
            {
                return 1;
            }
        }
    }
    return 0;
}
Reply
#2

Try this:
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
     new vehicleid = INVALID_VEHICLE_ID;
     for(new i = 0; i < MAX_VEHICLES; i++)
     {
          if(!IsVehicleOccupied(i))
          {
               vehicleid = i;
               break;
          }
     }
     if(vehicleid != INVALID_VEHICLE_ID)
     {
          PutPlayerInVehicle(playerid, vehicleid, 0);
     }
     else
     {
          GameTextForPlayer(playerid, "There are no more cars left.", 2500, 3);
     }
     return 1;
}
Reply
#3

Not putting me in vehicle at all
Reply
#4

Quote:
Originally Posted by iTorran
Посмотреть сообщение
Not putting me in vehicle at all
Working, tested:

pawn Код:
public OnPlayerRequestSpawn(playerid)
{
     new vehicleid = INVALID_VEHICLE_ID;
     for(new i = 0; i < MAX_VEHICLES; i++)
     {
          if(!IsVehicleOccupied(i) && IsVehicleConnected(i))
          {
               vehicleid = i;
               break;
          }
     }
     if(vehicleid != INVALID_VEHICLE_ID)
     {
          PutPlayerInVehicle(playerid, vehicleid, 0);
     }
     else
     {
          GameTextForPlayer(playerid, "There are no more cars left.", 2500, 3);
     }
     return 1;
}

stock IsVehicleConnected(vehicleid)
{
  new Float:x1,Float:y1,Float:z1;
  GetVehiclePos(vehicleid,x1,y1,z1);
  if(x1==0.0 && y1==0.0 && z1==0.0)
  {
    return 0;
  }
  return 1;
}
Reply
#5

Fixed!!!!!!!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)