if(IsPlayerConnected(playerid)) { if(PlayerInfo[playerid][pRank] == 6 && PlayerInfo[playerid][pMember] == TEAM_GROVE) { for(new cars=0; cars<19; cars++) { if(!VehicleOccupied(cars)) { SetVehicleToRespawn(grovecars[cars]); } } format(string, sizeof(string), "All vehicles has been respawned by %s(%d)", PlayerName(playerid),playerid); SendFactionMessage(TEAM_GROVE, COLOR_LIGHTBLUE, string); } }
Hello everyone, can someone tell me how to respawn only unused vehicles?
Here's my function: Код:
if(IsPlayerConnected(playerid)) { if(PlayerInfo[playerid][pRank] == 6 && PlayerInfo[playerid][pMember] == TEAM_GROVE) { for(new cars=0; cars<19; cars++) { if(!VehicleOccupied(cars)) { SetVehicleToRespawn(grovecars[cars]); } } format(string, sizeof(string), "All vehicles has been respawned by %s(%d)", PlayerName(playerid),playerid); SendFactionMessage(TEAM_GROVE, COLOR_LIGHTBLUE, string); } } |
new bool:vehicleused[MAX_VEHICLES];
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
vehicleused[GetPlayerVehicleID(i)] = true;
}
}
for(new i=1; i < MAX_VEHICLES; i++)
{
if(!vehicleused[i])
{
SetVehicleToRespawn(i);
}
}
for(new i=0; i < MAX_PLAYERS; i++)//Here it is looping through all the players
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))//It checks if any of the players is in a vehicle, so the bool is set to true for the players those are in any vehicle.
{
vehicleused[GetPlayerVehicleID(i)] = true;
}
}
for(new i=1; i < MAX_VEHICLES; i++)//Loop through the vehicles
{
if(!vehicleused[i])//If the bool is false it will respawn the vehicle, else it stays.
{
SetVehicleToRespawn(i);
}
}
new bool:vehicleused[MAX_VEHICLES]; //bool variable
for(new i=0; i < MAX_PLAYERS; i++) // loop of MAX_PLAYERS which is equals to 500
{//open bracket
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i)) // Checking if there is someone inside the vehicle and if the player is connected
{//open bracket
vehicleused[GetPlayerVehicleID(i)] = true; //making the variable true statement, means someone is inside the vehicle
}//close bracket
}//close bracket
for(new i=1; i < MAX_VEHICLES; i++) // loop of MAX_VEHICLES which is equals to 2000 (I guess)
{//open bracket
if(!vehicleused[i]) // ! = return 0; means if the vehicle isn't occupied by any players
{
SetVehicleToRespawn(i); //Loop of all the vehicles and respawn it | Function: https://sampwiki.blast.hk/wiki/Function:SetVehicleToRespawn
}//close bracket
}//open bracket