SA-MP Forums Archive
Delete spawned cars CMD? - 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)
+--- Thread: Delete spawned cars CMD? (/showthread.php?tid=453711)



Delete spawned cars CMD? - wumpyc - 26.07.2013

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



Re: Delete spawned cars CMD? - -Prodigy- - 26.07.2013

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



Re: Delete spawned cars CMD? - wumpyc - 26.07.2013

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



Re: Delete spawned cars CMD? - [ABK]Antonio - 26.07.2013

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


Re: Delete spawned cars CMD? - wumpyc - 26.07.2013

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? :/


Re: Delete spawned cars CMD? - kartik - 26.07.2013

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


Re: Delete spawned cars CMD? - ThePhenix - 26.07.2013

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;




Re: Delete spawned cars CMD? - wumpyc - 26.07.2013

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..


Re: Delete spawned cars CMD? - kartik - 26.07.2013

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 !


Re: Delete spawned cars CMD? - wumpyc - 26.07.2013

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