Respawn all cars
#1

I've created this cmd , but i don't know why he didn't respawn all my 500's cars
pawn Код:
if (strcmp(cmdtext, "/rac", true) == 0 || strcmp(cmdtext, "/respawnallcars", true) == 0)
    {
      if(PlayerInfo[playerid][pAdmin] >= 1337)
      {
        SendClientMessage(playerid,UNKNOWN_CMD," All cars respawned !");
        for(new i = 0; i < 500; i++)
        {
          SetVehicleToRespawn(i);
          return 1;
        }
      }
      else
      {
        SendClientMessage(playerid,COLOR_WHITE,ADMIN_TEXT);
        return 1;
      }
    }
Reply
#2

Using return in a loop will stop the loop.

FIXED:
pawn Код:
for(new i = 0; i < 500; i++) SetVehicleToRespawn(i);
Reply
#3

Quote:
Originally Posted by Danut
I've created this cmd , but i don't know why he didn't respawn all my 500's cars
pawn Код:
if (strcmp(cmdtext, "/rac", true) == 0 || strcmp(cmdtext, "/respawnallcars", true) == 0)
    {
      if(PlayerInfo[playerid][pAdmin] >= 1337)
      {
        SendClientMessage(playerid,UNKNOWN_CMD," All cars respawned !");
        for(new i = 0; i < 500; i++)
        {
          SetVehicleToRespawn(i);
          return 1;
        }
      }
      else
      {
        SendClientMessage(playerid,COLOR_WHITE,ADMIN_TEXT);
        return 1;
     }
    }
This will kill your server, even with Finn's fix, because you can't SetVehicleToRespawn if there's someone in it, so you should rather check if the vehicle is occupied. Here is a working command
pawn Код:
// You need this
stock IsVehicleOccupied(vehicleid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerInVehicle(i,vehicleid)) return 1;
    }
    return 0;
}
// if you use the commented way below
stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
      {
            return i;
      }
    }
  }
  return -1;
}
pawn Код:
// the cmd
    if (!strcmp(cmdtext, "/rac", true) || !strcmp(cmdtext, "/respawnallcars", true))
    {
      if(PlayerInfo[playerid][pAdmin] >= 1337)
      {
        SendClientMessage(playerid,UNKNOWN_CMD," All empty cars were respawned !");
        for(new i = 0; i < 500; i++) if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
// if you want all cars to respawn
// for(new i;i<500;i++)
// {
// if(IsVehicleOccupied(i)) RemovePlayerFromVehicle(GetVehicleDriver(i));
// SetVehicleToRespawn(i);
// }
      }
      else
      {
        SendClientMessage(playerid,COLOR_WHITE,ADMIN_TEXT);
        return 1;
      }
    }
Reply
#4

Or just RemovePlayerFromVehicle before you do it
Reply
#5

yea thx
Reply
#6

Quote:
Originally Posted by JeNkStAX
Or just RemovePlayerFromVehicle before you do it
He automatly remove you from vehicle ...
Reply
#7

Quote:
Originally Posted by Danut
What's mean loop ?
Are you serious?
Reply
#8

yep
Reply
#9

If you dont know what a loop is, you have alot to learn.

https://sampwiki.blast.hk/wiki/Loop
Reply
#10

thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)