Destroy cars command
#1

Im having a little problem creating this destroycreatedcars cmd.
I want it to Destroy all vehicles above ID 348(thats ID of new cars spawned by admins), but it dosent work at all
Can anyone give me a little help to solve my little problem?

if(strcmp(cmd, "/destroycreatedcars", true) == 0)
{
if(PlayerInfo[playerid][pAdmin] >=
{
new cardid= GetPlayerVehicleID(playerid);
new spawnedcar = carid >=348;
DestroyVehicle(spawnedcar);
return 1;
}

}
Reply
#2

This will destroy all vehicles with higher ID than 348(starting from ID 349):
pawn Код:
new carid = 348;
while(IsVehicleConnected(++carid)) DestroyVehicle(carid);
pawn Код:
IsVehicleConnected(vehicleid)
{
  new Float:x, Float:y, Float:z;
  GetVehiclePos(vehicleid, x, y, z);
  if(x == 0.0 && y == 0.0 && z == 0.0) return 0;
  return 1;
}
Reply
#3

Exactly where do i put it?
I tried many things but i didnt figure it out.
Reply
#4

The easiest way:
Код:
if(strcmp(cmd, "/destroycreatedcars", true) == 0)
  {
   if(PlayerInfo[playerid][pAdmin] >=8)
   {
     for(new x=349;x<MAX_VEHICLES;x++)if(IsVehicleConnected(x)) DestroyVehicle(x);
             return 1;
   }

  }
Код:
stock IsVehicleConnected(vehicleid) // Mастерминд
{
  new Float:x, Float:y, Float:z;
  GetVehiclePos(vehicleid, x, y, z);
  if(x == 0.0 && y == 0.0 && z == 0.0) return 0;
  return 1;
}
Reply
#5

I get an error on compile
error 029: invalid expression, assumed zero

Its on this line:
for(new x=348;IsVehicleConnected(x);<++) DestroyVehicle(x);
Reply
#6

EDIT:
Код:
if(strcmp(cmd, "/destroycreatedcars", true) == 0)
  {
   if(PlayerInfo[playerid][pAdmin] >=8)
   {
     for(new x=348;x<378;x++)DestroyVehicle(x);
             return 1;
   }

  }
Reply
#7

IsVehicleConnected is stupid, just use GetVehicleModel.

And DestroyVehicle has a check in it to see if the vehicle exists or not, so you can just delete vehicle 349 to 2000 without concern.
Reply
#8

Ok, im not planning to spawn to many cars.
I want it to destroycars ID 348 to like 378. 30 vehicles is enough.
Reply
#9

Quote:
Originally Posted by Joe Staff
IsVehicleConnected is stupid.
I didnt make that function, I copied it somewhere from useful functions..

This is more efficient than the one I posted before. It destroys all vehicles after id 348 and stops after first non-existing vehicle:
pawn Код:
new Float:x, Float:y, Float:z, carid = 348;
while(GetVehiclePos(++carid, x, y, z)) DestroyVehicle(carid);
But if theres still an existing vehicles after the non-existing vehicle, they wont get destroyed. It may only happen if some vehicle
gets destroyed and there are still vehicles with higher id than the destroyed vehicle, so you may wanna loop through all vehicles..

EDIT:
Quote:
Originally Posted by Joe Staff
just use GetVehicleModel.
..this is even more efficient than the one above:
pawn Код:
new carid = 348;
while(GetVehicleModel(++carid)) DestroyVehicle(carid);
Reply
#10

Quote:
Originally Posted by Mастерминд
Quote:
Originally Posted by Joe Staff
IsVehicleConnected is stupid.
I didnt make that function, I copied it somewhere from useful functions..

This is more efficient than the one I posted before. It destroys all vehicles after id 348 and stops after first non-existing vehicle:
pawn Код:
new Float:x, Float:y, Float:z, carid = 348;
while(GetVehiclePos(++carid, x, y, z)) DestroyVehicle(carid);
But if theres still an existing vehicles after the non-existing vehicle, they wont get destroyed. It may only happen if some vehicle
gets destroyed and there are still vehicles with higher id than the destroyed vehicle, so you may wanna loop through all vehicles..

EDIT:
Quote:
Originally Posted by Joe Staff
just use GetVehicleModel.
..this is even more efficient than the one above
pawn Код:
new carid = 348;
while(GetVehicleModel(++carid)) DestroyVehicle(carid);
Quote:
Originally Posted by Joe Staff
And DestroyVehicle has a check in it to see if the vehicle exists or not, so you can just delete vehicle 349 to 2000 without concern.
pawn Код:
for(new carid = 348; DestroyVehicle(carid++); ) {}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)