SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   Respawn vehicles (https://forum.sa-mp.com/showthread.php?t=665764)

Koreadars 15/04/2019 09:49 AM

Respawn vehicles
 
Hi, how can I make the CMD to respawn unoccupied vehicles in a radius?

Koreadars 15/04/2019 01:03 PM

Re: Respawn vehicles
 
bump

AmirSavand 15/04/2019 03:10 PM

Re: Respawn vehicles
 
You need to loop through all vehicles and check their distance and see if anyone's in em.

Koreadars 15/04/2019 03:12 PM

Re: Respawn vehicles
 
That's what I know. But what I don't know is how. I'd like if you give me a code of the loop.

polygxn 15/04/2019 03:22 PM

Re: Respawn vehicles
 
pawn Code:
RespawnNearbyVehicles(playerid, Float:radi) {
  new Float:x, Float:y, Float:z;
  GetPlayerPos(playerid, x, y, z);
  for(new i = 1; i < MAX_VEHICLES; i++) {
    if(GetVehicleModel(i)) {
      new Float:posx, Float:posy, Float:posz;
      new Float:tempposx, Float:tempposy, Float:tempposz;
      GetVehiclePos(i, posx, posy, posz);
      tempposx = (posx - x);
      tempposy = (posy - y);
      tempposz = (posz - z);
      if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) {
        SetVehicleToRespawn(i);
      }
    }
  }
}

pawn Code:
// Implement the rest of the code. For now everyone can use the command.
CMD:respawnnearbyvehicles(playerid, params[]) {
  for(new i = 0; i < MAX_VEHICLES; i++) {
    RespawnNearbyVehicles(playerid, 10); // Edit the radius if its not appropriate.
  }
  return 1;
}

Credits to MadeMan for the RespawnNearbyVehicles.

Koreadars 15/04/2019 04:31 PM

Re: Respawn vehicles
 
rep ty


All times are GMT. The time now is 10:49 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.