SA-MP Forums Archive
Some help Respawn car timer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Some help Respawn car timer (/showthread.php?tid=197003)



CarRespawn - NotoriousMOB - 07.12.2010

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!");
}
//////////////////////////////////////////////



Re: Some help Respawn car timer - NotoriousMOB - 07.12.2010

Bump Please some help here.....


Re: Some help Respawn car timer - TheXIII - 07.12.2010

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!");
}



Re: Some help Respawn car timer - NotoriousMOB - 07.12.2010

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);



Re: Some help Respawn car timer - TheXIII - 07.12.2010

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!");
}



Re: Some help Respawn car timer - NotoriousMOB - 07.12.2010

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


Re: Some help Respawn car timer - TheXIII - 07.12.2010

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.


Re: Some help Respawn car timer - NotoriousMOB - 07.12.2010

Yep there we go thanks alot man appreciate it.