Loop doesn't get run properly - 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)
+--- Thread: Loop doesn't get run properly (
/showthread.php?tid=614873)
Loop doesn't get run properly -
justjamie - 14.08.2016
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=0; i<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?
Re: Loop doesn't get run properly -
Shinja - 14.08.2016
return in a loop breaks it, do it like that
forward RespawnAllCars();
PHP код:
public RespawnAllCars()
{
for(new i=0; i<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=0, j=GetVehiclePoolSize; i<j; i++)
{
if(!IsVehicleOccupied(i)) && (strcmp(Vehicle[i][vOwner], "Nobody")) ReloadVehicle(i);
}
SendClientMessageToAll(-1,"{FFC300}Unoccupied vehicles have been respawned.");
return 1;
}