SA-MP Forums Archive
Why is this not working? Respawn Vehicles Command - 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: Why is this not working? Respawn Vehicles Command (/showthread.php?tid=79018)



Why is this not working? Respawn Vehicles Command - Badger(new) - 24.05.2009

This is called when a timer ends. The timer starts when an admin types the respawn all vehicles command.

This is meant to respawn all empty vehicles.

It does, but then the server crashes.

pawn Код:
public RespawnVeh()
{
    new i, v;
    while(v<=340)
    {
      if(i>=200){SetVehicleToRespawn(v);v++;i=0;}
        if(IsPlayerConnected(i)!=1)i++;
        else if(GetPlayerVehicleID(i)!=v)i++;
    }
    return 1;
}
What is wrong here?


Re: Why is this not working? Respawn Vehicles Command - Weirdosport - 24.05.2009

I'm finding it rather hard to interpret, try this:

pawn Код:
public RespawnVeh()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
      VehicleState[GetPlayerVehicleID(i)] = 1;
    }
    for(new i=1; i<MAX_VEHICLES; i++)
    {
      if(!VehicleState[i]) SetVehicleToRespawn(i);
      else VehicleState[i] = 0;
    }
    return 1;
}
It should also require less looping, and I think it's a bit easier to understand.. If you want to use 340 instead of MAX_VEHICLES just change them..


Re: Why is this not working? Respawn Vehicles Command - Badger(new) - 24.05.2009

thanks, ill give it a try.


Re: Why is this not working? Respawn Vehicles Command - Badger(new) - 24.05.2009

thank you very much . I was thinking about using an array with the vehicle IDs instead of respawning them inside the bit that checks if a player is inside them.

but basically mine would check a vehicle to see if any player was in it, if not respawn it then go onto the next and set i to 0.

Thanks again.


Re: Why is this not working? Respawn Vehicles Command - Weirdosport - 24.05.2009

Yeah but I realised that that would involve lots of loopage, so I looked at it from a different angle :P

Does it work?


Re: Why is this not working? Respawn Vehicles Command - Badger(new) - 24.05.2009

oh. yes perfectly. thanks for the help.