26.12.2016, 15:13
Hi, I'm working on faction ranks in my gamemode right now, they are loaded from MySQL. But I don't know if they are even loading correctly, one time it's OK other time it's some messy stuff. Anyways for example if I set the rank 1 to "test" and when I go in-game and print that it says "None ne" or "None " <- extra space in the end there. Also when I save the faction everything is OK, except rank 15 (the last one), it saves as "N ne". The empty space there is sometimes some kind of a weird character. This is what the enumerator looks like:
Here is the loading callback and the saving function:
I tried debugging the ranks like this:
and this:
the output of the first one was:
and the second one (with indexes):
Also this is what the saving query looks like:
What am I doing wrong?
Код:
enum factionInfo
{
FactionRanks,
FactionRank1[24],
FactionRank2[24],
FactionRank3[24],
FactionRank4[24],
FactionRank5[24],
FactionRank6[24],
FactionRank7[24],
FactionRank8[24],
FactionRank9[24],
FactionRank10[24],
FactionRank11[24],
FactionRank12[24],
FactionRank13[24],
FactionRank14[24],
FactionRank15[24]
}
Код:
forward OnFactionsLoaded();
public OnFactionsLoaded()
{
new rows, field[10], factionid;
cache_get_row_count(rows);
for (new i; i < rows; i++) if (i < MAX_FACTIONS)
{
cache_get_value_name_int(i, "ID", factionid);
cache_get_value_name_int(i, "Ranks", FactionInfo[factionid][FactionRanks]);
for (new index = 24, number = 1; index <= 360; index += 24, number++)
{
format(field, sizeof(field), "Rank%d", number);
cache_get_value_name(i, field, FactionInfo[factionid][factionInfo:index], 24);
}
}
}
SaveFaction(factionid)
{
new query[500], field[10];
mysql_format(g_MySQL, query, sizeof(query), "UPDATE `factions` SET `Ranks` = %d", FactionInfo[factionid][FactionRanks]);
for (new index = 24, number = 1; index <= 360; index += 24, number++)
{
format(field, sizeof(field), "Rank%d", number);
mysql_format(g_MySQL, query, sizeof(query), "%s, `%s` = '%e'", query, field, FactionInfo[factionid][factionInfo:index]);
}
mysql_format(g_MySQL, query, sizeof(query), "%s WHERE `ID` = %d", query, factionid);
mysql_tquery(g_MySQL, query);
}
Код:
printf("%s", FactionInfo[0][FactionRank1]);
printf("%s", FactionInfo[0][FactionRank2]);
printf("%s", FactionInfo[0][FactionRank3]);
printf("%s", FactionInfo[0][FactionRank4]);
printf("%s", FactionInfo[0][FactionRank5]);
printf("%s", FactionInfo[0][FactionRank6]);
printf("%s", FactionInfo[0][FactionRank7]);
printf("%s", FactionInfo[0][FactionRank8]);
printf("%s", FactionInfo[0][FactionRank9]);
printf("%s", FactionInfo[0][FactionRank10]);
printf("%s", FactionInfo[0][FactionRank11]);
printf("%s", FactionInfo[0][FactionRank12]);
printf("%s", FactionInfo[0][FactionRank13]);
printf("%s", FactionInfo[0][FactionRank14]);
printf("%s", FactionInfo[0][FactionRank15]);
Код:
printf("%s", FactionInfo[0][factionInfo:24]);
printf("%s", FactionInfo[0][factionInfo:48]);
printf("%s", FactionInfo[0][factionInfo:72]);
printf("%s", FactionInfo[0][factionInfo:96]);
printf("%s", FactionInfo[0][factionInfo:120]);
printf("%s", FactionInfo[0][factionInfo:144]);
printf("%s", FactionInfo[0][factionInfo:168]);
printf("%s", FactionInfo[0][factionInfo:192]);
printf("%s", FactionInfo[0][factionInfo:216]);
printf("%s", FactionInfo[0][factionInfo:240]);
printf("%s", FactionInfo[0][factionInfo:264]);
printf("%s", FactionInfo[0][factionInfo:288]);
printf("%s", FactionInfo[0][factionInfo:312]);
printf("%s", FactionInfo[0][factionInfo:336]);
printf("%s", FactionInfo[0][factionInfo:360]);
Код:
est one one one one one one one one one one one one one
Код:
test None None None None None None None None None None None None None N ne
Код:
UPDATE `factions` SET `Ranks` = 11, `Rank1` = 'test', `Rank2` = 'None', `Rank3` = 'None', `Rank4` = 'None', `Rank5` = 'None', `Rank6` = 'None', `Rank7` = 'None', `Rank8` = 'None', `Rank9` = 'None', `Rank10` = 'None', `Rank11` = 'None', `Rank12` = 'None', `Rank13` = 'None', `Rank14` = 'None', `Rank15` = 'N\nne' WHERE `ID` = 0


