03.08.2014, 13:42
is there any method to count how many players are in my current vehicle and check what seats id's are they in?!!
OnPlayerEnterVehicle
{
CountPlayersInVehicle(vehicleid, blabla
}
forward CountPlayersInVehicle(vehicleid);
public CountPlayersInVehicle(vehicleid)
{
PlayerInVehicle++;
}
new veh = GetPlayerVehicleID(playerid), cnt = 0, Seat[10][2], i;
for(i = 0; i < MAX_PLAYERS; i++) //Start a loop through all players. (Foreach is the recommended approach)
{
if(!IsPlayerConnected(i)) continue; //This skips ids that aren't connected. Remove if using Foreach
if(!IsPlayerInVehicle(i, veh)) continue; //This skips ids that are not inside your vehicle.
new vseat = GetPlayerVehicleSeat(i); //Get the player's vehicle seat ID
Seat[cnt][0] = i; //Save the playerid to the first element.
Seat[cnt][1] = (-1 < vseat < sizeof(Seat)) ? (vseat) : (cnt + 1); //Save the player's seat to the second element
++cnt; //Add '1' to the seat count.
}
for(i = 0; i < cnt; i++) printf("ID %d is in Seat ID %d", Seat[i][0], Seat[i][1]);
stock CountPlayersInVehicle(vehicleid)
{
new res = 0;
foreach(new i: Player)
if(GetPlayerVehicleID(i) == vehicleid) res++;
return res;
}
Thank you all, but another question: can i check which seat id is UnOccupied (empty) ?
|
stock GetFreeSeat(vehicleid)
{
foreach(new i: Player) {
if(IsPlayerInAnyVehicle(i) && GetPlayerVehicleID(i) == vehicleid) {
for(new j = 0; j < 9; j++) {
if(GetPlayerVehicleSeat(i) == j) continue;
else return j;
}
return -1;
}
}
return 1;
}
pawn Код:
|
That code wont work at all, first you loop through the players than if you found a player inside the vehicle you get his seatid and if it isn't j (start at 0 goes till the function returns j
If the seatid of the first person found is 0 than the function will return 1 and if the seatid isn't 0 than it will return 0 |
if(GetPlayerVehicleSeat(i) == j) continue;