remove all unoccupied cars spawned with /v command. -
RedJohn - 21.08.2013
I need script to to remove all unoccupied cars spawned with /v command.
Already checked
this thread and it's not helpful.
pawn Код:
COMMAND:v(playerid, params[])
{
if(pInfo[playerid][AdminLevel] < 4) return SendClientMessage(playerid, ERROR, ERROR_LEVEL);
new Vehicle[32], VehicleID, Float:pPosition[4], Message[50];
if(sscanf(params, "s[32]", Vehicle)) return SendClientMessage(playerid, ERROR, USAGE_V);
VehicleID = GetVehicleModelIDFromName(Vehicle);
if(VehicleID != 425 && VehicleID != 432 && VehicleID != 447 &&
VehicleID != 430 && VehicleID != 417 && VehicleID != 435 &&
VehicleID != 446 && VehicleID != 449 && VehicleID != 450 &&
VehicleID != 452 && VehicleID != 453 && VehicleID != 454 &&
VehicleID != 460 && VehicleID != 464 && VehicleID != 465 &&
VehicleID != 469 && VehicleID != 472 && VehicleID != 473 &&
VehicleID != 476 && VehicleID != 484 && VehicleID != 487 &&
VehicleID != 488 && VehicleID != 493 && VehicleID != 497 &&
VehicleID != 501 && VehicleID != 511 && VehicleID != 512 &&
VehicleID != 513 && VehicleID != 519 && VehicleID != 520 &&
VehicleID != 537 && VehicleID != 538 && VehicleID != 548 &&
VehicleID != 553 && VehicleID != 563 && VehicleID != 564 &&
VehicleID != 569 && VehicleID != 570 && VehicleID != 577 &&
VehicleID != 584 && VehicleID != 590 && VehicleID != 591 &&
VehicleID != 592 && VehicleID != 593 && VehicleID != 594 &&
VehicleID != 595 && VehicleID != 606 && VehicleID != 607 &&
VehicleID != 608 && VehicleID != 610 && VehicleID != 611)
{
if(VehicleID == -1 )
{
VehicleID = strval(Vehicle);
if(VehicleID < 400 || VehicleID > 611 ) return SendClientMessage(playerid, ERROR, ERROR_INVALID_CAR);
}
}
GetPlayerPos(playerid, pPosition[0], pPosition[1], pPosition[2]);
GetPlayerFacingAngle(playerid, pPosition[3]);
CreateVehicle(VehicleID, pPosition[0]+15.0, pPosition[1]+15.0, pPosition[2]+2.0, pPosition[3]+90, -1, -1, 5000);
Vehicle[0] = toupper(Vehicle[0]);
format(Message, sizeof(Message), "'%s' spawned.", Vehicle[0]);
SendClientMessage(playerid, ABLUE, Message);
return 1;
}
Re: remove all unoccupied cars spawned with /v command. -
RedJohn - 22.08.2013
Anybody?
Re: remove all unoccupied cars spawned with /v command. -
RajatPawar - 22.08.2013
pawn Код:
stock GetVehicleDriver(vehicleid)
{
for(new i; i<MAX_PLAYERS; i++)
{
if (IsPlayerInVehicle(i, vehicleid))
{
if(GetPlayerState(i) == 2)
{
return i;
}
}
}
return -1;
}
Using this stock
pawn Код:
CMD:v(...)
{
for(new i = 0 ; i < MAX_VEHICLES; i++)
{
if(GetVehicleDriver( i ) == -1)
{
DestroyVehicle( i );
}
}
return 1;
}
You can do the same to get passengers, I'm sure there's a stock for that
Re: remove all unoccupied cars spawned with /v command. -
RedJohn - 24.08.2013
"...remove all unoccupied cars
spawned with /v command..."
That removes every car in my gamemode (those I mapped).
I want it to remove only those which are spawned with /v command.
Re: remove all unoccupied cars spawned with /v command. -
RajatPawar - 24.08.2013
Oh, my bad. Then I guess, assuming you have an enum for players -
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 );
}
}
........
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.)