SA-MP Forums Archive
Destroy cars command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Destroy cars command (/showthread.php?tid=143295)



Destroy cars command - Richie - 22.04.2010

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;
}

}


Re: Destroy cars command - M4S7ERMIND - 22.04.2010

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;
}



Re: Destroy cars command - Richie - 22.04.2010

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


Re: Destroy cars command - GTAguillaume - 22.04.2010

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;
}



Re: Destroy cars command - Richie - 22.04.2010

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

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


Re: Destroy cars command - GTAguillaume - 22.04.2010

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

  }



Re: Destroy cars command - Joe Staff - 22.04.2010

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.


Re: Destroy cars command - Richie - 22.04.2010

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


Re: Destroy cars command - M4S7ERMIND - 22.04.2010

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);



Re: Destroy cars command - Nero_3D - 22.04.2010

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++); ) {}