SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/04/2019, 09:49 AM   #1
Koreadars
Big Clucker
 
Join Date: Mar 2019
Location: Czech Republic, Prdelákov.
Posts: 122
Reputation: 6
Default Respawn vehicles

Hi, how can I make the CMD to respawn unoccupied vehicles in a radius?
Koreadars is offline   Reply With Quote
Old 15/04/2019, 01:03 PM   #2
Koreadars
Big Clucker
 
Join Date: Mar 2019
Location: Czech Republic, Prdelákov.
Posts: 122
Reputation: 6
Default Re: Respawn vehicles

bump
Koreadars is offline   Reply With Quote
Old 15/04/2019, 03:10 PM   #3
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 79
Reputation: 8
Default Re: Respawn vehicles

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

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron

AmirSavand is offline   Reply With Quote
Old 15/04/2019, 03:12 PM   #4
Koreadars
Big Clucker
 
Join Date: Mar 2019
Location: Czech Republic, Prdelákov.
Posts: 122
Reputation: 6
Default 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.
Koreadars is offline   Reply With Quote
Old 15/04/2019, 03:22 PM   #5
polygxn
Banned
 
Join Date: Dec 2018
Posts: 100
Reputation: 21
Default 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.
polygxn is offline   Reply With Quote
Old 15/04/2019, 04:31 PM   #6
Koreadars
Big Clucker
 
Join Date: Mar 2019
Location: Czech Republic, Prdelákov.
Posts: 122
Reputation: 6
Default Re: Respawn vehicles

rep ty
Koreadars is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Respawn Vehicles don't respawn spawned cars JaKe Elite Scripting Help 6 20/05/2013 07:17 AM
Respawn vehicles bug Witnec Scripting Help 3 02/01/2013 02:15 PM
Help with respawn vehicles sniperwars Scripting Help 7 24/02/2012 11:51 PM
Vehicles don't respawn. Ash. Help Archive 1 26/06/2011 07:25 AM
Vehicles don't respawn PoWerZ Help Archive 0 08/04/2009 08:48 AM


All times are GMT. The time now is 10:48 PM.


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