PDA

View Full Version : MySQL picking up something different.


EliteApple
01/04/2013, 01:12 AM
Ingame when I do /factionon 1, it comes up as '0', as the name, when it should be 'LSPD'.

When I do /afactionname and let it back to LSPD, it shows as LSPD. But when I restart the server, it shows up as '0', it's showing the faction's bank's cash.

And I'm not even what sort of code I should be looking at. But, here's the saving/loading of the factions:


forward SaveFactions(busid);
public SaveFactions(busid)
{
new query[1024];
printf("Saving Faction %d.",busid);
format(query, sizeof(query), "UPDATE factions SET fX=%f,fY=%f,fZ=%f,fName='%s',fBank=%d WHERE FactionID=%d",
DynamicFactions[busid][fX],
DynamicFactions[busid][fY],
DynamicFactions[busid][fZ],
DynamicFactions[busid][fName],
DynamicFactions[busid][fBank],
busid);
mysql_query(query);

format(query, sizeof(query), "UPDATE factions SET fRankAmount=%d,fType=%d,fJoinRank=%d,fRank1='%s',f Rank2='%s',fRank3='%s' WHERE FactionID=%d",
DynamicFactions[busid][fRankAmount],
DynamicFactions[busid][fType],
DynamicFactions[busid][fJoinRank],
DynamicFactions[busid][fRank1],
DynamicFactions[busid][fRank2],
DynamicFactions[busid][fRank3],
busid);
mysql_query(query);

format(query, sizeof(query), "UPDATE factions SET fRank4='%s',fRank5='%s',fRank6='%s',fRank7='%s',fR ank8='%s',fRank9='%s',fRank10='%s' WHERE FactionID=%d",
DynamicFactions[busid][fRank4],
DynamicFactions[busid][fRank5],
DynamicFactions[busid][fRank6],
DynamicFactions[busid][fRank7],
DynamicFactions[busid][fRank8],
DynamicFactions[busid][fRank9],
DynamicFactions[busid][fRank10],
busid);
mysql_query(query);

format(query, sizeof(query), "UPDATE factions SET fRank11='%s',fRank12='%s',fRank13='%s',fRank14='%s ',fRank15='%s' WHERE FactionID=%d",
DynamicFactions[busid][fRank11],
DynamicFactions[busid][fRank12],
DynamicFactions[busid][fRank13],
DynamicFactions[busid][fRank14],
DynamicFactions[busid][fRank15],
busid);
mysql_query(query);

format(query, sizeof(query), "UPDATE factions SET fRank16='%s',fRank17='%s',fRank18='%s',fRank19='%s ',fRank20='%s' WHERE FactionID=%d",
DynamicFactions[busid][fRank16],
DynamicFactions[busid][fRank17],
DynamicFactions[busid][fRank18],
DynamicFactions[busid][fRank19],
DynamicFactions[busid][fRank20],
busid);
mysql_query(query);
}




