Okay, I made a function. I tested it shortly and it worked.
You should add the "ShopCarSpawner" function at every case where you want the car to be removed after its explosion.
pawn Код:
new csp;
#define FILTERSCRIPT
#define COLOR_RED 0xFF0000AA
#define COLOR_GREEN 0x00FF00AA
#define COLOR_BLUE 0x0000FFAA
#define COLOR_YELLOW 0xFFFF00AA
#define CarMenuID 3745
#define FastCars 3746
#define Bikes 3747
#define Boats 3748
#define Planes 3749
#define MAX_SHOP_CARS 2000
#include <a_samp>
#if defined FILTERSCRIPT
new ShopCar[MAX_SHOP_CARS];
new ShopCarExists[MAX_SHOP_CARS];
public OnFilterScriptInit()
{
csp = CreatePickup(1318, 23, -1975.4729,289.0419,35.1719,-1);
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
}
#endif
public OnPlayerRequestClass(playerid, classid)
{
return 1;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
for(new i=0; i<MAX_SHOP_CARS; i++)
{
if(vehicleid==ShopCar[i])
{
SetTimerEx("ResetCar", 5000, 0,"d", vehicleid); // We make this, that the vehicle will explode before getting deleted.
return 1;
}
}
return 1;
}
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
DestroyVehicle(vehicleid);
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/carmenu", true))
{
ShowPlayerDialog(playerid, CarMenuID, DIALOG_STYLE_LIST, "Car buy shop", "Premier ($1000)\nInfernus ($9500)\nStafford ($2555)", "Buy car", "Quit");
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
if(pickupid == csp)
ShowPlayerDialog(playerid, CarMenuID, DIALOG_STYLE_LIST, "Wang Cars Carshop", "Fast Cars\nBikes\nBoats\nPlanes", "Select genre", "Quit");
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new Float: x;
new Float: y;
new Float: z;
// We SHOULD use switch(dialogid) with cases, but we're only going to use one dialog in this tutorial.
if(dialogid == CarMenuID && response) // If the dialogid is 1 (our dialog) and they pressed 'Purchase'
{
// We'll use the switch/cases now because we're going to process a few results, not just one. Remember, the first item in the list has id 0.
switch(listitem)
{
case 0:
{
ShowPlayerDialog(playerid, FastCars, DIALOG_STYLE_LIST, "Wang Cars Carshop", "Jester\nInfernus\nEuros\nBullet", "Select genre", "Quit");
return SendClientMessage(playerid, COLOR_YELLOW, "You selected 'Fast Cars");
}
case 1:
{
if(GetPlayerMoney(playerid) < 9500) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
GivePlayerMoney(playerid, -9500);
PutPlayerInVehicle(playerid,411,0);
}
case 2:
{
if(GetPlayerMoney(playerid) < 2555) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
GivePlayerMoney(playerid, -2555);
PutPlayerInVehicle(playerid,580,0);
}
}
return 1;
}
if(dialogid == FastCars && response) // If the dialogid is 1 (our dialog) and they pressed 'Purchase'
{
// We'll use the switch/cases now because we're going to process a few results, not just one. Remember, the first item in the list has id 0.
switch(listitem)
{
case 0:
{
if(GetPlayerMoney(playerid) < 50000) return SendClientMessage(playerid,COLOR_RED,"You don't have $50000!");
GivePlayerMoney(playerid,-50000);
ShopCarSpawner(playerid,559); //The magic function.
return SendClientMessage(playerid, COLOR_YELLOW, "You bought a Jester!");
}
case 1:
{
ShopCarSpawner(playerid,411);
GivePlayerMoney(playerid,-50500);
return SendClientMessage(playerid, COLOR_YELLOW, "You bought an Infernus!");
}
case 2:
{
GetPlayerPos(playerid,x,y,z);
GivePlayerMoney(playerid,-34000);
CreateVehicle(587,x+2,y+2,z+2,0,0,0,0);
return SendClientMessage(playerid, COLOR_YELLOW, "You bought an Euros!");
}
case 3:
{
GetPlayerPos(playerid,x,y,z);
GivePlayerMoney(playerid,-45005);
CreateVehicle(541,x+2,y+2,z+2,0,0,0,0);
return SendClientMessage(playerid, COLOR_YELLOW, "You bought a Bullet!");
}
}
}
return 1;
}
forward ShopCarSpawner(playerid, vehicleid);
public ShopCarSpawner(playerid, vehicleid)
{
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid, a);
for(new i=0; i<MAX_SHOP_CARS; i++)
{
if(ShopCarExists[i]!=1)
{
ShopCar[i]=CreateVehicle(vehicleid,x,y,z,a,-1,-1,-1);
ShopCarExists[i]=1;
PutPlayerInVehicle(playerid, ShopCar[i],0);
return 1;
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
Try it if it works for you.
Would be nice if you tell me if it works.