Delete spawned cars CMD?
#1

Hello I was wondering how to do a command that would remove all vehicles that are spawned with this command:
Code:
CMD:veh(playerid, params[]) {

	new vehid,vehicle,engine,lights,alarm,doors,bonnet,boot,objective;
	if(PlayerInfo[playerid][pLevel] < 1) return error
	if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh <carid>");
	else if (vehid < 400 || vehid > 611) SendClientMessage(playerid, COLOR_GREY, "[ERROR] Invalid car id! [ Car ID's range from 400 - 611 ]");
	else
	{
		new Float:x, Float:y, Float:z;
		GetPlayerPos(playerid, x, y, z);
		vehicle = CreateVehicle(vehid, x + 3, y, z, 0, 0,0, -1);
		GetVehicleParamsEx(vehid,engine,lights,alarm,doors,bonnet,boot,objective);
		SetVehicleParamsEx(vehid,1,lights,alarm,doors,bonnet,boot,objective);
		ChangeVehicleColor(vehicle, 219, 251);
		SetVehicleNumberPlate(vehicle,"{FF8000}BHaulers");
		PutPlayerInVehicle(playerid,vehicle,0);
		SendClientMessage(playerid, COLOR_GREEN, "Car spawned!");
	}
	return 1;
}
Reply
#2

pawn Code:
new vehToDelete[MAX_VEHICLES] = {-1, ...};

// in your cmd
vehToDelete[vehicle] = CreateVehicle(...)

CMD:deletevehicles(playerid, params[])
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(vehToDelete[i] != -1)
            DestroyVehicle(i);
    }
    return 1;
}
Reply
#3

I'm confused now. Could you edit this for me?
Code:
new vehToDelete[MAX_VEHICLES];
CMD:veh(playerid, params[]) {

	new vehid,vehicle,engine,lights,alarm,doors,bonnet,boot,objective;
	if(PlayerInfo[playerid][pLevel] < 1) return error
	if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh <carid>");
	else if (vehid < 400 || vehid > 611) SendClientMessage(playerid, COLOR_GREY, "[ERROR] Invalid car id! [ Car ID's range from 400 - 611 ]");
	else
	{
		new Float:x, Float:y, Float:z, Float:angle;
		GetPlayerPos(playerid, x, y, z);
		GetPlayerFacingAngle(playerid,angle);
		vehToDelete[vehicle] = CreateVehicle(vehid, x + 3, y, z, angle, 219,251, -1);
		GetVehicleParamsEx(vehid,engine,lights,alarm,doors,bonnet,boot,objective);
		SetVehicleParamsEx(vehid,1,lights,alarm,doors,bonnet,boot,objective);
		SetVehicleNumberPlate(vehToDelete[vehicle],"{FF8000}BHaulers");
		VehicleFuel[vehid] = 100+random(50);
		PutPlayerInVehicle(playerid,vehToDelete[vehicle],0);
		SendClientMessage(playerid, COLOR_GREEN, "Car spawned!");
	}
	return 1;
}

CMD:cleancars(playerid, params[])
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(vehToDelete[i] != -1)
            DestroyVehicle(i);
    }
    return 1;
}
Reply
#4

vehicle is always going to be 0...meaning it's just replacing itself over and over so you'll only ever delete one vehicle
Reply
#5

Quote:
Originally Posted by [ABK]Antonio
View Post
vehicle is always going to be 0...meaning it's just replacing itself over and over so you'll only ever delete one vehicle
so what do I have to do? :/
Reply
#6

Try this:
pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define MAX_Vehicles 100

new vehicles[MAX_Vehicles];
new vehid,vehicle,engine,lights,alarm,doors,bonnet,boot,objective;
CMD:Veh(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"Message");  //your  level checks,colors
else
{
if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, -1, "USAGE: /veh <carid>");
else if (vehid < 400 || vehid > 611) SendClientMessage(playerid, -1, "[ERROR] Invalid car id! [ Car ID's range from 400 - 611 ]");
else
{
new float:x,float:y,float:z,float:a;

GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,a);
new i=0 ;
if(i<Max_vehicles)
{
vehicles[i]=CreateVehicle(vehid,x,y,z,a,random(126),random(126),150000);
GetVehicleParamsEx(vehid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehid,1,lights,alarm,doors,bonnet,boot,objective);
ChangeVehicleColor(vehicle, 219, 251);
SetVehicleNumberPlate(vehicle,"{FF8000}BHaulers");
PutPlayerInVehicle(playerid,vehicle,0);
i++;
}
return SendClientMessage(playerid,-1,"Vehicle Spawned!");  //your  colors
}
return 1;
}
}
CMD:Cleanup(playerid)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"Message");  //your  level checks,colors
else
{
for(new i;i<=count;i++)
{
DestroyVehicle(vehicles[i]);
}
return SendClientMessageToAll(-1,"Spwaned Cars Have Been Cleared"),1;
}
}
PS: You'll get tag mismatch warnings (I haven't changed your variables!)
Reply
#7

Here you go:
You need zcmd include and sscanf(include+plugin)

You check the vehid using /dl
PHP Code:
CMD:delallveh(playeridparams[])
{
    for(new 
0MAX_VEHICLESi++)
    {
        
DestroyVehicle(i);
    }
    return 
1;
}
CMD:delveh(playeridparams[])
{
    new 
vehid;
    if(
sscanf(params"d"vehid)) return SendClientMessage(playerid, -1"USAGE: /delveh [veh]");
    
DestroyVehicle(vehid);
    new 
string[60];
    
format(stringsizeof(string), "Vehicle %d destroyed!"vehid);
    
SendClientMessage(playerid, -1string);
    return 
1;

Reply
#8

Quote:
Originally Posted by ThePhenix
View Post
Here you go:
You need zcmd include and sscanf(include+plugin)

You check the vehid using /dl
PHP Code:
CMD:delallveh(playeridparams[])
{
    for(new 
0MAX_VEHICLESi++)
    {
        
DestroyVehicle(i);
    }
    return 
1;
}
CMD:delveh(playeridparams[])
{
    new 
vehid;
    if(
sscanf(params"d"vehid)) return SendClientMessage(playerid, -1"USAGE: /delveh [veh]");
    
DestroyVehicle(vehid);
    new 
string[60];
    
format(stringsizeof(string), "Vehicle %d destroyed!"vehid);
    
SendClientMessage(playerid, -1string);
    return 
1;

I don't want to delete all vehicles.. Only those that were spawned with /veh.

Any btw kartik your method is awful.. test it and you will see why..
Reply
#9

Quote:
Originally Posted by wumpyc
View Post
I don't want to delete all vehicles.. Only those that were spawned with /veh.

Any btw kartik your method is awful.. test it and you will see why..
Will ONLY delete vehicles with id in the vehicles array ! Updated cause i fucked up !
seems to be working !
EDIT: works with dcmd, strcmp,mcmd
IDK why its not working with zcmd...see if i did return 1 inside an if statement ..if so delete it
EDIT : both returns are inside if statements so no further action is taken ! updating !
Reply
#10

Quote:
Originally Posted by ThePhenix
View Post
What about using foreach - ******?
Iter_Add??
if i knew how to use it i would
Quote:
Originally Posted by kartik
View Post
Will ONLY delete vehicles with id in the vehicles array ! Updated cause i fucked up !
this will spawn way too much vehicles:
Code:
for(new i; i<MAX_Vehicles;i++)
{
vehicles[i]=CreateVehicle(vehid,x,y,z,a,random(126),random(126),150000);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)