Respawn only unused vehicles
#1

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

Quote:
Originally Posted by iWaYz
Посмотреть сообщение
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);
			}
		}
pawn Код:
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);
        }
    }
Reply
#3

Sorry for my impertinence but can you make further explain. Because I can't understand it. ;(
Reply
#4

Sure
pawn Код:
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);
        }
    }
Reply
#5

I'll use TonyII's code and explain it to you
pawn Код:
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:...eToRespawn
    }//close bracket
}//open bracket
Edit: Too Late
Reply
#6

Your explanation is much better then mine tho,
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)