22.03.2015, 10:09
Pretty simple, use vehicle callbacks for auto destroying and a player var to store vehicle id.
Now the vehicle will destroy if the player spawns a new one. Read the link in prevous post.
For destroying the vehicle after 5 minutes, we would not use timers, a smarter way is to utilize respawn_delay of a vehicle. Set it to 5 mins when creating a vehicle in the command.
https://sampwiki.blast.hk/wiki/CreateVehicle
Now the vehicle will destroy after 5 mins if not used within that time period.
pawn Код:
new car[MAX_PLAYERS];
//for example you have the cmd bike
CMD:bike(playerid, params[])
{
if(IsValidVehicle(car[playerid])) DestroyVehicle(car[playerid]);//destroy the previous veh if exist
car[playerid] = CreateVehicle(...);//create the neŵ veh and store in car var
return 1;
}
For destroying the vehicle after 5 minutes, we would not use timers, a smarter way is to utilize respawn_delay of a vehicle. Set it to 5 mins when creating a vehicle in the command.
https://sampwiki.blast.hk/wiki/CreateVehicle
pawn Код:
public OnVehicleSpawn(vehicleid)
{
for(new i; i < MAX_PLAYERS; ++i)
{
if(IsPlayerConnected(i))
{
if(car[i] == vehicleid)//if the car respawns after 5 mins of unuse
{
DestroyVehicle(car[i]);
break;
}
}
}
return 1;
}