24.08.2013, 07:32
Oh, my bad. Then I guess, assuming you have an enum for players -
Either use a timer, or you can overload (native) the CreateVehicle function to call a custom callback, say "OnPlayerSpawnVehicle" and check if previous vehicle spawned is occupied or not (will reduce usage of CPU - Just called when the next vehicle is spawned instead of a per second timer.)
pawn Код:
forward public CheckForUnusedVehs(playerid);
enum pI
{
vSPAWNED[ 10 ] // Can spawn max 10 vehicles
}
new PlayerInfo[ MAX_PLAYERS ][ pI ];
public OnPlayerConnect(playerid)
{
for(new i = 0 ; i < MAX_PLAYERS ; i++ )
{
PlayerInfo[playerid][vSPAWNED][ i ] = -1;
}
SetTimerEx("CheckForUnusedVehs", 1000, 1, "d", playerid);
return 1;
}
CMD:v(..)
{
..
for(new i = 0 ; i < 10; i ++)
{
if( PlayerInfo[playerid][vSPAWNED][ i ] == -1 )
return (PlayerInfo[playerid][vSPAWNED][ i ] = CreateVehicle(...));
}
return 1;
}
stock GetVehicleDriver(vehicleid)
{
for(new i; i<MAX_PLAYERS; i++)
{
if (IsPlayerInVehicle(i, vehicleid))
{
if(GetPlayerState(i) == 2)
{
return i;
}
}
}
return -1;
}
public CheckForUnusedVehs( playerid )
{
for(new i = 0; i < 10; i++ )
{
if(PlayerInfo[playerid][ vSPAWNED ][ i ] != -1 )
{
if(GetVehicleDriver( PlayerInfo[playerid][ vSPAWNED ][ i ] ) == -1)
{
DestroyVehicle( i );
}
}
........