Need help with clearing vehicles spawned trough /v -
Gozerr - 18.05.2009
Ok, i made a little /v command:
Код:
dcmd_v(playerid, params[])
{
new vid;
if(IsPlayerAdmin(playerid) || VIPLoggedIn[playerid] == 1)
{
if (sscanf(params, "d", vid)) SendClientMessage(playerid, COLOR_YELLOW, "Usage: /v [id]");
else
if (vid < 400 || vid > 611)
{
SendClientMessage(playerid, COLOR_RED, "Invalid Vehicle ID!");
}
else
{
GetPlayerPos(playerid, PlayerPosX[playerid], PlayerPosY[playerid], PlayerPosZ[playerid]);
GetPlayerFacingAngle(playerid, PlayerPosA[playerid]);
PlayerPosInterior[playerid]=GetPlayerInterior(playerid);
veh=CreateVehicle(vid, PlayerPosX[playerid], PlayerPosY[playerid],PlayerPosZ[playerid], PlayerPosA[playerid], 0, 0, never);
LinkVehicleToInterior(veh, PlayerPosInterior[playerid]);
PutPlayerInVehicle(playerid, veh, 0);
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "Admins/VIP only!");
}
return 1;
}
This works fine. (Yes, 'never' is a custom define)
Then i made this command, to clear all the vehicles spawned with /v:
Код:
dcmd_clearspawnedvehicles(playerid, params[])
{
#pragma unused params
if(IsPlayerAdmin(playerid))
{
DestroyVehicle(veh);
SendClientMessage(playerid, COLOR_RED, "Vehicles cleared!");
}
else
{
SendClientMessage(playerid, COLOR_RED, "Admins only!");
}
return 1;
}
But with this, only the last spawned vehicle is cleared.
Is there a way to do this? Do I need to give every spawned vehicle a unique name?
Thanks, Gozerr
Re: Need help with clearing vehicles spawned trough /v -
Weirdosport - 18.05.2009
pawn Код:
// top of script
new Spawned;
new SpawnedVehs[MAX_VEHICLES];
// in the script
SpawnedVehs[Spawned] = CreateVehicle(blah blah);
Spawned++;
//in the destroy script
for(new i=0; i< Spawned; i++)
{
DestroyVehicle(SpawnedVehs[i]);
}
This should work, good luck.
Re: Need help with clearing vehicles spawned trough /v -
Gozerr - 18.05.2009
Thanks for the quick reply! Ill test it now.
Re: Need help with clearing vehicles spawned trough /v -
Weirdosport - 18.05.2009
Ooops, also in the Destroy script after the vehicles have been destroyed you need:
pawn Код:
Spawned = 0;
SpawnedVehs = {0,...};
Let me just check the "..." bit...
EDIT: It doesn't work, it makes a compile error... I don't know how to fix this, but I know when you're setting it in the first place you can do this:
new Variable[MAX_PLAYERS] = {4,...};
Re: Need help with clearing vehicles spawned trough /v -
Joe Staff - 18.05.2009
pawn Код:
// top of script
new Spawned;
new SpawnedVehs[MAX_VEHICLES];
// in the script
SpawnedVehs[Spawned] = CreateVehicle(blah blah);
Spawned++;
//in the destroy script
for(new i=0; i< Spawned; i++)
{
DestroyVehicle(SpawnedVehs[i]);
SpawnedVehs[i]=0;
}
Spawned=0;
Using Weirdo's example, that should work
Re: Need help with clearing vehicles spawned trough /v -
Weirdosport - 18.05.2009
Duhh, I was thinking about using a loop, but must've forgotten there already was one /fail - thanks..