Checking occupied vehicle?
#1

Hello,

I believe there was a function to check if a vehicle is occupied... Now I can't find it. Does anyone know what it was?

Regards, Jochem
Reply
#2

There is no native function to check that, but you can make your own.
Reply
#3

I did with a simple loop.

But I don't know if it would work with if(IsVehicleOccupied(vehicleid))

pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i =0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i,vehicleid))
        {
            return 1;
        }
    }
return 0;
}
Reply
#4

pawn Код:
stock IsVehicleOccupied(vehid)
{
    for(new i; i <= MAX_PLAYERS; i++) {
        if(IsPlayerConnected(i)) {
            if(IsPlayerInVehicle(i, vehid)) return 1;
        }
    }
    return 0;
}
Reply
#5

Why using IsPlayerConnected? It was unneeded or is it needed?
Reply
#6

Not needed..
The player cannot be inside a vehicle if *he's not connected.
Reply
#7

I do that with all for statements, it's a habit I've gotten into. It wouldn't do any harm being there anyway.

-Conroy
Reply
#8

Quote:
Originally Posted by Conroy
Посмотреть сообщение
I do that with all for statements, it's a habit I've gotten into. It wouldn't do any harm being there anyway.

-Conroy
Well you're actually wrong.
The code is slower with an unecesarry check like that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)