Some help Respawn car timer
#1

I made a timer so all vehicles respawn automatic every hour.
but there's a problem it also respawns iff Player is in a vehicle heres how it looks like:

pawn Код:
SetTimer("SetVehicleRespawn",50000,1);
//////////////////////////////////////////////
stock IsAnyPlayerInVehicle(vehicleid)
{
  for (new i = 0; i != MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid)) return 1;
  }
  return 0;
}
//////////////////////////////////////////////
public SetVehicleRespawn()
{
for(new car = 1; car <= 268; car++)
{
if(!IsPlayerInAnyVehicle(car)) SetVehicleToRespawn(car);
}
SendClientMessageToAll(COLOR_WHITE,"All vehicles has been respawned!");
}
//////////////////////////////////////////////
Reply
#2

Bump Please some help here.....
Reply
#3

There's a huge difference between IsAnyPlayerInVehicle and IsPlayerInAnyVehicle! Try this. It should be faster than going trough all players again and again for every vehicle.

pawn Код:
public SetVehicleRespawn()
{
    #define VEHICLES_IN_SERVER MAX_VEHICLES
   
    new bool:VehicleOccupied[VEHICLES_IN_SERVER] = false;

    for(new player; player <= GetMaxPlayers(); player++)
    {
        if( IsPlayerInAnyVehicle(player) ) VehicleOccupied[GetPlayerVehicleID(player)] = true;
    }
    for(new car; car <= VEHICLES_IN_SERVER; car++);
    {
        if( !VehicleOccupied[car] ) SetVehicleRespawn(car);
    }
    SendClientMessageToAll(COLOR_WHITE,"All vehicles has been respawned!");
}
Reply
#4

pawn Код:
(48177) : error 036: empty statement
(48179) : error 017: undefined symbol "car"
(48179) : error 017: undefined symbol "car"

That's :

pawn Код:
for(new car; car <= VEHICLES_IN_SERVER; car++);
    {
    if( !VehicleOccupied[car] ) SetVehicleRespawn(car);
Reply
#5

Quote:
Originally Posted by NotoriousMOB
Посмотреть сообщение
pawn Код:
(48177) : error 036: empty statement
(48179) : error 017: undefined symbol "car"
(48179) : error 017: undefined symbol "car"

That's :

pawn Код:
for(new car; car <= VEHICLES_IN_SERVER; car++);
    {
    if( !VehicleOccupied[car] ) SetVehicleRespawn(car);
Sorry, typo. Try this:
pawn Код:
public SetVehicleRespawn()
{
    #define VEHICLES_IN_SERVER MAX_VEHICLES

    new bool:VehicleOccupied[VEHICLES_IN_SERVER] = false, MAX_PLAYER_IN_SERVER = GetMaxPlayers();

    for(new player; player <= MAX_PLAYER_IN_SERVER; player++)
    {
        if( IsPlayerInAnyVehicle(player) ) VehicleOccupied[GetPlayerVehicleID(player)] = true;
    }
    for(new car; car <= VEHICLES_IN_SERVER; car++)
    {
        if( !VehicleOccupied[car] ) SetVehicleToRespawn(car);
    }
    SendClientMessageToAll(COLOR_WHITE,"All vehicles has been respawned!");
}
Reply
#6

Thanks alot man finaly worked now
but how come the SendClientMessageToAll won't show when they respawn.
Reply
#7

Ah, yet another stupid mistake. replace this line:
pawn Код:
for(new car; car <= VEHICLES_IN_SERVER; car++)
With this:
pawn Код:
for(new car; car < VEHICLES_IN_SERVER; car++)
It's because of array size.
Reply
#8

Yep there we go thanks alot man appreciate it.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)