Not looping through all factions in database. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Server (
https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (
https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Not looping through all factions in database. (
/showthread.php?tid=658103)
Not looping through all factions in database. -
yllo - 23.08.2018
So I have tried to set it up so it gathers all the information from the table factions. It is meant to create a little 'i' icon for the player in the game at the x y z of the factions. The function "LoadFactions" is called ongamemodeinit, and then successfully calls the net function. Only one symbol is created in the game for one of the factions and not for the second, ect ect.
PHP Code:
forward LoadFactions();
public LoadFactions()
{
new DB_Query[900];
mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `factions`");
mysql_tquery(Database, DB_Query, "FactionsRecieved");
print(DB_Query);
}
forward FactionsRecieved();
public FactionsRecieved()
{
if(cache_num_rows() == 0) print("No factions have been made");
else
{
for(new i = 0; i < cache_num_rows(); i++)
{
//cache_get_value_int(0, "fID", factionInfo[fID][fID]);
cache_get_value(0, "facName", factionInfo[fID][facName],32);
cache_get_value_name_float(0, "facX", factionInfo[fID][facX]);
cache_get_value_name_float(0, "facY", factionInfo[fID][facY]);
cache_get_value_name_float(0, "facZ", factionInfo[fID][facZ]);
CreateDynamicPickup(1239, 1, factionInfo[fID][facX], factionInfo[fID][facY], factionInfo[fID][facZ], 0, 0);
}
printf("[INFO]: Loaded %d groups from the database.", cache_num_rows());
}
return true;
}
Re: Not looping through all factions in database. -
Calisthenics - 23.08.2018
pawn Code:
cache_get_value(0, ..
cache_get_value_name_float(0,
first parameter is rowid and you only retrieve from first row. Replace
0 with
i.
You also commented out a line but you use
fID as array index. Never rely on that, it's only a way to identify an iten IN database so use
i there instead.