Respawn unused vehicles automaticaly
#1

Here is the code,

PHP код:
#define RESPAWN_TIME 20 // Twenty minutes
 
public OnGameModeInit() {
     
SetTimer("VehicleRespawn"RESPAWN_TIME 600001);
     return 
1;
}
 
forward VehicleRespawn();
public 
VehicleRespawn() {
    for(new 
0MAX_VEHICLES++ ) {
         for(new 
0GetMaxPlayers(); ++ ) {
              if(!
IsPlayerConnected(o)) continue;
              if(
IsAnyBodyInVehicle(i)) continue;
              
SetVehicleToRespawn(i);
         }
    }
    return 
1;
}
 
stock IsAnyBodyInVehicle(vid) {
  for(new 
0GetMaxPlayers(); ++ ) {
       if(
IsPlayerInVehicle(ivid)) return 1;
  }
  return 
0;

My problem:

When it respawns the vehicles it respawns trailers that are being used at the moment and connected to a truck.Can someone help me out with this? PLEASE !!!

P.S Dont give me any thread links...
Reply
#2

Here you go, this is from my personal script. You will have to modify it tho, change of variables.. change foreach if you don't use foreach or just take my concept and script your own (you should do this).

pawn Код:
respawnAllVehicles()
{
    new bool:vehicleActivityStatus[MAX_VEHICLES] = {false, ...}, pCurVehicleID = INVALID_VEHICLE_ID;
    foreach(new i : Character)
    {
        if(IsPlayerInAnyVehicle(i)) {
            pCurVehicleID = GetPlayerVehicleID(i);
        }
        else if(playerData[i][pCurrentVehicleDrivenID] != INVALID_VEHICLE_ID) {
            pCurVehicleID = playerData[i][pCurrentVehicleDrivenID];
        }
        if(pCurVehicleID != INVALID_VEHICLE_ID) {
            vehicleActivityStatus[pCurVehicleID] = true;
        }  
        if(IsTrailerAttachedToVehicle(pCurVehicleID)) {
            vehicleActivityStatus[GetVehicleTrailer(pCurVehicleID)] = true;
        }
        pCurVehicleID = INVALID_VEHICLE_ID;
    }
    for(new i = 0; i < MAX_VEHICLES; ++i) {
        if(vehicleActivityStatus[i] == false) {
            SetVehicleToRespawn(i);
        }
    }
}
Reply
#3

Thanks man,btw love your profile picture,the best game on PS2 :P
Reply
#4

Just for the record: AddStaticVehicleEx and CreateVehicle have a "respawn" parameter that is intended for this exact purpose.
Reply
#5

That's if the vehicle has actually been entered. Sometimes a manual respawn is necessary.
Reply
#6

Help??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)