vehicles empty.
#3

The above code will respawn every vehicle if playerid 0 isn't inside any of them.
It will also respawn the same vehicle for every player not inside a vehicle.
Also, the additional checks never work since it's looping through integer values from 0 to MAX_PLAYERS (usually 50) and MAX_VEHICLES (usually 2000).
Both INVALID_xxx values are set to 65535, which will never be reached and can be removed from that code.

And it will spam the chatbox as well.

pawn Код:
CMD:cleanvehicles(playerid, params[])
{
    // Setup local variables
    new bool:PlayerInsideVehicle = false;

    // Loop through all vehicles (first vehicle-id is 1, not 0)
    for(new vid = 1; vid < MAX_VEHICLES; vid++)
    {
        // If this vehicle doesn't have a model, it doesn't exist and the loop continues with the next vehicle, skipping the rest of the code
        if (GetVehicleModel(vid) == 0) continue;

        // Loop through all players
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            // Check if this player is connected
            if (IsPlayerConnected(i)
            {
                // If this player is connected, check if he's inside the current vehicle
                if(IsPlayerInVehicle(i, vid))
                {
                    // Current vehicle is occupied by at least one player
                    PlayerInsideVehicle = true;
                }
            }
        }

        // If no player is inside this vehicle, respawn it (if there is at least one player inside it, don't do anything)
        if (PlayerInsideVehicle == false)
        {
            SetVehicleToRespawn(vid); // You may also put "DestroyVehicle(vid);" on this line to delete them instead of respawning
        }

        // Re-initialize the variable and proceed with the next vehicle
        PlayerInsideVehicle = false;
    }

    // Send a message to all players to let them know unoccupied vehicles have been respawned
    SendClientMessageToAll(-1, "Unused vehicles successfully respawned");

    return 1;
}
Reply


Messages In This Thread
vehicles empty. - by Snoopythekill - 16.12.2014, 18:45
Re: vehicles empty. - by Sawalha - 16.12.2014, 19:01
Re: vehicles empty. - by PowerPC603 - 16.12.2014, 21:07

Forum Jump:


Users browsing this thread: 2 Guest(s)