[HELP]Vehicles Not Destroying
#1

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
Reply
#2

pawn Код:
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..

NOTE:
https://sampwiki.blast.hk/wiki/IsValidVehicle
Код:
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
Reply
#3

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
Reply
#4

Pretty simple, use vehicle callbacks for auto destroying and a player var to store vehicle id.
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;
}
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

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;
}
Now the vehicle will destroy after 5 mins if not used within that time period.
Reply
#5

I will try this code ok thanks
Reply
#6

Not working
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)