SA-MP Forums Archive
Automatic Vehicle Respawn Problem - 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)
+--- Thread: Automatic Vehicle Respawn Problem (/showthread.php?tid=608498)



Automatic Vehicle Respawn Problem - xxxSpeedxxx - 01.06.2016

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.I need the script to check if the trailer is connected to a truck,if not respawn it,if yes no respawn.I have no idea how to make this.Can someone help me out with this? PLEASE !!! I need this really bad on my server! I'will rep+1 anyone who helps me out with this...


Re: Automatic Vehicle Respawn Problem - BR3TT - 01.06.2016

I'd say you should use this function to check if the trailer is connected, if so then run what you want it to, https://sampwiki.blast.hk/wiki/IsTrailerAttachedToVehicle


Re: Automatic Vehicle Respawn Problem - Jefff - 02.06.2016

https://sampforum.blast.hk/showthread.php?tid=594273
my post


Re: Automatic Vehicle Respawn Problem - Sew_Sumi - 02.06.2016

Yea, you're going to need to make some vehicle tracking variables, and do your check better.

With the MAX_VEHICLES and MAX_PLAYERS, you're doing 1000 checks on 2000 vehicles.


Re: Automatic Vehicle Respawn Problem - Micko123 - 02.06.2016

Trairels are treated like vehicles, but there is no driver in it so server recognize it as empty vehicle and sends it to respawn. Use https://sampwiki.blast.hk/wiki/IsTrailerAttachedToVehicle like BR3TT said and it should do the job . Learn it


Re: Automatic Vehicle Respawn Problem - Nin9r - 02.06.2016

Код HTML:
forward VehicleRespawn(playerid);
public VehicleRespawn(playerid)
{
      foreach(Player, player)
      {
      if(!IsVehicleOccupied(player)) SetVehicleToRespawnEx(player);
      }
      for(new car = 0; car <= MAX_VEHICLES; car++)
      {
          if(!IsVehicleOccupied(car) && !IsATrailer(car)) SetVehicleVirtualWorld(car, 1);

      }
      return 1;
}


stock IsATrailer(vehicleid) {
	switch(GetVehicleModel(vehicleid)) {
		case 435, 450, 584, 591: return 1;
	}
	return 0;
}
Now, the trailers won't be respawned.


Re: Automatic Vehicle Respawn Problem - xxxSpeedxxx - 02.06.2016

Quote:
Originally Posted by Nin9r
Посмотреть сообщение
Код HTML:
forward VehicleRespawn(playerid);
public VehicleRespawn(playerid)
{
      foreach(Player, player)
      {
      if(!IsVehicleOccupied(player)) SetVehicleToRespawnEx(player);
      }
      for(new car = 0; car <= MAX_VEHICLES; car++)
      {
          if(!IsVehicleOccupied(car) && !IsATrailer(car)) SetVehicleVirtualWorld(car, 1);

      }
      return 1;
}


stock IsATrailer(vehicleid) {
	switch(GetVehicleModel(vehicleid)) {
		case 435, 450, 584, 591: return 1;
	}
	return 0;
}
Now, the trailers won't be respawned.
Код:
D:\srw\gamemodes\NG.pwn(214) : error 017: undefined symbol "IsVehicleOccupied"
D:\srw\gamemodes\NG.pwn(214) : error 017: undefined symbol "SetVehicleToRespawnEx"
D:\srw\gamemodes\NG.pwn(218) : error 017: undefined symbol "IsVehicleOccupied"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.



Re: Automatic Vehicle Respawn Problem - Dayrion - 02.06.2016

Quote:
Originally Posted by xxxSpeedxxx
Посмотреть сообщение
Код:
D:\srw\gamemodes\NG.pwn(214) : error 017: undefined symbol "IsVehicleOccupied"
D:\srw\gamemodes\NG.pwn(214) : error 017: undefined symbol "SetVehicleToRespawnEx"
D:\srw\gamemodes\NG.pwn(218) : error 017: undefined symbol "IsVehicleOccupied"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Because you haven't function called IsVehicleOccupied - SetVehicleToRespawnEx - IsVehicleOccupied ...
Before copy/paste, you should understand the code.