Why is this not working? Respawn Vehicles Command
#1

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?
Reply
#2

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..
Reply
#3

thanks, ill give it a try.
Reply
#4

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.
Reply
#5

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

Does it work?
Reply
#6

oh. yes perfectly. thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)