How to delete cars/vehicles? +REP!
#1

Here is my code for spawning vehicles:

Код:
//Vehicle Spawner
#include 				<a_samp>
#include 				<zcmd>
#include                <sscanf2>

//Defines
#define USE_ADMIN   	true // if true, you need to be admin to do this

//Define Colors
#define C_RED      		0xFF0000FF
#define C_GREEN     	0x00FF00FF

//Vehicle Names
new aVehicleNames[212][] =
{
	{"Landstalker"},{"Bravura"},{"Buffalo"},{"Linerunner"},{"Perrenial"},{"Sentinel"},{"Dumper"},{"Firetruck"},{"Trashmaster"},{"Stretch"},
	{"Manana"},{"Infernus"},{"Voodoo"},{"Pony"},{"Mule"},{"Cheetah"},{"Ambulance"},{"Leviathan"},{"Moonbeam"},{"Esperanto"},{"Taxi"},
	{"Washington"},{"Bobcat"},{"Mr Whoopee"},{"BF Injection"},{"Hunter"},{"Premier"},{"Enforcer"},{"Securicar"},{"Banshee"},{"Predator"},{"Bus"},
	{"Rhino"},{"Barracks"},{"Hotknife"},{"Trailer 1"},{"Previon"},{"Coach"},{"Cabbie"},{"Stallion"},{"Rumpo"},{"RC Bandit"},{"Romero"},{"Packer"},
	{"Monster"},{"Admiral"},{"Squalo"},{"Seasparrow"},{"Pizzaboy"},{"Tram"},{"Trailer 2"},{"Turismo"},{"Speeder"},{"Reefer"},{"Tropic"},{"Flatbed"},
	{"Yankee"},{"Caddy"},{"Solair"},{"Berkley's RC Van"},{"Skimmer"},{"PCJ-600"},{"Faggio"},{"Freeway"},{"RC Baron"},{"RC Raider"},{"Glendale"},{"Oceanic"},
	{"Sanchez"},{"Sparrow"},{"Patriot"},{"Quad"},{"Coastguard"},{"Dinghy"},{"Hermes"},{"Sabre"},{"Rustler"},{"ZR-350"},{"Walton"},{"Regina"},{"Comet"},
	{"BMX"},{"Burrito"},{"Camper"},{"Marquis"},{"Baggage"},{"Dozer"},{"Maverick"},{"News Chopper"},{"Rancher"},{"FBI Rancher"},{"Virgo"},{"Greenwood"},
	{"Jetmax"},{"Hotring"},{"Sandking"},{"Blista Compact"},{"Police Maverick"},{"Boxville"},{"Benson"},{"Mesa"},{"RC Goblin"},{"Hotring Racer A"},
	{"Hotring Racer B"},{"Bloodring Banger"},{"Rancher"},{"Super GT"},{"Elegant"},{"Journey"},{"Bike"},{"Mountain Bike"},{"Beagle"},{"Cropdust"},{"Stunt"},
	{"Tanker"},{"Roadtrain"},{"Nebula"},{"Majestic"},{"Buccaneer"},{"Shamal"},{"Hydra"},{"FCR-900"},{"NRG-500"},{"HPV1000"},{"Cement Truck"},{"Tow Truck"},
	{"Fortune"},{"Cadrona"},{"FBI Truck"},{"Willard"},{"Forklift"},{"Tractor"},{"Combine"},{"Feltzer"},{"Remington"},{"Slamvan"},{"Blade"},{"Freight"},
	{"Streak"},{"Vortex"},{"Vincent"},{"Bullet"},{"Clover"},{"Sadler"},{"Firetruck LA"},{"Hustler"},{"Intruder"},{"Primo"},{"Cargobob"},{"Tampa"},{"Sunrise"},{"Merit"},
	{"Utility"},{"Nevada"},{"Yosemite"},{"Windsor"},{"Monster A"},{"Monster B"},{"Uranus"},{"Jester"},{"Sultan"},{"Stratum"},{"Elegy"},{"Raindance"},{"RC Tiger"},
	{"Flash"},{"Tahoma"},{"Savanna"},{"Bandito"},{"Freight Flat"},{"Streak Carriage"},{"Kart"},{"Mower"},{"Duneride"},{"Sweeper"},{"Broadway"},{"Tornado"},{"AT-400"},
	{"DFT-30"},{"Huntley"},{"Stafford"},{"BF-400"},{"Newsvan"},{"Tug"},{"Trailer 3"},{"Emperor"},{"Wayfarer"},{"Euros"},{"Hotdog"},{"Club"},{"Freight Carriage"},
	{"Trailer 3"},{"Andromada"},{"Dodo"},{"RC Cam"},{"Launch"},{"Police Car (LSPD)"},{"Police Car (SFPD)"},{"Police Car (LVPD)"},{"Police Ranger"},{"Picador"},{"S.W.A.T. Van"},
	{"Alpha"},{"Phoenix"},{"Glendale"},{"Sadler"},{"Luggage Trailer A"},{"Luggage Trailer B"},{"Stair Trailer"},{"Boxville"},{"Farm Plow"},{"Utility Trailer"}
};