forward LoadFactions();
public LoadFactions()
{
new arrCoords[28][64];
new sql[80], row[512];
format(sql, sizeof(sql), "SELECT COUNT(*) FROM factions");
mysql_query(sql);
mysql_store_result();
mysql_fetch_row(row);
totalfactions = 11;
mysql_free_result();

for (new idx=0; idx<totalfactions; idx++)
{
format(sql, sizeof(sql), "SELECT * FROM factions WHERE FactionID=%d", idx);
mysql_query(sql);
mysql_store_result();
if (mysql_num_rows() > 0)
{
mysql_fetch_row(row);
split(row, arrCoords, '|');
mysql_free_result();
DynamicFactions[idx][fX] = floatstr(arrCoords[0]);
DynamicFactions[idx][fY] = floatstr(arrCoords[1]);
DynamicFactions[idx][fZ] = floatstr(arrCoords[2]);
DynamicFactions[idx][fType] = strval(arrCoords[3]);
DynamicFactions[idx][fJoinRank] = strval(arrCoords[4]);
DynamicFactions[idx][fRankAmount] = strval(arrCoords[5]);
DynamicFactions[idx][fBank] = strval(arrCoords[6]);
strmid(DynamicFactions[idx][fName], arrCoords[7], 0, strlen(arrCoords[7]), 255);
strmid(DynamicFactions[idx][fRank1], arrCoords[8], 0, strlen(arrCoords[8]), 255);
strmid(DynamicFactions[idx][fRank2], arrCoords[9], 0, strlen(arrCoords[9]), 255);
strmid(DynamicFactions[idx][fRank3], arrCoords[10], 0, strlen(arrCoords[10]), 255);
strmid(DynamicFactions[idx][fRank4], arrCoords[11], 0, strlen(arrCoords[11]), 255);
strmid(DynamicFactions[idx][fRank5], arrCoords[12], 0, strlen(arrCoords[12]), 255);
strmid(DynamicFactions[idx][fRank6], arrCoords[13], 0, strlen(arrCoords[13]), 255);
strmid(DynamicFactions[idx][fRank7], arrCoords[14], 0, strlen(arrCoords[14]), 255);
strmid(DynamicFactions[idx][fRank8], arrCoords[15], 0, strlen(arrCoords[15]), 255);
strmid(DynamicFactions[idx][fRank9], arrCoords[16], 0, strlen(arrCoords[16]), 255);
strmid(DynamicFactions[idx][fRank10], arrCoords[17], 0, strlen(arrCoords[17]), 255);
strmid(DynamicFactions[idx][fRank11], arrCoords[18], 0, strlen(arrCoords[18]), 255);
strmid(DynamicFactions[idx][fRank12], arrCoords[19], 0, strlen(arrCoords[19]), 255);
strmid(DynamicFactions[idx][fRank13], arrCoords[20], 0, strlen(arrCoords[20]), 255);
strmid(DynamicFactions[idx][fRank14], arrCoords[21], 0, strlen(arrCoords[21]), 255);
strmid(DynamicFactions[idx][fRank15], arrCoords[22], 0, strlen(arrCoords[22]), 255);
strmid(DynamicFactions[idx][fRank16], arrCoords[23], 0, strlen(arrCoords[23]), 255);
strmid(DynamicFactions[idx][fRank17], arrCoords[24], 0, strlen(arrCoords[24]), 255);
strmid(DynamicFactions[idx][fRank18], arrCoords[25], 0, strlen(arrCoords[25]), 255);
strmid(DynamicFactions[idx][fRank19], arrCoords[26], 0, strlen(arrCoords[26]), 255);
strmid(DynamicFactions[idx][fRank20], arrCoords[27], 0, strlen(arrCoords[27]), 255);
}
}
mysql_free_result();
printf("%d Factions loaded from database", totalfactions);
return true;
}


Ideas? Thanks in advanced, it's been bugging me ALOT.

EliteApple
01/04/2013, 02:36 AM
Bumping, that is if I'm allowed too, I don't know. I need help though really bad.

EliteApple
02/04/2013, 11:12 AM
Bump

Scenario
02/04/2013, 11:23 AM
You were doing a bit of unnecessary stuff when loading the factions from the DB. See if this works better for you:

forward LoadFactions();
public LoadFactions()
{
mysql_query("SELECT * FROM `factions`");
mysql_store_result();
totalfactions = mysql_num_rows();

new
szQuery[1000] // may need to (in/de)crease
;

for(new i = 0; i < totalfactions; i++)
{
while(mysql_fetch_row_format(szQuery, "|"))
{
sscanf(szQuery, "<|>fffdddds[255]",
DynamicFactions[i][fX],
DynamicFactions[i][fY],
DynamicFactions[i][fZ],
DynamicFactions[i][fType],
DynamicFactions[i][fJoinRank],
DynamicFactions[i][fRankAmount],
DynamicFactions[i][fBank],
DynamicFactions[i][fName]
);
}
}
mysql_free_result();
}

You really should be using threaded queries, though!

EliteApple
02/04/2013, 11:47 AM
Should I go ahead and also add the factionranks in there too? As they need to load, yea?

Hanger
02/04/2013, 11:49 AM
When updating values use '' for floats something = '%f'

EliteApple
02/04/2013, 11:51 AM
What are floats again? Sorry, it's been awhile.

Konstantinos
02/04/2013, 11:52 AM
Read me. (http://lmgtfy.com/?q=samp+floats)

EliteApple
02/04/2013, 11:54 AM
Gotcha, Dwane, thank ya, remember now.