SA-MP Forums Archive
Vehicle auto respawn with SetTimer? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicle auto respawn with SetTimer? (/showthread.php?tid=205431)



Vehicle auto respawn with SetTimer? - Hudgens - 01.01.2011

I haven't figured out how to make all server vehicles respawn with SetTimer and function?
Can anyone here explain ?


Re: Vehicle auto respawn with SetTimer? - Grim_ - 01.01.2011

pawn Код:
// Somewhere, like in a command
SetTimer( "RespawnVehicles", 5000, false ); // Change '5000' to make a different delay

// After main( )
forward RespawnVehicles( );
public RespawnVehicles( )
{
   for( new i = 0; i < MAX_VEHICLES; i ++ )
   {
      SetVehicleToRespawn( i );
   }
}



Re: Vehicle auto respawn with SetTimer? - Hudgens - 01.01.2011

Thank you =).


Re: Vehicle auto respawn with SetTimer? - Hudgens - 01.01.2011

Well it is working, anyhow...
I don't want the car you're using to respawn if you're in it, as they do. Is it possible to only make the cars respawn if they are empty and moved out of spawn point?


Re: Vehicle auto respawn with SetTimer? - Grim_ - 01.01.2011

Just check if a player is in the current vehicle before respawning it.


Re: Vehicle auto respawn with SetTimer? - Hudgens - 01.01.2011

Sorry but I don't understand. Do you mean via command nor function?


Re: Vehicle auto respawn with SetTimer? - blackwave - 01.01.2011

pawn Код:
// Somewhere, like in a command
SetTimer( "RespawnVehicles", 5000, false ); // Change '5000' to make a different delay

// After main( )
forward RespawnVehicles( );
public RespawnVehicles( )
{
   for( new i = 0; i < MAX_VEHICLES; i ++ )
   {
      if(!IsPlayerInAnyVehicle(i))
    {
      SetVehicleToRespawn( i );
}
   }
}



Re: Vehicle auto respawn with SetTimer? - Grim_ - 01.01.2011

blackwave, that code will not work, the following is what you are looking for (still untested)
pawn Код:
// Somewhere, like in a command
SetTimer( "RespawnVehicles", 5000, false ); // Change '5000' to make a different delay

// After main( )
forward RespawnVehicles( );
public RespawnVehicles( )
{
   new vehicles[ MAX_VEHICLES ];
   for( new i = 0; i < MAX_PLAYERS; i ++ )
   {
      if( IsPlayerInAnyVehicle( i ) )
      {
         vehicles[ GetPlayerVehicleID( i ) ] = 1;
      }
   }

   for( new v = 0; v < MAX_VEHICLES; v ++ )
   {
      if( vehicles[ v ] == 1 ) continue;
      SetVehicleToRespawn( v );
   }
   return 1;
}
I can't think of a better way at approaching this at the time.