SA-MP Forums Archive
Respawn only unused vehicles - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Respawn only unused vehicles (/showthread.php?tid=465884)



Respawn only unused vehicles - iWaYz - 24.09.2013

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



Re: Respawn only unused vehicles - TonyII - 24.09.2013

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



Re: Respawn only unused vehicles - iWaYz - 24.09.2013

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


Re: Respawn only unused vehicles - TonyII - 24.09.2013

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



Re: Respawn only unused vehicles - Patrick - 24.09.2013

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:SetVehicleToRespawn
    }//close bracket
}//open bracket
Edit: Too Late


Re: Respawn only unused vehicles - TonyII - 24.09.2013

Your explanation is much better then mine tho,