new IsSpawnedVehicle[MAX_PLAYERS];
new VehicleDestroyerTimer;
forward DestroySpawnedVehicle(playerid, vehicleid);
public OnPlayerExitVehicle(playerid, vehicleid)
{
VehicleDestroyerTimer = SetTimer("DestroySpawnedVehicle", 10000, true);
return 1;
}
public DestroySpawnedVehicle(playerid, vehicleid)
{
if(IsSpawnedVehicle[playerid] == 1)
{
new currentvehivle;
currentvehivle = GetPlayerVehicleID(playerid);
DestroyVehicle(currentvehivle);
IsSpawnedVehicle[playerid] = 0;
KillTimer(VehicleDestroyerTimer);
return 1;
}
return 0;
}
SetTimerEx("DestroySpawnedVehicle", 10000, true, "ii", playerid, vehicleid);
Well because you're not passing any information to the function at all, Pawn can't read minds you know!
|
Thanks
Will this only work for id 0? (i looked at Lorenc_ poast =/) |
The code I posted will work for any playerid or vehicleid! You must understand that you're getting the playerid and vehicleid passed by the OnPlayerExitVehicle function, and then passing it from the timer to the other function for destroying the vehicle.
If you do not pass that information, the parameters in your vehicle destruction function will not have anything sent to them, therefore they will default to 0. |
#include <a_samp>
new IsSpawnedVehicle[MAX_PLAYERS];
#define COLOR_ERROR 0xFF303EAA
#define DIALOGID 1
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/vehicles", cmdtext, true, 10) == 0)
{
ShowPlayerDialog(playerid, DIALOGID, DIALOG_STYLE_LIST, "Vehicle Categories", "Airplanes\nHelicopters\nBikes\nConvertibles\nIndustrial\nLowriders\nOff Road\nPublic Service Vehicles\nSaloons\nSport Vehicles\nStation Wagons\nBoats\nUnique Vehicles\nRC Vehicles", "Select", "Cancel");
return 1;
}
else if (strcmp("/aclenup", cmdtext, true, 10) == 0) //Fail
{
if(IsPlayerAdmin(playerid))
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
DestroyVehicle(IsSpawnedVehicle[i]);
SendClientMessage(playerid, 0xFF0000FF, "Info => All vehicles cleaned up!");
return 1;
}
}
return 0;
}
else if (strcmp("/cleanup", cmdtext, true, 10) == 0) //Fail
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
DestroyVehicle(IsSpawnedVehicle[i]);
SendClientMessage(i, 0xFF0000FF, "Info => You cleaned up the vehicles YOU used/uses");
IsSpawnedVehicle[i] = 0;
return 1;
}
return 0;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOGID) // Vehicle Dialog
{
if(!response) return SendClientMessage(playerid, COLOR_ERROR,"Error: You have cancelled.");
{
if(listitem == 0) // Airplanes
{
ShowPlayerDialog(playerid, DIALOGID+1, DIALOG_STYLE_LIST, "Airplanes", "Andromada \nAT-400 \nBeagle \nBack", "Select", "Cancel");
return 1;
}
}
}
else if(dialogid == DIALOGID+1) // Airplanes
{
if(!response) return SendClientMessage(playerid, COLOR_ERROR,"Error: You have cancelled.");
{
if(listitem == 0) // Andromada
{
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X,Y,Z);
GetPlayerFacingAngle(playerid, A);
new vehicleid = CreateVehicle(592, X,Y,Z,A, -1, -1, -1);
PutPlayerInVehicle(playerid, vehicleid, 0);
IsSpawnedVehicle[playerid] = 1;
return 1;
}
else if(listitem == 1) //AT-400
{
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X,Y,Z);
GetPlayerFacingAngle(playerid, A);
new vehicleid = CreateVehicle(577, X,Y,Z,A, -1, -1, -1);
PutPlayerInVehicle(playerid, vehicleid, 0);
IsSpawnedVehicle[playerid] = 1;
return 1;
}
else if(listitem == 2) // Beagle
{
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X,Y,Z);
GetPlayerFacingAngle(playerid, A);
new vehicleid = CreateVehicle(511, X,Y,Z,A, -1, -1, -1);
PutPlayerInVehicle(playerid, vehicleid, 0);
IsSpawnedVehicle[playerid] = 1;
return 1;
}
else if(listitem == 3) // Back
{
ShowPlayerDialog(playerid, DIALOGID, DIALOG_STYLE_LIST, "Vehicle Categories", "Airplanes", "Select", "Cancel");
return 1;
}
}
}
return 0;
}
for(new i = 0; i < MAX_VEHICLES; i++)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
for your vehicle like the remove all vehicles u should use
pawn Код:
pawn Код:
|
else if (strcmp("/acleanup", cmdtext, true, 10) == 0) //Clean up everyones spawned vehicles...
{
if(IsPlayerAdmin(playerid))
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
DestroyVehicle(IsSpawnedVehicle[i] == 1);
SendClientMessage(playerid, 0xFF0000FF, "Info => Everyones vehicles cleaned up!");
IsSpawnedVehicle[playerid] = 0;
return 1;
}
}
return 0;
}
else if (strcmp("/cleanup", cmdtext, true, 10) == 0) //The player who type /cleanup, get HIS vehicles cleaned
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
DestroyVehicle(IsSpawnedVehicle[playerid] == 1);
SendClientMessage(playerid, 0xFF0000FF, "Info => You cleaned up the vehicles YOU used/uses");
IsSpawnedVehicle[playerid] = 0;
return 1;
}
return 0;
}
return 0;
}