Loop doesn't get run properly
#1

Title.

PHP код:
/* ============================================================================= */
forward RespawnAllCars1();
public 
RespawnAllCars1()
{
    new 
query[256];
    
format(query,sizeof(query),"SELECT * from vehicles");
    
mysql_tquery(connection,query,"RespawnAllCars","");
    return 
1;
}
/* ============================================================================= */
forward RespawnAllCars();
public 
RespawnAllCars()
{
    for(new 
i=0i<cache_get_row_count(); i++)
        {
        new 
vid cache_get_field_content_int(i"id");
        if(
IsVehicleOccupied(vid)) return 1;
        else if(!
strcmp(Vehicle[vid][vOwner], "Nobody")) return 1;
        
ReloadVehicle(vid);
         }
    
SendClientMessageToAll(-1,"{FFC300}Unoccupied vehicles have been respawned.");
    return 
1;
}
/* ============================================================================= */ 
It doesnt do the reloadvehicle, and doesnt send the "Have been respawned".
The vehicle isnt occupied and the owner isnt nobody.
What's the problem here?
Reply
#2

return in a loop breaks it, do it like that
forward RespawnAllCars();
PHP код:
public RespawnAllCars() 

    for(new 
i=0i<cache_get_row_count(); i++) 
        { 
        new 
vid cache_get_field_content_int(i"id"); 
        if(!
IsVehicleOccupied(vid)) && (strcmp(Vehicle[vid][vOwner], "Nobody")) ReloadVehicle(vid); 
         } 
    
SendClientMessageToAll(-1,"{FFC300}Unoccupied vehicles have been respawned."); 
    return 
1

And i don't think you really need a query for it, use GetVehiclePoolSize better
PHP код:
public RespawnAllCars() 

    for(new 
i=0j=GetVehiclePoolSizei<ji++) 
        { 
        if(!
IsVehicleOccupied(i)) && (strcmp(Vehicle[i][vOwner], "Nobody")) ReloadVehicle(i); 
         } 
    
SendClientMessageToAll(-1,"{FFC300}Unoccupied vehicles have been respawned."); 
    return 
1

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)