PDA

View Full Version : Car Spawner Help


TyThaBomb
02/10/2011, 11:04 PM
Well, I made a car spawner, but obviously the cars pile and pile and pile. I was trying to find a way to when they spawn one car it stays, then if they spawn another, the one before it gets destroyed. I'll just show you a snip of it. Any help would be greatly appreciated!:cool:

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp(cmdtext, "/carmenu",true)==0)
{
if(IsPlayerConnected(playerid))
{
if(spawnedcar[playerid] != 0)
{
new scar;
scar= GetPlayerVehicleID(playerid);
RemovePlayerFromVehicle(playerid);
DestroyVehicle(scar);
ShowMenuForPlayer(CarMenu,playerid);
spawnedcar[playerid] = 0;
TogglePlayerControllable(playerid, 0);
}
else if(spawnedcar[playerid] != 1)
{
ShowMenuForPlayer(CarMenu,playerid);
spawnedcar[playerid] = 1;
TogglePlayerControllable(playerid, 0);
}
}
return 1;
}

DIALOG:
public OnPlayerSelectedMenuRow(playerid, row)
{
new Menu:CurrentMenu = GetPlayerMenu(playerid);
new Float:x, Float:y, Float:z, Float:a;
GetPlayerFacingAngle(playerid,a);
GetPlayerPos(playerid, x, y, z);
new car;
if(CurrentMenu == CarMenu)
{
switch(row)
{
case 0: //infernus
{
car=CreateVehicle(411,x,y,z+4,a,-1,-1,30000);
PutPlayerInVehicle(playerid,car,0);
spawnedcar[playerid] = 1;
SendClientMessage(playerid, 0x33CCFFAA, "<| You Have Selected the: Infernus |>");

TogglePlayerControllable(playerid, 1);
}

henry jiggy
02/10/2011, 11:51 PM
When the car spawns, assign its id to a global variable, example.


//OUTSIDE of any function

new PlayerVehicle[MAX_PLAYERS];


//On the vehicle spawn
DestroyVehicle(PlayerVehicle[playerid]);
PlayerVehicle[playerid] = CreateVehicle(411,x,y,z+4,a,-1,-1,30000)
PutPlayerInVehicle(playerid,PlayerVehicle[playerid],0);
spawnedcar[playerid] = 1;

//OnPlayerDisconnect

DestroyVehicle(PlayerVehicle[playerid]);
PlayerVehicle[playerid] = 9999999999999999999999999999;


Just put that propperly on your script with the proper car modelids and you're good to go!