Respawn All Vehicles command.
#1

hi. I attempted a command that respawns all vehicles. The command itself works, but all vehicles get respawned and then the server crashes.

I tried to get it to only respawn empty vehicles. Here is the code in the timer:

pawn Код:
public RespawnVeh()
{
  for(new v=0; v<MAX_VEHICLES; v++)
  {
      for(new i=0; i<MAX_PLAYERS; i++)
      {
        if(IsPlayerInVehicle(i,v)){}
        else SetVehicleToRespawn(v);
      }
    }
    return 1;
}
What have I done wrong here, or is this way which I've done not possible?
Reply
#2

From the LARP gamemode.

Код:
	if(strcmp(cmd, "/respawnallcars", true) == 0 || strcmp(cmd, "/rac", true) == 0) // by Ellis
	{
	  if(IsPlayerConnected(playerid))
	  {
	    if(PlayerInfo[playerid][pAdmin] < 3)
			{
			  SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
			  return 1;
			}
			new bool:unwanted[CAR_AMOUNT];
			for(new player=0; player<MAX_PLAYERS; player++)
   		{
      	if(IsPlayerInAnyVehicle(player)) { unwanted[GetPlayerVehicleID(player)]=true; }
   		}
			for(new car = 1; car <= 268; car++)
			{
				if(!unwanted[car]) SetVehicleToRespawn(car);
			}
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "SERVER: All unused cars respawned by %s.", sendername);
			BroadCast(COLOR_WHITE,string);
		}
		return 1;
	}
Reply
#3

Код:
public RespawnVeh()
{
  for(new v = 0; v < MAX_VEHICLES; v++)
	{
    SetVehicleToRespawn(v);
	}
	return 1;
}
I hope that can help you

sorry my bad english
Reply
#4

thanks exo. I'll try pick out the bits I need .

thanka for replying GammerZ but, I could've easily done that bit myself, which I did, but in the second line of my first post

Quote:
Originally Posted by -The_Badger-
hi. I attempted a command that respawns all vehicles. The command itself works, but all vehicles get respawned and then the server crashes.

I tried to get it to only respawn empty vehicles. Here is the code in the timer:
it says I want to only respawn empty vehicles. Thanks anyway.
Reply
#5

i changed it to go a different way, but now the server crashes. It respawns all vehicles except ones with players in but then no-one can join the server, although it is still online and it shows that players are connected, when they aren't.

Here is the code:
pawn Код:
public RespawnVeh()
{
  new v;
  new i;
  while(v<340)
  {
    if(i>=200){SetVehicleToRespawn(v);v++;i=0;}
    if(IsPlayerConnected(i)!=1)i++;
    else if(!IsPlayerInVehicle(i,v))i++;
  }
  i=0;
  v=0;
  return 1;
}
i think it may be because I have:
pawn Код:
BV[0]=CreateVehicle(//etc);
lots of those so the vehicle ID would be whatever i have infront right?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)