//Commands / Spawn Vehicles
COMMAND:v(playerid, params[])
{
	#if USE_ADMIN == true
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, C_RED, " ** This command will be added to this server soon. For now, try /cmds . ");
	#endif
	new Vehicle[50];
	if(!sscanf(params, "s[50]", Vehicle))
	{
		new string[128], Float:Pos[4];
		GetPlayerPos(playerid, Pos[0],Pos[1],Pos[2]); GetPlayerFacingAngle(playerid, Pos[3]);
		new veh = GetVehicleModelID(Vehicle);
		if(veh < 400 || veh > 611) return SendClientMessage(playerid, C_RED, " ** This is not a valid vehicle name! Please try again ");
		if(IsPlayerInAnyVehicle(playerid)) { DestroyVehicle(GetPlayerVehicleID(playerid)); }
		GetXYInFrontOfPlayer(playerid, Pos[0], Pos[1], 5);
		new PVeh = CreateVehicle(veh, Pos[0], Pos[1], Pos[2], Pos[3]+90, -1, -1, -1);
		LinkVehicleToInterior(PVeh, GetPlayerInterior(playerid)); SetVehicleVirtualWorld(PVeh, GetPlayerVirtualWorld(playerid));
		format(string, sizeof string, " ** You spawned a %s. ID: %i. ", aVehicleNames[veh - 400], veh);
  		SendClientMessage(playerid, C_GREEN, string);
	} else return SendClientMessage(playerid, C_GREEN, " ** Usage: /v [vehiclename] ");
	return 1;
}

//Command Help
COMMAND:spawnhelp(playerid, cmdtext[])
{
	SendClientMessage(playerid, C_GREEN, " -|_|- Vehicle spawn help -|_|- ");
	SendClientMessage(playerid, C_RED, " - /v [vehiclename] > Spawns a vehicle of your choice ");
	SendClientMessage(playerid, C_RED, " - /vnames > Gives you a link where to check the vehicle names ");
	return 1;
}

//Vehicle Names Help
COMMAND:vnames(playerid, cmdtext[])
				return SendClientMessage(playerid, C_GREEN, " ** Please visit \"https://sampwiki.blast.hk/wiki/Vehicle_Model_ID_List\" for all the vehicle names!");

//Stocks - Do NOT Edit ... Ignore
stock GetVehicleModelID(vehiclename[])
{
	for(new i = 0; i < 211; i++)
	{
		if(strfind(aVehicleNames[i], vehiclename, true) != -1)
		return i + 400;
	}
	return -1;
}

stock GetXYInFrontOfPlayer(playerid, &Float:x2, &Float:y2, Float:distance)
{
	new Float:a;

	GetPlayerPos(playerid, x2, y2, a);
	GetPlayerFacingAngle(playerid, a);

	if(GetPlayerVehicleID(playerid))
	{
		GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
	}

	x2 += (distance * floatsin(-a, degrees));
	y2 += (distance * floatcos(-a, degrees));
}
After I spawn them and for example I spawn too many, I need to delete them. And is there a way to delete them? And also after I blow one car up, it will respawn in the same place I spawned them. Is there a way to let them NOT respawn? Thanks
Reply
#2

For deleting vehicles , Use the function :
pawn Код:
new VehicleID[MAX_PLAYERS];

DestroyVehicle(VehicleID[playerid]);
Reply
#3

Quote:
Originally Posted by .FuneraL.
Посмотреть сообщение
For deleting vehicles , Use the function :
pawn Код:
new VehicleID[MAX_PLAYERS];

DestroyVehicle(VehicleID[playerid]);
Okay and what do I do ingame to delete the vehicles? Anything to type in for example /destroycar or /destroyv?
Reply
#4

Quote:
Originally Posted by TheMightyEddy
Посмотреть сообщение
Okay and what do I do ingame to delete the vehicles? Anything to type in for example /destroycar or /destroyv?
Yes. Use this code example :

pawn Код:
if(strcmp("/destroyv", cmdtext, true) == 0)
{
     new pName[MAX_PLAYER_NAME];
     new string[256]
     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
     format(string, sizeof(string), "[Information]: %s has Destroyed one Vehicle!", pName);
     SendClientMessageToAll(0xFFFFFFFF, string);
     DestroyVehicle(VehicleID[playerid]);
     return 1;
}
Reply
#5

Quote:
Originally Posted by .FuneraL.
Посмотреть сообщение
Yes. Use this code example :

pawn Код:
if(strcmp("/destroyv", cmdtext, true) == 0)
{
     new pName[MAX_PLAYER_NAME];
     new string[256]
     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
     format(string, sizeof(string), "[Information]: %s has Destroyed one Vehicle!", pName);
     SendClientMessageToAll(0xFFFFFFFF, string);
     DestroyVehicle(VehicleID[playerid]);
     return 1;
}
Thank you but I don't think it works for ZCMD.
Reply
#6

It would work. just convert strcmp to zcmd.
Reply
#7

Quote:
Originally Posted by Reklez
Посмотреть сообщение
It would work. just convert strcmp to zcmd.
Can you please do that for me? I can't find how...
Reply
#8

*sight*

pawn Код:
COMMAND:destroyv(playerid, params[])
{
     new pName[MAX_PLAYER_NAME];
     new string[256]
     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
     format(string, sizeof(string), "[Information]: %s has Destroyed one Vehicle!", pName);
     SendClientMessageToAll(0xFFFFFFFF, string);
     DestroyVehicle(VehicleID[playerid]);
     return 1;
}
Reply
#9

Thanks so much but I get these errors:

Код:
error 001: expected token: ";", but found "-identifier-"
error 017: undefined symbol "VehicleID"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
Reply
#10

pawn Код:
new VehicleID[MAX_PLAYERS];
add that at the top of script after #include, then on your spawn vehicle command add this

pawn Код:
VehicleID[playerid] = PVeh;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)