View Full Version : [HELP]Vehicles Not Destroying

22/03/2015, 09:30 AM
Hey all i have a /bike system , when a player type /bike he gets the Bike/car , but it doesn't destroy , i want something like , when a player spawn a vehicle it must destroy in 5 minutes if no one use it , and if the player spawn another type of bike , the first bike must destroy

Example :

A player spawn BMX , and again he Spawn NRG , then BMX must destroy , And If he didn't spawn any other vehicle then BMX must destroy in 5 minutes when no one used it , Thanks

22/03/2015, 09:37 AM
new pVehicle[ MAX_PLAYERS char ] = { -1, -1, ... }; // defining a new variable and assigning -1 to it(-1 isn't a valid vehicle ID.

// in the command:
if( IsValidVehicle( pVehicle{ playerid } ) ) DestroyVehicle( pVehicle{ playerid } ); // destroying the vehicle if there is any previously spawned by the player.

pVehicle{ playerid } = CreateVehicle( .... ); // assigning the newly created vehicle to the variable

and that's it really..

This function exists within the SA-MP server, but it has not been defined within the include files. To use this function, you must first declare the appropriate native at the top of your script:
'native IsValidVehicle(vehicleid);'. It is recommended you place this under the inclusion of a_samp.inc

22/03/2015, 09:41 AM
Dude i want the server to destroy the Vehicle automatically... after the player spawn a new vehicle , and if he don't then the vehicle must destroy in 5 minutes

22/03/2015, 10:09 AM
Pretty simple, use vehicle callbacks for auto destroying and a player var to store vehicle id.

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;

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.

public OnVehicleSpawn(vehicleid)
for(new i; i < MAX_PLAYERS; ++i)
if(car[i] == vehicleid)//if the car respawns after 5 mins of unuse
return 1;
Now the vehicle will destroy after 5 mins if not used within that time period.

22/03/2015, 10:30 AM
I will try this code ok thanks

22/03/2015, 12:52 PM
Not working